Skip to content

ddl,executor: fix usages of getting regions from pd client (#63371)#63379

Merged
ti-chi-bot[bot] merged 4 commits into
pingcap:release-nextgen-20250815from
ti-chi-bot:cherry-pick-63371-to-release-nextgen-20250815
Sep 5, 2025
Merged

ddl,executor: fix usages of getting regions from pd client (#63371)#63379
ti-chi-bot[bot] merged 4 commits into
pingcap:release-nextgen-20250815from
ti-chi-bot:cherry-pick-63371-to-release-nextgen-20250815

Conversation

@ti-chi-bot

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #63371

What problem does this PR solve?

Issue Number: close #61702

Problem Summary:

The old impl doesn't work in next-gen because the keys are not encoded by the keyspace.

What changed and how does it work?

  • Use store.GetCodec() to encode region ranges before sending get-region requests.
  • Add a test for information_schema.tikv_region_status.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    Sysbench 20,000,000 rows (tableSizeInBytes=4.092GiB):
[2025/09/04 14:44:00.614 +08:00] [INFO] [reorg_util.go:134] ["initialize reorg meta"] [keyspaceName=keyspace1] [category=ddl] [jobSchema=test] [jobTable=sbtest1] [jobType="add index"] [enableDistTask=true] [enableFastReorg=true] [targetScope=dxf_service] [maxNodeCount=1] [tableSizeInBytes=4.092GiB] [concurrency=1] [batchSize=256]

Before this PR:

mysql> select * from information_schema.tikv_region_status where table_id = 7;
+-----------+--------------------+--------------------+----------+---------+------------+----------+----------+------------+--------------+--------------+----------------+----------------+---------------+---------------+------------+------------------+------------------+-------------------------+---------------------------+
| REGION_ID | START_KEY          | END_KEY            | TABLE_ID | DB_NAME | TABLE_NAME | IS_INDEX | INDEX_ID | INDEX_NAME | IS_PARTITION | PARTITION_ID | PARTITION_NAME | EPOCH_CONF_VER | EPOCH_VERSION | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE | APPROXIMATE_KEYS | REPLICATIONSTATUS_STATE | REPLICATIONSTATUS_STATEID |
+-----------+--------------------+--------------------+----------+---------+------------+----------+----------+------------+--------------+--------------+----------------+----------------+---------------+---------------+------------+------------------+------------------+-------------------------+---------------------------+
|        14 | 72FFFFFF00000000FB | 7800000100000000FB |        7 | test    | sbtest1    |        1 |        1 | k_1        |            0 |         NULL | NULL           |              1 |            11 |             0 |          0 |                1 |                0 | NULL                    |                      NULL |
|        14 | 72FFFFFF00000000FB | 7800000100000000FB |        7 | test    | sbtest1    |        0 |     NULL | NULL       |            0 |         NULL | NULL           |              1 |            11 |             0 |          0 |                1 |                0 | NULL                    |                      NULL |
+-----------+--------------------+--------------------+----------+---------+------------+----------+----------+------------+--------------+--------------+----------------+----------------+---------------+---------------+------------+------------------+------------------+-------------------------+---------------------------+
2 rows in set (1 min 20.46 sec)

mysql> show table sbtest1 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 |
+-----------+------------------------------------------------+------------------------------------------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+------------------------+------------------+
|       270 | t_7_i_1_038000000001089dc20380000000000c530300 | t_7_r_4716102                                  |       271 |               1 | 271   |          0 |             0 |          0 |                 1031 |          4741227 |                        |                  |
|       272 | t_7_r_4716102                                  | t_7_r_9358899                                  |       273 |               1 | 273   |          0 |             0 |          0 |                 1029 |          4670598 |                        |                  |
|       274 | t_7_r_9358899                                  | t_7_r_14381182                                 |       275 |               1 | 275   |          0 |             0 |          0 |                 1040 |          5041457 |                        |                  |
|       146 | t_7_r_14381182                                 | t_281474976710596_                             |       147 |               1 | 147   |          0 |             0 |          0 |                 1177 |          5735440 |                        |                  |
|       276 | t_7_                                           | t_7_i_1_0380000000002426cb03800000000054a65e   |       277 |               1 | 277   |          0 |             0 |          0 |                    1 |                0 |                        |                  |
|       278 | t_7_i_1_0380000000002426cb03800000000054a65e   | t_7_i_1_03800000000098f7150380000000002ccea1   |       279 |               1 | 279   |          0 |             0 |          0 |                   72 |          9998595 |                        |                  |
|       280 | t_7_i_1_03800000000098f7150380000000002ccea1   | t_7_i_1_038000000001089dc20380000000000c530300 |       281 |               1 | 281   |          0 |             0 |          0 |                   72 |         10001405 |                        |                  |
+-----------+------------------------------------------------+------------------------------------------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+------------------------+------------------+
7 rows in set (0.01 sec)

After this PR:

mysql> show table sbtest1 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 |
+-----------+-------------------------------------------------+-------------------------------------------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+------------------------+------------------+
|       274 | t_15_i_1_038000000001089dc20380000000000c475b00 | t_15_r_5337962                                  |       275 |               1 | 275   |          0 |             0 |          0 |                 1027 |          5366615 |                        |                  |
|       276 | t_15_r_5337962                                  | t_15_r_10418020                                 |       277 |               1 | 277   |          0 |             0 |          0 |                 1034 |          5097457 |                        |                  |
|       278 | t_15_r_10418020                                 | t_15_r_14976190                                 |       279 |               1 | 279   |          0 |             0 |          0 |                 1010 |          4609699 |                        |                  |
|       146 | t_15_r_14976190                                 | t_281474976710596_                              |       147 |               1 | 147   |          0 |             0 |          0 |                 1127 |          5124631 |                        |                  |
|       280 | t_15_                                           | t_15_i_1_0380000000002426cb0380000000005494a1   |       281 |               1 | 281   |          0 |             0 |          0 |                    1 |                0 |                        |                  |
|       282 | t_15_i_1_0380000000002426cb0380000000005494a1   | t_15_i_1_03800000000098f7150380000000002cc988   |       283 |               1 | 283   |          0 |             0 |          0 |                   72 |          9998595 |                        |                  |
|       284 | t_15_i_1_03800000000098f7150380000000002cc988   | t_15_i_1_038000000001089dc20380000000000c475b00 |       285 |               1 | 285   |          0 |             0 |          0 |                   72 |         10001405 |                        |                  |
+-----------+-------------------------------------------------+-------------------------------------------------+-----------+-----------------+-------+------------+---------------+------------+----------------------+------------------+------------------------+------------------+
7 rows in set (0.01 sec)

mysql> select * from information_schema.tikv_region_status where table_id = 15;
+-----------+--------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+----------+---------+------------+----------+----------+------------+--------------+--------------+----------------+----------------+---------------+---------------+------------+------------------+------------------+-------------------------+---------------------------+
| REGION_ID | START_KEY                                                                                                    | END_KEY                                                | TABLE_ID | DB_NAME | TABLE_NAME | IS_INDEX | INDEX_ID | INDEX_NAME | IS_PARTITION | PARTITION_ID | PARTITION_NAME | EPOCH_CONF_VER | EPOCH_VERSION | WRITTEN_BYTES | READ_BYTES | APPROXIMATE_SIZE | APPROXIMATE_KEYS | REPLICATIONSTATUS_STATE | REPLICATIONSTATUS_STATEID |
+-----------+--------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+----------+---------+------------+----------+----------+------------+--------------+--------------+----------------+----------------+---------------+---------------+------------+------------------+------------------+-------------------------+---------------------------+
|       274 | 7800000174800000FF000000000F5F6980FF0000000000000103FF8000000001089DC2FF0380000000000C47FF5B00000000000000F9 | 7800000174800000FF000000000F5F7280FF0000000051736A00FE |     NULL | NULL    | NULL       |        0 |     NULL | NULL       |            0 |         NULL | NULL           |              1 |            72 |             0 |          0 |             1027 |          5366615 | NULL                    |                      NULL |
|       276 | 7800000174800000FF000000000F5F7280FF0000000051736A00FE                                                       | 7800000174800000FF000000000F5F7280FF000000009EF76400FE |     NULL | NULL    | NULL       |        0 |     NULL | NULL       |            0 |         NULL | NULL           |              1 |            70 |             0 |          0 |             1034 |          5097457 | NULL                    |                      NULL |
|       278 | 7800000174800000FF000000000F5F7280FF000000009EF76400FE                                                       | 7800000174800000FF000000000F5F7280FF00000000E484BE00FE |     NULL | NULL    | NULL       |        0 |     NULL | NULL       |            0 |         NULL | NULL           |              1 |            71 |             0 |          0 |             1010 |          4609699 | NULL                    |                      NULL |
|       146 | 7800000174800000FF000000000F5F7280FF00000000E484BE00FE                                                       | 78000001748000FFFFFFFFFFFFC4000000FC                   |     NULL | NULL    | NULL       |        0 |     NULL | NULL       |            0 |         NULL | NULL           |              1 |            71 |             0 |          0 |             1127 |          5124631 | NULL                    |                      NULL |
+-----------+--------------------------------------------------------------------------------------------------------------+--------------------------------------------------------+----------+---------+------------+----------+----------+------------+--------------+--------------+----------------+----------------+---------------+---------------+------------+------------------+------------------+-------------------------+---------------------------+
4 rows in set (0.01 sec)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-20250815 labels Sep 4, 2025
@ti-chi-bot

Copy link
Copy Markdown
Member Author

@D3Hunter This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot

ti-chi-bot Bot commented Sep 4, 2025

Copy link
Copy Markdown

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Signed-off-by: tangenta <tangenta@126.com>
@ti-chi-bot ti-chi-bot Bot added the approved label Sep 5, 2025
@tangenta tangenta removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 5, 2025
@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 5, 2025
@ti-chi-bot

ti-chi-bot Bot commented Sep 5, 2025

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: D3Hunter, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 5, 2025
@ti-chi-bot

ti-chi-bot Bot commented Sep 5, 2025

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2025-09-05 01:32:46.066956311 +0000 UTC m=+143510.050053759: ☑️ agreed by tangenta.
  • 2025-09-05 01:51:35.513845862 +0000 UTC m=+144639.496943309: ☑️ agreed by D3Hunter.

@D3Hunter

D3Hunter commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

/retest

1 similar comment
@D3Hunter

D3Hunter commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

/retest

@D3Hunter D3Hunter changed the title ddl,executor: fix usages of getting regions from pd client (#63371) ddl,executor: fix usages of getting regions from pd client (#63371) | tidb-test=pr/2595 Sep 5, 2025
@D3Hunter

D3Hunter commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

/retest

@D3Hunter D3Hunter changed the title ddl,executor: fix usages of getting regions from pd client (#63371) | tidb-test=pr/2595 ddl,executor: fix usages of getting regions from pd client (#63371) Sep 5, 2025
Signed-off-by: tangenta <tangenta@126.com>
Signed-off-by: tangenta <tangenta@126.com>
@D3Hunter

D3Hunter commented Sep 5, 2025

Copy link
Copy Markdown
Contributor

/retest

@ti-chi-bot ti-chi-bot Bot merged commit 375aac0 into pingcap:release-nextgen-20250815 Sep 5, 2025
5 checks passed
@ti-chi-bot ti-chi-bot Bot deleted the cherry-pick-63371-to-release-nextgen-20250815 branch September 5, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-20250815

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants