Skip to content

br: Allow Skip Finegrained Scatter to Speed up Split & Scatter - #69175

Merged
ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
YuJuncen:skip-finegrained-scatter
Jun 23, 2026
Merged

ti-chi-bot[bot] merged 7 commits into
pingcap:masterfrom
YuJuncen:skip-finegrained-scatter

Conversation

@YuJuncen

@YuJuncen YuJuncen commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #69173

Problem Summary:

BR snapshot restore currently scatters both rough split regions and fine split regions. For restore workloads that only need coarse-grained region balancing, scattering every fine split region can add unnecessary PD scheduling work.

What changed and how does it work?

This PR adds two BR snapshot restore flags:

  • --coarse-scatter, defaulting to false.
  • --split-region-index-step, a hidden flag defaulting to 128, which controls the number of split-key indexes between two rough split keys.

When --coarse-scatter=true, snapshot restore still scatters the rough split regions, then performs the final fine split pass without scattering those fine split regions. The default restore behavior is unchanged.

Both flags are passed through RestoreConfig to SnapClient, then into RegionSplitter. The existing SplitKeysAndScatter behavior remains unchanged, while the BR restore path can call the same split flow with scatter disabled for the final split pass.

A playground verification record is included in br_coarse_scatter_playground_verification.md.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Unit test commands:

./tools/check/failpoint-go-test.sh br/pkg/restore/split -run 'Test(SplitScatter|RegionSplitterRoughSplitUsesConfiguredRegionIndexStep)$' -count=1
./tools/check/failpoint-go-test.sh br/pkg/task -run 'Test(SplitRegionIndexStepFlag|RestoreConfigAdjust|ConfigureRestoreClient|Default)$' -count=1
make lint
git diff --check

Manual test:

go build -o /tmp/br-coarse-scatter ./br/cmd/br
tiup playground v9.0.0-beta.2.pre-nightly --db 1 --pd 1 --kv 3 --tiflash 0 --without-monitor --tag br-coarse-scatter-verify

Then two database backup/restore runs were compared:

  • Default restore with --split-region-index-step=2: BR restore log had 5 scatter regions entries.
  • Restore with --split-region-index-step=2 --coarse-scatter=true: BR restore log had 1 scatter regions entry, before finish spliting regions roughly, and no fine split scatter entries afterward.

See br_coarse_scatter_playground_verification.md for the full commands and outputs.

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.

Add the `--coarse-scatter` option for BR snapshot restore to scatter only rough split regions, and the hidden `--split-region-index-step` option to configure rough split granularity.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added SplitRegionIndexStep tuning for restore rough-region splitting.
    • Added CoarseScatter to control whether scattering is applied only during the rough-split phase.
    • Enhanced region splitting to support non-scattering splits for key sets.
  • Tests

    • Expanded coverage to verify rough-split key sampling and correct scatter vs non-scatter invocation behavior.
    • Updated restore configuration tests to assert the new default values and flag parsing.

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 15, 2026
@tiprow

tiprow Bot commented Jun 15, 2026

Copy link
Copy Markdown

Hi @YuJuncen. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes-sigs/prow repository.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 04627c68-b5ca-4b97-bd5e-b3b787b09f9b

📥 Commits

Reviewing files that changed from the base of the PR and between 2bdce0b and 994d836.

📒 Files selected for processing (4)
  • br/pkg/restore/snap_client/client.go
  • br/pkg/task/BUILD.bazel
  • br/pkg/task/common_test.go
  • br/pkg/task/restore.go
✅ Files skipped from review due to trivial changes (1)
  • br/pkg/task/common_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • br/pkg/restore/snap_client/client.go
  • br/pkg/task/restore.go

📝 Walkthrough

Walkthrough

Introduces a two-phase region splitting strategy for snapshot restore. A coarse first pass splits and scatters a subset of keys sampled at configurable regionIndexStep intervals; a fine second pass splits all keys with scatter behavior controlled by a new coarseScatter flag. New CLI flags, RestoreConfig fields, SnapClient accessors, and a SplitKeys (no-scatter) client interface method wire the full stack.

Changes

Two-phase rough/fine region splitting with scatter control

Layer / File(s) Summary
Split client scatter-control interface and SplitKeys implementation
br/pkg/restore/split/client.go, br/pkg/restore/split/client_test.go, br/pkg/restore/split/mock_pd_client.go
Adds SplitKeys to SplitClient interface. Refactors SplitKeysAndScatter and SplitWaitAndScatter to delegate to shared helpers with a scatter bool. splitWaitAndMaybeScatter gates scatterRegions on that flag. Result regions are only accumulated when scatter is enabled. Mocks and a new test assertion cover the no-scatter path.
RegionSplitter rough-split configuration and two-phase execution
br/pkg/restore/split/split.go, br/pkg/restore/split/split_test.go
Adds DefaultRegionIndexStep, NormalizeRegionIndexStep, NewRegionSplitterWithRegionIndexStep constructor, and SetCoarseScatter setter. executeSplitByRanges now runs a coarse phase (subset of keys, scatter=true) then a full phase (scatter toggled by coarseScatter). A splitKeys helper routes to the appropriate client method. Old codec-mapping test removed; new recordingSplitClient and TestRegionSplitterRoughSplitUsesConfiguredRegionIndexStep added.
SnapClient configuration fields and splitter integration
br/pkg/restore/snap_client/client.go, br/pkg/restore/snap_client/tikv_sender.go
Adds splitRegionIndexStep and coarseScatter to SnapClient struct, initialized in NewRestoreClient. Exposes four logged accessors with normalization. SplitPoints constructs RegionSplitter via NewRegionSplitterWithRegionIndexStep.
RestoreConfig flags, validation, normalization, and client wiring
br/pkg/task/restore.go, br/pkg/task/BUILD.bazel, br/pkg/task/common_test.go, br/pkg/task/config_test.go, br/pkg/task/restore_nokit_test.go
Exports FlagSplitRegionIndexStep (hidden) and FlagCoarseScatter. Adds fields to RestoreConfig with TOML/JSON tags. ParseFromFlags reads and validates both (step must be >0). Adjust normalizes step. configureRestoreClient calls the new SnapClient setters. Bazel dependency updated. Tests cover defaults, flag parsing, step=0 error, and getter assertions.

Sequence Diagram(s)

sequenceDiagram
    rect rgba(173, 216, 230, 0.5)
        Note over CLI,RegionSplitter: Configuration wiring
        CLI->>RestoreConfig: ParseFromFlags(FlagSplitRegionIndexStep, FlagCoarseScatter)
        RestoreConfig->>RestoreConfig: Adjust: NormalizeRegionIndexStep
        RestoreConfig->>SnapClient: SetSplitRegionIndexStep(step)
        RestoreConfig->>SnapClient: SetCoarseScatter(coarseScatter)
    end

    rect rgba(144, 238, 144, 0.5)
        Note over SnapClient,pdClient: Two-phase split execution
        SnapClient->>RegionSplitter: NewRegionSplitterWithRegionIndexStep(splitClient, step)
        RegionSplitter->>RegionSplitter: derive coarseKeys via regionIndexStep
        RegionSplitter->>pdClient: SplitKeysAndScatter(coarseKeys) [phase 1, scatter=true]
        pdClient-->>RegionSplitter: coarse regions scattered
        RegionSplitter->>pdClient: SplitKeys or SplitKeysAndScatter(fullKeys) [phase 2, scatter=!coarseScatter]
        pdClient-->>RegionSplitter: fine regions
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size/L, release-note-none, ok-to-test

Suggested reviewers

  • 3pointer
  • Leavrth

Poem

🐇 Hop, hop through the keyspace wide,
A coarse pass first, then fine inside,
Scatter fewer, split just right,
Two phases make the restore light.
The rabbit optimized with glee —
Less scatter time, more hops for free! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.32% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly identifies the main change: allowing skipping fine-grained scatter to speed up the split and scatter process.
Description check ✅ Passed The PR description comprehensively covers the problem statement, solution approach, test coverage, and documentation impact, following the template structure.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #69173 by adding --coarse-scatter and --split-region-index-step flags to reduce scatter duration in huge clusters.
Out of Scope Changes check ✅ Passed All code changes are directly related to implementing the two new restore flags and their integration throughout the restore pipeline.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.74194% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.1825%. Comparing base (21e43a8) to head (994d836).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69175        +/-   ##
================================================
- Coverage   76.3192%   76.1825%   -0.1367%     
================================================
  Files          2041       2068        +27     
  Lines        561223     577136     +15913     
================================================
+ Hits         428321     439677     +11356     
- Misses       132000     135485      +3485     
- Partials        902       1974      +1072     
Flag Coverage Δ
integration 45.9315% <67.7419%> (+6.2669%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 60.4610% <ø> (ø)
parser ∅ <ø> (∅)
br 64.2037% <67.7419%> (+1.4299%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
br/pkg/restore/split/mock_pd_client.go (1)

113-119: ⚡ Quick win

Differentiate scatter vs non-scatter behavior in these test doubles.

At Line 113/117 and Line 701/705, both method pairs behave identically, so tests using these clients can’t detect scatter-routing regressions. Please record/assert scatter intent separately (or simulate scatter side effects only in SplitKeysAndScatter) to keep these fixtures contract-faithful.

Also applies to: 701-707

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@br/pkg/restore/split/mock_pd_client.go` around lines 113 - 119, The
SplitKeysAndScatter and SplitKeys methods in the mock client currently have
identical implementations, both calling SplitWaitAndScatter with the same
parameters, which prevents tests from detecting scatter-routing regressions.
Differentiate these two methods by ensuring SplitKeysAndScatter simulates or
records the scatter operation behavior while SplitKeys does not, either by
passing different parameters to SplitWaitAndScatter or by calling different
underlying methods. Apply this differentiation at both locations mentioned in
the comment (around lines 113-119 and lines 701-707) to maintain consistent
contract-faithful test fixtures that can distinguish between scatter and
non-scatter routing paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@br/pkg/restore/split/mock_pd_client.go`:
- Around line 113-119: The SplitKeysAndScatter and SplitKeys methods in the mock
client currently have identical implementations, both calling
SplitWaitAndScatter with the same parameters, which prevents tests from
detecting scatter-routing regressions. Differentiate these two methods by
ensuring SplitKeysAndScatter simulates or records the scatter operation behavior
while SplitKeys does not, either by passing different parameters to
SplitWaitAndScatter or by calling different underlying methods. Apply this
differentiation at both locations mentioned in the comment (around lines 113-119
and lines 701-707) to maintain consistent contract-faithful test fixtures that
can distinguish between scatter and non-scatter routing paths.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5ae4a6bb-dab8-4241-b569-57a3129d5475

📥 Commits

Reviewing files that changed from the base of the PR and between f4da686 and 58381e8.

📒 Files selected for processing (5)
  • br/pkg/restore/split/client.go
  • br/pkg/restore/split/client_test.go
  • br/pkg/restore/split/mock_pd_client.go
  • br/pkg/restore/split/split.go
  • br/pkg/restore/split/split_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • br/pkg/restore/split/client_test.go
  • br/pkg/restore/split/split.go

@ti-chi-bot ti-chi-bot Bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 16, 2026
@YuJuncen

Copy link
Copy Markdown
Contributor Author

/retest-required

@tiprow

tiprow Bot commented Jun 17, 2026

Copy link
Copy Markdown

@YuJuncen: PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test.

Details

In response to this:

/retest-required

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 kubernetes-sigs/prow repository.

@YuJuncen

Copy link
Copy Markdown
Contributor Author

/retest-required

@YuJuncen

Copy link
Copy Markdown
Contributor Author

/retest

@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Leavrth, RidRisR

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 Jun 23, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-06-16 05:10:33.421039027 +0000 UTC m=+1455134.491356437: ☑️ agreed by Leavrth.
  • 2026-06-23 05:29:08.518856528 +0000 UTC m=+11832.182082042: ☑️ agreed by RidRisR.

@Leavrth

Leavrth commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@ti-chi-bot ti-chi-bot Bot added the ok-to-test Indicates a PR is ready to be tested. label Jun 23, 2026
@ti-chi-bot
ti-chi-bot Bot merged commit 6092703 into pingcap:master Jun 23, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

br: reduce region scatter durtion for huge clusters

3 participants