-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Implement "Tablet Targeting" RFC #18809
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: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Nick Van Wiggeren <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #18809 +/- ##
==========================================
+ Coverage 69.68% 69.73% +0.04%
==========================================
Files 1605 1607 +2
Lines 214461 214642 +181
==========================================
+ Hits 149456 149674 +218
+ Misses 65005 64968 -37 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8ecfaf3 to
883637f
Compare
Signed-off-by: Nick Van Wiggeren <[email protected]>
883637f to
8ab64dc
Compare
Signed-off-by: Nick Van Wiggeren <[email protected]>
f77286f to
1eb17dd
Compare
1eb17dd to
29e658c
Compare
Signed-off-by: Nick Van Wiggeren <[email protected]>
3ef8159 to
84f29f0
Compare
Signed-off-by: Nick Van Wiggeren <[email protected]>
84f29f0 to
6c49907
Compare
Signed-off-by: Nick Van Wiggeren <[email protected]>
Signed-off-by: Nick Van Wiggeren <[email protected]>
| info.alias = shardSession.TabletAlias | ||
| info.rowsAffected = shardSession.RowsAffected | ||
| } | ||
| // Override alias if tablet-specific routing is set | ||
| if targetAlias := session.GetTargetTabletAlias(); targetAlias != nil { | ||
| info.alias = targetAlias | ||
| } |
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.
we should error out if info.alias is set and does not match targetAlias if set.
We should also error out during the use command as well if the shard session exists and shardSession.TabletAlias does not match the alias in the use command.
| // Clear any existing tablet-specific routing if not specified | ||
| if tabletAlias == nil { | ||
| vc.SafeSession.SetTargetTabletAlias(nil) | ||
| } else { | ||
| // Store tablet alias in session for routing | ||
| // Note: We don't validate the tablet exists here - if it doesn't exist or is | ||
| // unreachable, the query will fail during execution with a clear error message | ||
| vc.SafeSession.SetTargetTabletAlias(tabletAlias) | ||
|
|
||
| // Keep tabletType as determined by ParseDestination (defaultTabletType) | ||
| // The actual routing uses the tablet alias, so the type is only for VCursor state | ||
| } |
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.
We do not need to call this. As on the next query a new vcursor object will be created and that will set the tabletAlias based on the session target.
|
|
||
| // TestTargetTabletAlias tests the SetTargetTabletAlias and GetTargetTabletAlias methods. | ||
| func TestTargetTabletAlias(t *testing.T) { | ||
| session := NewSafeSession(&vtgatepb.Session{}) | ||
|
|
||
| // Test: initially nil | ||
| assert.Nil(t, session.GetTargetTabletAlias()) |
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 test on thread safety is not required.
A connection as a contract cannot be shared, so no one can call SetTarget in parallel.
| // Query different replicas and verify different server UUIDs | ||
| // This proves we're actually hitting different physical tablets | ||
| for range 10 { |
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.
not sure if we need this for loop here
| if tabletAlias != nil && dest == nil { | ||
| return "", defaultTabletType, nil, nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "tablet alias must be used with a shard") | ||
| } | ||
| return keyspace, tabletType, dest, tabletAlias, nil |
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.
If there is a destination then it will not go through the planner? The query will be shard targeted.
Is this the expectation?
|
Promptless docs suggestions: https://app.gopromptless.ai/change-history/3cbec78d-1d26-4d49-8801-a64abf8827c0 |
Description
This PR adds the ability for a user to target a specific tablet by alias when doing
USE, instead of only being able to pick a type for a shard. This means that a user can get "stable" routing, which is extremely useful when they don't have access to the underlying MySQL instance and need to do things like debug.Related Issue(s)
Checklist
AI Disclosure
This PR was written hand-in-hand with Claude Code, which absolutely got the initial few approaches extremely incorrect and required a lot of human help. Robot isn't going to take my job any time soon.