问题背景:
通过granfan-->pd-->region health 图表监控到empty region 较多,且此集群目前业务并不多,数据量也很小,初始化时只创建了较表。
问题排查:
查看region merge相关参数:
l max-merge-region-size:
##控制region merge的大小上限,当region大于指定值时pd不会将相邻的region合并(默认20)
l max-merge-region-keys:
##控制region merge的key上限,当region大于指定值时pd不会将相邻的region合并(默认2000)
l merge-schedule-limit:
##同时进行region merge调度的任务数,设置为则关闭region merge(默认值8)
如下,这些参数都是默认值,
$ pd-ctl config show max-merge-region-size |grep max-merge-region-size "max-merge-region-size": 20, $ pd-ctl config show max-merge-region-keys |grep max-merge-region-keys "max-merge-region-keys": 200000, $ pd-ctl config show merge-schedule-limit |grep merge-schedule-limit "merge-schedule-limit": 8, |
查看region的split和merge频率相关参数,
l patrol-region-interval:
##控制replicaChecker检查region监控状态的运行频率,越短则运行越快(10ms)
l split-merge-interval:
##控制对同一个region做split和merge的操作间隔,对应新split的region一段时间不会merge(默认1h)
$ pd-ctl config show patrol-region-interval |grep patrol "patrol-region-interval": "100ms", $ pd-ctl config show split-merge-interval |grep split "split-merge-interval": "1h0m0s", |
测试ddl时与分配的region是否会merge:
突然想到,空regions多的集群在ddl时使用了region预分配参数,查看相关表时只有1个region,在社区咨询老师说是被merge了。
创建测试表并预分配region,查看region数是指定的:
mysql> create table guo004(id int, name varchar(10)) SHARD_ROW_ID_BITS=4 PRE_SPLIT_REGIONS=4; Query OK, 0 rows affected (0.51 sec) mysql> show table guo004 regions; +-----------+-----------------------------+-----------------------------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+ | REGION_ID | START_KEY | END_KEY | LEADER_ID | LEADER_STORE_ID | PEERS | SCATTERING | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE(MB) | APPROXIMATE_KEYS | +-----------+-----------------------------+-----------------------------+-----------+-----------------+---------------------+------------+---------------+------------+----------------------+------------------+ | 25373 | t_437_ | t_437_r_576460752303423488 | 25375 | 5 | 25374, 25375, 25376 | 0 | 341 | 0 | 1 | 0 | | 25377 | t_437_r_576460752303423488 | t_437_r_1152921504606846976 | 25379 | 5 | 25378, 25379, 25380 | 0 | 29 | 0 | 1 | 0 | | 25381 | t_437_r_1152921504606846976 | t_437_r_1729382256910270464 | 25383 | 5 | 25382, 25383, 25384 | 0 | 0 | 0 | 1 | 0 | | 25385 | t_437_r_1729382256910270464 | t_437_r_2305843009213693952 | 25387 | 5 | 25386, 25387, 25388 | 0 | 0 | 0 | 1 | 0 | | 25389 | t_437_r_2305843009213693952 | t_437_r_2882303761517117440 | 25391 | 5 | 25390, 25391, 25392 | 0 | 29 | 0 | 1 | 0 | | 25393 | t_437_r_2882303761517117440 | t_437_r_3458764513820540928 | 25395 | 5 | 25394, 25395, 25396 | 0 | 0 | 0 | 1 | 0 | | 25397 | t_437_r_3458764513820540928 | t_437_r_4035225266123964416 |