Are regions in TiKV pre-allocated? How to check the distribution of the current sizes of all regions?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiKV中的region是否预先分配好的?如何查看当前所有region大小的分布情况?

| username: alfred

【TiDB Usage Environment】Production\Test Environment\POC
【TiDB Version】
【Encountered Problem】
【Reproduction Path】What operations were performed that led to the problem
【Problem Phenomenon and Impact】

| username: WalterWj | Original post link

  1. No
  2. You can use pd-ctl to export all region information, then use jq or write a script to analyze the JSON content.
| username: h5n1 | Original post link

You can query the region distribution by performing a join query on tikv_region_status, tikv_store_status, and tikv_region_peers under Information-schema, or use pd-ctl region store xxx to view the regions on certain stores.

| username: TiDBer_jYQINSnf | Original post link

When a TiKV cluster starts, there is an initial region with a range of startkey=“” and endkey=“”, which can accommodate all keys. This region continuously splits, similar to cell division, where one becomes two.

In Grafana, there is a regionsize panel where you can see the size statistics of the regions.

| username: wuxiangdong | Original post link

Pre-allocation, manual allocation, and automatic allocation are all possible.

| username: tidb狂热爱好者 | Original post link

Are there any commands to check the allocation status?

| username: alfred | Original post link

How is a Region split?

Regions are not pre-divided, but there is indeed a Region splitting mechanism. When the size of a Region exceeds the value of the parameters region-max-size or region-max-keys, splitting is triggered, and the information after the split is reported to PD.

| username: alfred | Original post link

Is the default split size 96MB?

| username: Lucien-卢西恩 | Original post link

Yes, the logic for Region splitting and scheduling can be referred to in the document link above.

| username: OnTheRoad | Original post link

When it reaches 144MB in size, it will split into two.

| username: alfred | Original post link

In the course, some say it splits at 96MB, while others say it splits at 144MB. I’m not sure at what size it actually splits.

| username: OnTheRoad | Original post link

  1. The default size of a Region is 96MB (controlled by the TiKV configuration parameter region-split-size);

  2. When a Region expands to exceed 144MB (controlled by the TiKV configuration parameter region-max-size, default is 96MBx3/2=144MB), it will be split into two.

| username: alfred | Original post link

That is, region-max-size = 1.5 * region-split-size, by default it starts splitting at 144MB, :+1:

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.