首页 > 数据库 >TiDB placement_rule in sql使用

TiDB placement_rule in sql使用

时间:2024-06-17 17:21:57浏览次数:22  
标签:placement zone 20160 rule zone2 tikv sql test ID

1、配置好tikv label

例如:

tikv_servers:
- host: 10.37.129.6
  ssh_port: 22
  port: 20160
  status_port: 20180
  deploy_dir: /tidb-deploy/tikv-20160
  data_dir: /tidb-data/tikv-20160
  log_dir: /tidb-deploy/tikv-20160/log
  config:
    server.labels:
      host: host1
      zone: zone1
  arch: amd64
  os: linux
- host: 10.37.129.6
  ssh_port: 22
  port: 20161
  status_port: 20181
  deploy_dir: /tidb-deploy/tikv-20161
  data_dir: /tidb-data/tikv-20161
  log_dir: /tidb-deploy/tikv-20161/log
  config:
    server.labels:
      host: host1
      zone: zone1
  arch: amd64
  os: linux
- host: 10.37.129.7
  ssh_port: 22
  port: 20160
  status_port: 20180
  deploy_dir: /tidb-deploy/tikv-20160
  data_dir: /tidb-data/tikv-20160
  log_dir: /tidb-deploy/tikv-20160/log
  config:
    server.labels:
      host: host2
      zone: zone2
  arch: amd64
  os: linux
- host: 10.37.129.8
  ssh_port: 22
  port: 20160
  status_port: 20180
  deploy_dir: /tidb-deploy/tikv-20160
  data_dir: /tidb-data/tikv-20160
  log_dir: /tidb-deploy/tikv-20160/log
  config:
    server.labels:
      host: host3
      zone: zone2
  arch: amd64
  os: linux

这里我们有四个tikv实例,其中10.37.129.6:2016010.37.129.6:20161zone110.37.129.7:2016010.37.129.8:20160zone2

2、用sql创建placement rule和业务表

/* 配置为3副本,该placement rule表示`leader`只在`zone2`的tikv实例,`follow`在`zone1`和`zone2`各一副本。*/
mysql> create placement policy p1 leader_constraints="[+zone=zone2]" FOLLOWER_CONSTRAINTS="{+zone=zone1: 1,+zone=zone2: 1}";
mysql> create table test.t1 (id int) PLACEMENT POLICY='p1'; 

/* 配置为3副本,该placement rule表示`leader`只在`zone2`的tikv实例,`follow`在`zone1`有两副本。*/
mysql> create placement policy p2 leader_constraints="[+zone=zone2]" FOLLOWER_CONSTRAINTS="{+zone=zone1: 2}";
mysql> create table test.t2 (id int) PLACEMENT POLICY='p2';

3、检查表的peer存储

方式一:

mysql>  show table test.t1 regions;
+-----------+-----------+---------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+-------------------------------------------------------------------------------------------+------------------+
| REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS               | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | SCHEDULING_CONSTRAINTS                                                                    | SCHEDULING_STATE |
+-----------+-----------+---------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+-------------------------------------------------------------------------------------------+------------------+
|     60007 | t_207_    | t_208_  |     60008 |               1 | 60008, 60009, 60010 |          0 |            27 |          0 |                    1 |                0 | LEADER_CONSTRAINTS="[+zone=zone2]" FOLLOWER_CONSTRAINTS="{+zone=zone1: 1,+zone=zone2: 1}" | SCHEDULED        |
+-----------+-----------+---------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+-------------------------------------------------------------------------------------------+------------------+
mysql>  show table test.t2 regions;
+-----------+-----------+---------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+----------------------------------------------------------------------------+------------------+
| REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS               | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | SCHEDULING_CONSTRAINTS                                                     | SCHEDULING_STATE |
+-----------+-----------+---------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+----------------------------------------------------------------------------+------------------+
|     65009 | t_211_    | t_212_  |     65010 |               1 | 65010, 65012, 65013 |          0 |            39 |          0 |                    1 |                0 | LEADER_CONSTRAINTS="[+zone=zone2]" FOLLOWER_CONSTRAINTS="{+zone=zone1: 2}" | SCHEDULED        |
+-----------+-----------+---------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+----------------------------------------------------------------------------+------------------+

可以看到test.t1test.t2表的peerplacement rule等相关信息

方式二:

mysql> select TRP.REGION_ID,PEER_ID,IS_LEADER,TRP.STORE_ID,DB_NAME,TABLE_NAME,LABEL,ADDRESS from information_schema.TIKV_REGION_PEERS TRP join information_schema.TIKV_REGION_STAT
US TRS on TRP.REGION_ID=TRS.REGION_ID join information_schema.TIKV_STORE_STATUS TSS on TRP.STORE_ID=TSS.STORE_ID where TABLE_NAME='t1' and DB_NAME='test';
+-----------+---------+-----------+----------+---------+------------+------------------------------------------------------------------------+-------------------+
| REGION_ID | PEER_ID | IS_LEADER | STORE_ID | DB_NAME | TABLE_NAME | LABEL                                                                  | ADDRESS           |
+-----------+---------+-----------+----------+---------+------------+------------------------------------------------------------------------+-------------------+
|     60007 |   60008 |         1 |        1 | test    | t1         | [{"key": "host", "value": "host3"}, {"key": "zone", "value": "zone2"}] | 10.37.129.8:20160 |
|     60007 |   60009 |         0 |        2 | test    | t1         | [{"key": "host", "value": "host2"}, {"key": "zone", "value": "zone2"}] | 10.37.129.7:20160 |
|     60007 |   60010 |         0 |        5 | test    | t1         | [{"key": "host", "value": "host1"}, {"key": "zone", "value": "zone1"}] | 10.37.129.6:20161 |
+-----------+---------+-----------+----------+---------+------------+------------------------------------------------------------------------+-------------------+

mysql> select TRP.REGION_ID,PEER_ID,IS_LEADER,TRP.STORE_ID,DB_NAME,TABLE_NAME,LABEL,ADDRESS from information_schema.TIKV_REGION_PEERS TRP join information_schema.TIKV_REGION_STAT
US TRS on TRP.REGION_ID=TRS.REGION_ID join information_schema.TIKV_STORE_STATUS TSS on TRP.STORE_ID=TSS.STORE_ID where TABLE_NAME='t2' and DB_NAME='test';
+-----------+---------+-----------+----------+---------+------------+------------------------------------------------------------------------+-------------------+
| REGION_ID | PEER_ID | IS_LEADER | STORE_ID | DB_NAME | TABLE_NAME | LABEL                                                                  | ADDRESS           |
+-----------+---------+-----------+----------+---------+------------+------------------------------------------------------------------------+-------------------+
|     65009 |   65012 |         0 |        5 | test    | t2         | [{"key": "host", "value": "host1"}, {"key": "zone", "value": "zone1"}] | 10.37.129.6:20161 |
|     65009 |   65013 |         0 |        6 | test    | t2         | [{"key": "host", "value": "host1"}, {"key": "zone", "value": "zone1"}] | 10.37.129.6:20160 |
|     65009 |   65010 |         1 |        1 | test    | t2         | [{"key": "host", "value": "host3"}, {"key": "zone", "value": "zone2"}] | 10.37.129.8:20160 |
+-----------+---------+-----------+----------+---------+------------+------------------------------------------------------------------------+-------------------+

可以看到peer对应的tikv labelip

标签:placement,zone,20160,rule,zone2,tikv,sql,test,ID
From: https://www.cnblogs.com/longfeij/p/18252848

相关文章

  • debezium+kafka实现sqlserver数据同步(debezium-connector-sqlserver)
    SELECTCASEWHENdss.[status]=4THEN1ELSE0ENDASisRunningFROM[#db].sys.dm_server_servicesdssWHEREdss.[servicename]LIKEN'SQLServerAgent(%'1.情景展示在企业当中,往往会存在不同数据库之间的表的数据需要保持一致的情况(数据同步)。如何将A库a表的数据......
  • mysqlconf
    [mysqld]#max_connections=20000#数据传输可能出现大表中断与这个有关系port=13306default-authentication-plugin=mysql_native_password#datadir=/opt/data/mysql/mysql#socket=/opt/data/mysql/mysql/mysql.sockdatadir=/opt/data/mysql/mysql/mysqlsocket=/o......
  • MySQL触发器基本结构
    1、修改分隔符符号delimiiter$$可以修改成$$//都行2、创建触发器函数名称createtrigger函数名3、什么样的操作触发,操作哪个表after:···之后触发before:···之前触发insert:插入被触发update:修改被触发delete:删除被触发on表名实例:在user表被添加信息后触发......
  • 如何解决c++使用mysql数据库读取中文输出时乱码问题
    使用vs写c++输出数据库中文时出现乱码设置utf-8还是不行这是数据库的内容这是输出:在网上找有说改成utf-8的格式,加入这样一句:mysql_query(conn,"setnamesutf8");效果就是这样:发现错误依旧,询问群友后修改,需要在连接数据库的函数中加入如下一句:mysql_query(conn,"set......
  • MYSQL查询语句报1 of ORDER BY clause is not in SELECT list
    我的语句如下:SELECTDISTINCT r.id, r.device_model_id, r.device_model_name, r.alarm_type_id, r.alarm_type_name, r.alarm_level, r.filter_condition, r.filter_condition_value, r.offline_tag, p.param_data_id, p.parmsFROM alarm_ruler, alarm_rule_pa......
  • MySQL 5.7 安装教程(Win 10)
    转自:https://www.cnblogs.com/swjian/p/11907600.htmlMySQL5.7下载官网下载(不推荐使用):https://dev.mysql.com/downloads/mysql/清华镜像站下载(推荐):https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.27-winx64.zipMySQL5.7解压将下载完的zi......
  • 绘制MySQL数据库的实体关系图(ERD)与逻辑模型图
    绘制MySQL的实体关系图(ERD,Entity-RelationshipDiagram)和数据库模型图对于理解和设计数据库结构非常重要。这些图表有助于可视化数据库中的表、列、关系以及约束。以下是一些步骤和工具,你可以使用它们来创建这些图表。步骤确定实体:首先,确定你的数据库中的实体(或称为表......
  • MySQL中的锁机制及其应用
    MySQL中的锁是用于确保数据完整性和一致性的重要机制。当多个事务尝试同时访问或修改同一数据时,锁可以防止并发问题,如脏读、不可重复读和幻读。MySQL提供了多种类型的锁,以满足不同的应用场景和性能需求。以下是MySQL中常见的锁类型:共享锁(SharedLocks,S锁)和排他锁(Exclusi......
  • 致远互联FE协作办公平台 ncsubjass SQL注入致RCE漏洞复现
    0x01产品简介致远互联FE协作办公平台是一款为企业提供全方位协同办公解决方案的产品。它集成了多个功能模块,旨在帮助企业实现高效的团队协作、信息共享和文档管理。0x02漏洞概述致远互联FE协作办公平台ncsubjass.jsp接口处存在SQL注入漏洞,未经身份验证的攻击者可以通过......
  • 【Mysql】Windows下安装和配置Mysql
    一、下载官网下载Mysql:https://dev.mysql.com/downloads/mysql/百度网盘链接mysql-8.0.31:https://pan.baidu.com/s/1CiW7oL8fR05NPZT55_9DUQ?pwd=0724提取码:0724二、解压下载完成后我们得到的是一个压缩包,将其解压,我们就可以得到MySQL8.0.31的软件本体了(就是一个文件夹),我......