-
Notifications
You must be signed in to change notification settings - Fork 753
core: region heartbeat with bucket meta #10231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-nextgen-20251011
Are you sure you want to change the base?
core: region heartbeat with bucket meta #10231
Conversation
|
This cherry pick PR is for a release branch and has not yet been approved by triage owners. To merge this cherry pick:
DetailsInstructions 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. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis 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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
Signed-off-by: tongjian <1045931706@qq.com>
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
/retest |
1 similar comment
|
/retest |
|
/retest-required |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this 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 | 🔴 CriticalData race:
SetBucketMetais 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'sbucketMetafield without synchronization, while other goroutines may concurrently callGetBuckets()(which readsbucketMeta).The simplest fix is to set
bucketMetaduring construction via theWithBucketMetaoption (beforePutRegion), keeping it consistent with howSetBucketsis 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-
PutRegionSetBucketMetacall: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 | 🔴 CriticalAdd
BucketMetafield to the scheduling service forwarding request at line 1414.The interface now requires
GetBucketMeta(), andRegionFromHeartbeat()calls it at line 250. However, the forwarding code inserver/grpc_service.go(lines 1414–1433) constructsschedulingpbReqwithout theBucketMetafield. 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 newmetapb.Bucketson every call whenbucketMetais set.This is called repeatedly in hot paths — for example, Line 912 calls
GetBuckets()four times withinGenerateRegionGuideFunc(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.
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.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()) }
|
This cherry pick PR is for a release branch and has not yet been approved by triage owners. To merge this cherry pick:
DetailsInstructions 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. |
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lhy1024, okJiang The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@bufferflies: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
What problem does this PR solve?
Issue Number: Ref #10117
CP: #10120
What is changed and how does it work?
Check List
Tests
Code changes
Side effects
Related changes
pingcap/docs/pingcap/docs-cn:pingcap/tiup:Release note
Summary by CodeRabbit
Release Notes
Chores
New Features
Tests