How to check the leader on a specific TiKV, the table and data corresponding to the region

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

Original topic: 我想看某个tikv上面的leader,region对应的表和数据怎么查

| username: 舞动梦灵

I am planning to scale down the servers, specifically the TiKV nodes. During the scaling down process, I want to manually check the data to see if it can be accessed normally. How can I check which table and data a region on a specific store belongs to?

| username: zhanggame1 | Original post link

The INFORMATION_SCHEMA.TIKV_REGION_PEERS can show the region_id, the store_id where it is stored, and whether it is the leader.
The INFORMATION_SCHEMA.TIKV_REGION_STATUS can show the region_id, db_name, and table_name.

| username: DBAER | Original post link

Query like this?

| username: DBAER | Original post link

Mainly checking if the region is healthy?
You can use this command to check if the region is healthy:
tiup cluster check --cluster

| username: 舞动梦灵 | Original post link

Originally, everything was normal. I just wanted to scale down the resources.

| username: 舞动梦灵 | Original post link

Okay. I’ll check it out.

| username: zhanggame1 | Original post link

This way of checking is fine.

| username: zhanggame1 | Original post link

When scaling down resources, you need to ensure that there are at least 3 TiKV instances remaining.

| username: 舞动梦灵 | Original post link

I have 6 of them, and now I want to shrink them one by one, leaving only 3 TiKV. But how can I see which specific data corresponds to this? Is there a way to check? This corresponds to only part of the data in this table, right? It can’t be the whole table, right?

| username: zhanggame1 | Original post link

The 6 regions are definitely part of a table. You don’t really need to look at the specific data; knowing it won’t be useful. If you want to see it, you can convert the start and end keys of the regions into readable data.

| username: TiDBer_小阿飞 | Original post link

The command SELECT TIDB_DECODE_KEY('7480000000000000465F728000002E4717D540') AS decoded_key; can show the corresponding table ID and row ID.
Using pd-ctl region keys --format=hex 7AXXXXXXXX can find out which region it belongs to.
Then, you can check in the information_schema to find out which table it belongs to.

| username: 舞动梦灵 | Original post link

Thanks, brother. Once the leader migration is complete, all queries should no longer be related to this TiKV, right? The remaining regions are just replica data slowly migrating, correct?

| username: zhanggame1 | Original post link

Scale down one by one until the tombstone state.

| username: 小于同学 | Original post link

Learned.