Skip to content

Conversation

@bufferflies
Copy link
Contributor

@bufferflies bufferflies commented Feb 9, 2026

What problem does this PR solve?

Issue Number: Ref #10117
CP: #10120

What is changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

Summary by CodeRabbit

Release Notes

  • Chores

    • Updated core dependencies to latest compatible version across all modules
  • New Features

    • Introduced bucket metadata support for regions with version-aware tracking
    • Enhanced region comparison logic to account for bucket version changes
  • Tests

    • Added test coverage for bucket metadata inheritance scenarios
    • Added test coverage for region behavior with updated metadata

Signed-off-by: tongjian <1045931706@qq.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/cherry-pick-not-approved release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the dco. labels Feb 9, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 9, 2026

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
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
Copy link

coderabbitai bot commented Feb 9, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request updates the kvproto dependency across multiple go.mod files and introduces bucket metadata support to RegionInfo. Bucket metadata is captured from heartbeats, stored in regions, propagated during inheritance and synchronization, and used for version-aware bucket comparisons in region guidance logic.

Changes

Cohort / File(s) Summary
Dependency Updates
go.mod, client/go.mod, tests/integrations/go.mod, tools/go.mod
Updated github.com/pingcap/kvproto from v0.0.0-20250923091925-d79d11002599 to v0.0.0-20260106110113-438649d89ee7 across all module definitions.
Bucket Metadata Core Support
pkg/core/region.go
Added bucketMeta field to RegionInfo; introduced SetBucketMeta() method and extended GetBuckets() to return bucketMeta when present. Updated Clone() to copy bucketMeta, Inherit() to conditionally propagate bucket metadata, and RegionFromHeartbeat() to capture bucketMeta from heartbeat. Extended RegionHeartbeatRequest interface with GetBucketMeta() and modified GenerateRegionGuideFunc to use version-aware bucket comparison logic.
Region Creation Options
pkg/core/region_option.go
Added WithBucketMeta() option to set bucket metadata during region creation.
Syncer Integration
pkg/syncer/client.go
Added SetBucketMeta() call in region synchronization to propagate bucket metadata during bucket version updates.
Tests
pkg/core/region_test.go, server/cluster/cluster_test.go
Added TestGetBucketMeta() to verify bucket metadata inheritance behavior and TestStaleBucketMeta() to validate bucket metadata handling across heartbeats and region splits.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • lhy1024

Poem

🐰 Buckets now wear metadata tags,
Flowing through heartbeats like treasure maps,
Versions compared with wisdom and care,
Regions inherit with buckets to spare! 🪣✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description omits the 'What is changed and how does it work?' explanation section, leaving only an empty commit-message block. Add a detailed explanation of the changes in the 'What is changed and how does it work?' section. Include the commit-message describing the bucket metadata support feature implementation.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing bucket metadata support in region heartbeats, which is the core objective across multiple files.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 9, 2026
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 9, 2026
Signed-off-by: tongjian <1045931706@qq.com>
@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.62%. Comparing base (13ab99f) to head (d1a30a0).
⚠️ Report is 6 commits behind head on release-nextgen-20251011.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           release-nextgen-20251011   #10231      +/-   ##
============================================================
- Coverage                     78.68%   78.62%   -0.06%     
============================================================
  Files                           491      491              
  Lines                         66238    66338     +100     
============================================================
+ Hits                          52117    52158      +41     
- Misses                        10354    10413      +59     
  Partials                       3767     3767              
Flag Coverage Δ
unittests 78.62% <80.95%> (-0.06%) ⬇️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 9, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 9, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-09 07:49:43.443231005 +0000 UTC m=+171199.137370855: ☑️ agreed by lhy1024.
  • 2026-02-09 09:23:03.250077026 +0000 UTC m=+176798.944216856: ☑️ agreed by okJiang.

@bufferflies
Copy link
Contributor Author

/retest

1 similar comment
@bufferflies
Copy link
Contributor Author

/retest

@bufferflies
Copy link
Contributor Author

/retest-required

@rleungx
Copy link
Member

rleungx commented Feb 11, 2026

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/syncer/client.go (1)

222-245: ⚠️ Potential issue | 🔴 Critical

Data race: SetBucketMeta is called after the region is already stored in the shared cache.

On Line 239, bc.PutRegion(region) makes the region visible to other goroutines. Then on Line 244, region.SetBucketMeta(buckets[i]) mutates the region's bucketMeta field without synchronization, while other goroutines may concurrently call GetBuckets() (which reads bucketMeta).

The simplest fix is to set bucketMeta during construction via the WithBucketMeta option (before PutRegion), keeping it consistent with how SetBuckets is already handled:

🐛 Proposed fix to eliminate the data race
 				if hasBuckets {
 					opts = append(opts, core.SetBuckets(buckets[i]))
+					opts = append(opts, core.WithBucketMeta(&metapb.BucketMeta{
+						Version: buckets[i].GetVersion(),
+						Keys:    buckets[i].GetKeys(),
+					}))
 				}
 				region = core.NewRegionInfo(r, regionLeader, opts...)

And remove or guard the post-PutRegion SetBucketMeta call:

 				if hasBuckets {
 					if old := origin.GetBuckets(); buckets[i].GetVersion() > old.GetVersion() {
 						region.UpdateBuckets(buckets[i], old)
-						region.SetBucketMeta(buckets[i])
 					}
 				}
pkg/core/region.go (1)

207-222: ⚠️ Potential issue | 🔴 Critical

Add BucketMeta field to the scheduling service forwarding request at line 1414.

The interface now requires GetBucketMeta(), and RegionFromHeartbeat() calls it at line 250. However, the forwarding code in server/grpc_service.go (lines 1414–1433) constructs schedulingpbReq without the BucketMeta field. This causes bucket metadata from the original heartbeat to be silently dropped when forwarding to the scheduling service.

Missing field in forward request
schedulingpbReq := &schedulingpb.RegionHeartbeatRequest{
    // ... existing fields ...
    QueryStats:      request.GetQueryStats(),
    // Missing: BucketMeta field assignment
}

Add: BucketMeta: request.GetBucketMeta(),

🤖 Fix all issues with AI agents
In `@pkg/core/region_test.go`:
- Around line 1460-1461: Replace the truncated comment "// Inherit false if
region" with a complete sentence that explains the expected behavior in this
test: e.g., "Inherit should not override buckets when region has bucketMeta
set." Reference the test target by name (region) and the assertions using
region.GetBuckets().GetVersion() so readers understand this assertion verifies
that Inherit does not modify bucket metadata/version for a region that already
has bucketMeta.

In `@pkg/core/region.go`:
- Around line 617-623: SetBucketMeta writes the plain pointer field bucketMeta
on RegionInfo without synchronization, causing a data race when GetBuckets or
other readers access bucketMeta concurrently (e.g., after bc.PutRegion(region)).
Fix by making bucketMeta an atomic pointer (e.g.,
atomic.Pointer[metapb.BucketMeta] or unsafe.Pointer with
atomic.StorePointer/atomic.LoadPointer) and update SetBucketMeta to use atomic
store and GetBuckets to use atomic load; alternatively, ensure callers set
bucketMeta before calling PutRegion (update syncer path where SetBucketMeta is
invoked) so no concurrent readers observe a non-atomic write. Ensure references
to bucketMeta in RegionInfo, SetBucketMeta, and GetBuckets are updated
consistently.
🧹 Nitpick comments (2)
pkg/core/region.go (1)

645-651: GetBuckets() allocates a new metapb.Buckets on every call when bucketMeta is set.

This is called repeatedly in hot paths — for example, Line 912 calls GetBuckets() four times within GenerateRegionGuideFunc (executed per heartbeat). Each call allocates a new struct.

At minimum, cache the result in local variables at Line 912:

♻️ Suggested optimization in GenerateRegionGuideFunc
-			if region.GetBuckets().GetVersion() > origin.GetBuckets().GetVersion() || (region.GetBuckets().GetVersion() == 0 && origin.GetBuckets().GetVersion() > 0) {
+			regionBuckets := region.GetBuckets()
+			originBuckets := origin.GetBuckets()
+			if regionBuckets.GetVersion() > originBuckets.GetVersion() || (regionBuckets.GetVersion() == 0 && originBuckets.GetVersion() > 0) {
 				if log.GetLevel() <= zap.DebugLevel {
 					debug("bucket key changed",
 						zap.Uint64("region-id", region.GetID()),
-						zap.Uint64("old-bucket-version", origin.GetBuckets().GetVersion()),
-						zap.Uint64("new-bucket-version", region.GetBuckets().GetVersion()))
+						zap.Uint64("old-bucket-version", originBuckets.GetVersion()),
+						zap.Uint64("new-bucket-version", regionBuckets.GetVersion()))
 				}
server/cluster/cluster_test.go (1)

620-654: Consider strengthening assertions and testing the "stale" path.

  1. Line 653 only asserts re.NotEqual(bucket1, region1.GetBuckets()) — a negative check. Consider also asserting the expected state (e.g., the new bucket version) to catch regressions more precisely.

  2. The test name is TestStaleBucketMeta, but it only tests that a newer bucket meta (v3) replaces old buckets (v2). It doesn't verify that a stale (older version) bucket meta is correctly rejected. Adding that scenario would match the test name and increase coverage.

💡 Suggested additions
 	region1 := cluster.GetRegion(1)
 	re.NotEqual(bucket1, region1.GetBuckets())
+	re.Equal(uint64(3), region1.GetBuckets().GetVersion())
+
+	// Stale bucket meta (version < current) should not overwrite
+	staleBucketMeta := &metapb.BucketMeta{
+		Version: 1,
+		Keys:    [][]byte{{'c'}, {'d'}},
+	}
+	region3 := region2.Clone(core.WithIncVersion(), core.WithBucketMeta(staleBucketMeta))
+	re.NoError(cluster.processRegionHeartbeat(core.ContextTODO(), region3))
+	re.Equal(uint64(3), cluster.GetRegion(1).GetBuckets().GetVersion())
 }

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 11, 2026

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
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.

ti-chi-bot and others added 5 commits February 11, 2026 14:48
close tikv#10035

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
ref tikv#9707

With the adjustment of metering rules on the metering side, it is no longer necessary to report DFS-related statistics.
This PR removes the related code.

Signed-off-by: JmPotato <github@ipotato.me>

Co-authored-by: JmPotato <github@ipotato.me>
… (tikv#10096)

ref tikv#9629

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
close tikv#10062

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Signed-off-by: bufferflies <1045931706@qq.com>
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 11, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 11, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lhy1024, okJiang
Once this PR has been reviewed and has the lgtm label, please assign niubell for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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 removed the approved label Feb 11, 2026
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Feb 11, 2026

@bufferflies: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen-2 a789c5e link true /test pull-unit-test-next-gen-2
pull-unit-test-next-gen-1 a789c5e link true /test pull-unit-test-next-gen-1

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/cherry-pick-not-approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants