-
Notifications
You must be signed in to change notification settings - Fork 774
keyspace: cache meta-service group status #10976
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
Open
bufferflies
wants to merge
13
commits into
tikv:master
Choose a base branch
from
bufferflies:pr-cp-10892-cache-meta-service-group-status
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+611
−189
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
373334d
keyspace: cache meta-service group status (#463)
AmoebaProtozoa c4a0aa9
keyspace: refine meta-service group status cache
bufferflies 13a9e89
Merge remote-tracking branch 'origin/master' into pr10976
bufferflies f01ce3e
Merge remote-tracking branch 'origin/master' into pr10976
bufferflies f514e59
keyspace: persist group changes before updating in-memory view
bufferflies 77936b6
keyspace: add HasGroups to avoid map copy on create path
bufferflies e5262c6
keyspace: serialize meta-service group flush with synchronous writes
bufferflies e036819
keyspace: reset persisted status when re-adding a meta-service group
bufferflies 6580fdc
keyspace: revert TSO keyspace group move on config txn commit failure
bufferflies 88ae189
keyspace: merge patched fields into cached meta-service group status
bufferflies 28bbf4b
keyspace: roll back config txn side effects under the meta-group lock
bufferflies 52c082b
keyspace: flush meta-service group status off the mgm lock, fenced to…
bufferflies 91caa0b
keyspace: mark added groups dirty when status reconcile fails
bufferflies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Keep rollback under the meta-service group lock and cover commit failures.
Line 955 runs after
runTxnWithMetaGroupLockhas already deferred-unlocked, soUpdateGroupsSafelycan observe transient reassignment counts before rollback. Also,RunInTxncan fail at commit afterUpdateKeyspaceGrouphas persisted, but this outer error path only reverts the meta-service cache. Move all non-transactional rollback into the locked helper/error path and include the TSO group move.Suggested shape
Then track successful
UpdateKeyspaceGroupside effects alongsidemetaServiceGroupReassigned, and revert both from the rollback callback before the lock is released.Also applies to: 953-959
🤖 Prompt for AI Agents
✅ Addressed in commits b9b3eed to f01ce3e
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.
This still looks unresolved on the current head (
77936b6d).UpdateKeyspaceGroupis persisted before the keyspace-metaRunInTxncommits. The rollback inside theSaveKeyspaceMetaerror branch only covers errors returned beforeRunInTxncommits; ifRunInTxnreturns a commit conflict/error aftertxnFuncreturns nil, the outer error path only rolls back the meta-service cache and never moves the TSO keyspace group fromnewIDback tooldID.Please roll back successful
UpdateKeyspaceGroupside effects from the outerRunInTxnerror path as well, preferably while still holding the meta-service group manager lock.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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 8907
@lhy1024, you're right — this is still open.store.RunInTxn(inpkg/storage/kv/etcd_kv.go) runstxnFuncand then callstxn.commit()separately, so a commit-time failure aftertxnFuncreturnsnilbypasses the inline revert inside theSaveKeyspaceMetaerror branch entirely, and the outer error path inupdateKeyspaceConfigTxn(Line 955 area) only reverts the meta-service assignment count, never theUpdateKeyspaceGroupmove.I'll centralize both rollbacks into a single callback invoked by
runTxnWithMetaGroupLockon any error while themgmlock is still held, and drop the now-redundant inline revert to avoid double-reverting.runTxnWithMetaGroupLockto accept arollback func()invoked on anyRunInTxnerror, before the lock is released.updateKeyspaceConfigTxn, hoistoldUserKind/newUserKind/oldID/newIDto function scope and track whetherUpdateKeyspaceGroupsucceeded.This makes rollback fire exactly once per failure, whether the failure originates inside
txnFunc(e.g.SaveKeyspaceMetaerror) or fromRunInTxn's commit step aftertxnFuncreturnsnil, and both reverts happen before themgmlock is released.🧬 Code Graph Analysis Results
Relevant code snippets
pkg/keyspace/keyspace.goL
318-L362 —runTxnWithMetaGroupLock(holdsmgmlock across the storage txn)L
364-L463 —updateKeyspaceConfigTxn(showsUpdateKeyspaceGrouppersistence timing and the outerRunInTxnerror rollback behavior)pkg/keyspace/tso_keyspace_group.goL
696-L762 —GroupManager.UpdateKeyspaceGroup(persists the keyspace group move immediately; used byupdateKeyspaceConfigTxn)pkg/storage/kv/etcd_kv.goL
212-L222 —RunInTxn(commit happens aftertxnFuncreturns nil; commit conflict can surface viaRunInTxnerror)L
56-L67 —StorageEndpoint.SaveKeyspaceMeta(the meta write happens inside the txn passed toRunInTxn)pkg/keyspace/meta_service_group.goL
411-L421 —MetaServiceGroupManager.AttachEndpoints(used after successful config update)L
437-L441 —MetaServiceGroupManager.HasGroups(guards assignment paths in other keyspace creation/config flows)Failed to handle agent chat message. Please try again.
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.
6580fdc0now covers commit-time TSO rollback, but the rollback still runs afterrunTxnWithMetaGroupLockreleases the manager lock. A second config update can acquire that lock and persist another TSO group move before lines 972–980 run; the first request then applies its stale rollback over the successful update, leaving group membership inconsistent with committed keyspace metadata. The meta-service count rollback has the same interleaving window.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.
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.
Fixed in 6580fdc. The TSO keyspace group move is now tracked (
keyspaceGroupMoved) and reverted from the outer error path as well, covering a commit-time failure aftertxnFuncreturns nil; the flag prevents the inner revert from being duplicated.Follow-up 28bbf4b takes the mgm lock across the outer rollback (both the TSO move and the meta-service assignment) so the undo is atomic with respect to
UpdateGroupsSafely, per your note about keeping it under the lock.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.
Fixed in 28bbf4b. The outer rollback (both the TSO keyspace group move and the meta-service assignment) now runs while holding the mgm lock, taken in a deferred-unlock closure, so it is atomic with respect to
UpdateGroupsSafelyand a second config update cannot interleave a TSO move between the failed commit and the rollback.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.
The current head still releases the manager lock when
runTxnWithMetaGroupLockreturns at line 966 and only reacquires it at line 977. A second config update can therefore still run in that gap before the stale rollback, so the interleaving described above remains.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.
This is still open after
28bbf4b6. The error path now reacquiresmgm.Lock(), butrunTxnWithMetaGroupLockhas already released the original lock before returning. A later config update can acquire the lock and commit in that gap, after which the failed request reacquires it and applies a stale rollback over the successful update.A deterministic state-transition test reproduces the same interleaving:
old -> failedand releases the lock when its txn fails;old -> committed;failed -> old.The expected source count is
0, but the stale rollback restores it to1:Please run the rollback from inside
runTxnWithMetaGroupLock, before its deferred unlock, for example via an error rollback callback. Releasing and reacquiring the same mutex does not preserve atomicity.