tidb的regins管理
```bash
命令及sql查看
#tidb热点regins查看
select * from information_schema.tidb_hot_regions where REGION_ID='121930461';
select * from information_schema.TIKV_REGION_PEERS limit 10; #regins存储位置是否为leader
select * from information_schema.TIKV_REGION_STATUS limit 10; #regins的详细信息
select * from information_schema.TIKV_STORE_STATUS; #各个tikv的状态
#查看regins
tiup ctl:v4.0.4 pd -i -u http://172.21.210.96:2379
hot read #热读regins
region topread 5 #查找热点 最热的5个read
region topwrite 5 #查找热点 最热的5个write
store #查看各个节点的存储情况 和表select * from information_schema.TIKV_STORE_STATUS;一样
operator add split-region 378432 #手动 split
之后再用上面的命令查看表的 region 分布情况,理论上经过一段时间调度后,leader 节点会被自动 rebalance
operator add transfer-leader 378432 20 #把 Region 1 的 leader 调度到 store 2,也可以手动迁移 leader
```
```bash
存储store_id
mysql> select STORE_ID,ADDRESS from information_schema.TIKV_STORE_STATUS;
+-----------+----------------------+
| STORE_ID | ADDRESS |
+-----------+----------------------+
| 120005586 | 172.21.210.27:3930 |
| 1 | 172.21.210.35:20160 |
| 482647 | 172.21.210.26:20160 |
| 7277286 | 172.21.210.22:20160 |
| 7342570 | 172.21.210.37:20160 |
| 9504107 | 172.21.210.100:20160 |
| 7277501 | 172.21.210.25:20160 |
| 7351439 | 172.21.210.56:20160 |
| 120005598 | 172.21.210.25:3930 |
| 117005 | 172.21.210.36:20160 |
| 7192446 | 172.21.210.34:20160 |
| 7351461 | 172.21.210.57:20160 |
+-----------+----------------------+
#查看热点regins
tiup ctl:v4.0.4 pd -i -u http://172.21.210.96:2379
region topread 5 #查找热点 最热的5个read
region topwrite 5 #查找热点 最热的5个write
operator add split-region 378432 #手动 split reginon
迁移regins
mysql> select * from information_schema.TIKV_REGION_PEERS where REGION_ID='9495367';
+-----------+----------+----------+------------+-----------+--------+--------------+
| REGION_ID | PEER_ID | STORE_ID | IS_LEARNER | IS_LEADER | STATUS | DOWN_SECONDS |
+-----------+----------+----------+------------+-----------+--------+--------------+
| 9495367 | 9495368 | 117005 | 0 | 1 | NORMAL | NULL |
| 9495367 | 9504543 | 9504107 | 0 | 0 | NORMAL | NULL |
| 9495367 | 11990971 | 7277286 | 0 | 0 | NORMAL | NULL |
+-----------+----------+----------+------------+-----------+--------+--------------+
3 rows in set (0.61 sec)
tiup ctl:v4.0.4 pd -i -u http://172.21.210.96:2379
>> operator add transfer-leader 9495367 7277286 #迁移热点的learder
mysql> select * from information_schema.TIKV_REGION_PEERS where REGION_ID='9495367';
+-----------+----------+----------+------------+-----------+--------+--------------+
| REGION_ID | PEER_ID | STORE_ID | IS_LEARNER | IS_LEADER | STATUS | DOWN_SECONDS |
+-----------+----------+----------+------------+-----------+--------+--------------+
| 9495367 | 9495368 | 117005 | 0 | 0 | NORMAL | NULL |
| 9495367 | 9504543 | 9504107 | 0 | 0 | NORMAL | NULL |
| 9495367 | 11990971 | 7277286 | 0 | 1 | NORMAL | NULL |
+-----------+----------+----------+------------+-----------+--------+--------------+
```
```bash
#通过 region 找对应表的信息
[root@host-172-21-210-32 ~]# curl http://172.21.210.32:10080/regions/9495367
{
"region_id": 9495367,
"start_key": "dIAAAAAAAElQX2mAAAAAAAAAAgE1MDU5QTZDRf83Njk0RkNBM/9FMDUzOUI2NP80MDBBNTRDM/8AAAAAAAAAAPcDkO9oH9cV1Q0=",
"end_key": "dIAAAAAAAElQX2mAAAAAAAAAAgE1MDU5QTZGMv84Rjc0RkNBM/9FMDUzOUI2NP80MDBBNTRDM/8AAAAAAAAAAPcDkO9oH9c65vA=",
"frames": [
{
"db_name": "platform_address_1",
"table_name": "addr_layer_info_5100_20220308",
"table_id": 18768,
"is_record": false,
"index_name": "idx_gates_code",
"index_id": 2,
"index_values": [
"5059A6CE7694FCA3E0539B64400A54C3",
"1220308510002500877"
]
}
]
}
```