-
Notifications
You must be signed in to change notification settings - Fork 753
Tso keyspace group keyspace list length #10218
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: master
Are you sure you want to change the base?
Conversation
Signed-off-by: ystaticy <y_static_y@sina.com>
Signed-off-by: ystaticy <y_static_y@sina.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
|
Hi @ystaticy. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
📝 WalkthroughWalkthroughAdds a per-keyspace-group gauge metric and exposes a setter; refactors bootstrap keyspace ID resolution into internal helpers to avoid import cycles; updates keyspace-group save to update metrics post-commit; adds tests and a go.mod dependency change. Changes
Sequence Diagram(s)sequenceDiagram
participant API as API/Caller
participant KVS as KVStore/Txn
participant DB as Storage
participant TSO as TSO metrics
API->>KVS: saveKeyspaceGroups(groups)
KVS->>DB: RunInTxn(persist groups)
DB-->>KVS: commit success
KVS-->>API: return nil
Note over API,KVS: Post-commit side-effects
loop for each group
API->>TSO: SetKeyspaceGroupKeyspaceCountGauge(groupID, count)
TSO-->>TSO: update gauge vector[label=groupID]
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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: ystaticy <y_static_y@sina.com>
Signed-off-by: ystaticy <y_static_y@sina.com>
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: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
pkg/tso/keyspace_group_manager.go (1)
915-956:⚠️ Potential issue | 🟠 MajorNextGen reserve keyspace can be removed/inserted incorrectly.
WhengetBootstrapKeyspaceIDreturnsSystemKeyspaceID,checkReserveKeyspaceassumes the reserved key is at index 0 (newKeyspaces[1:]) and inserts at the front, which can drop the wrong keyspace and leave the list unsorted. Remove by value and keep the list ordered.🐛 Suggested fix to keep reserved key handling order-safe
func (kgm *KeyspaceGroupManager) checkReserveKeyspace(newGroup *endpoint.KeyspaceGroup, newKeyspaces []uint32, reserveKeyspace uint32) { if newGroup.ID == constant.DefaultKeyspaceGroupID { if _, ok := newGroup.KeyspaceLookupTable[reserveKeyspace]; !ok { log.Warn("this keyspace is not in default keyspace group. add it back", zap.Uint32("keyspace", reserveKeyspace)) kgm.keyspaceLookupTable[reserveKeyspace] = newGroup.ID newGroup.KeyspaceLookupTable[reserveKeyspace] = struct{}{} - newGroup.Keyspaces = make([]uint32, 1+len(newKeyspaces)) - newGroup.Keyspaces[0] = reserveKeyspace - copy(newGroup.Keyspaces[1:], newKeyspaces) + newGroup.Keyspaces = append(append([]uint32{}, newKeyspaces...), reserveKeyspace) + sort.Slice(newGroup.Keyspaces, func(i, j int) bool { + return newGroup.Keyspaces[i] < newGroup.Keyspaces[j] + }) } } else { if _, ok := newGroup.KeyspaceLookupTable[reserveKeyspace]; ok { log.Warn("this keyspace is in non-default keyspace group. remove it", zap.Uint32("keyspace", reserveKeyspace)) kgm.keyspaceLookupTable[reserveKeyspace] = constant.DefaultKeyspaceGroupID delete(newGroup.KeyspaceLookupTable, reserveKeyspace) - newGroup.Keyspaces = newKeyspaces[1:] + filtered := make([]uint32, 0, len(newKeyspaces)-1) + for _, ks := range newKeyspaces { + if ks != reserveKeyspace { + filtered = append(filtered, ks) + } + } + newGroup.Keyspaces = filtered } } }pkg/keyspace/tso_keyspace_group.go (1)
361-372:⚠️ Potential issue | 🟡 MinorDefer gauge metric updates until after the transaction commits.
Updating
SetKeyspaceGroupKeyspaceCountGaugeinside the transaction callback can leave metrics inconsistent with persisted data. If a later iteration'sLoadKeyspaceGrouporSaveKeyspaceGroupfails, the transaction rolls back but earlier gauge updates persist, reflecting a state that was never written to storage.Collect the gauge updates and apply them after
RunInTxnsucceeds.
|
@ystaticy: The following test 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. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #10218 +/- ##
==========================================
+ Coverage 78.63% 78.66% +0.03%
==========================================
Files 520 520
Lines 70089 70112 +23
==========================================
+ Hits 55112 55152 +40
+ Misses 10989 10986 -3
+ Partials 3988 3974 -14
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Issue Number: Close #10219
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
New Features
Tests
Chores