-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
TabletServer: Handle nil targets properly everywhere #14734
Conversation
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[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
|
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
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.
Can you amend the description with a link to all places where we call tabletenv.LocalContext()
? All of those are potentially affected.
@@ -625,7 +631,10 @@ func (tsv *TabletServer) Rollback(ctx context.Context, target *querypb.Target, t | |||
target, nil, true, /* allowOnShutdown */ | |||
func(ctx context.Context, logStats *tabletenv.LogStats) error { | |||
defer tsv.stats.QueryTimings.Record("ROLLBACK", time.Now()) | |||
defer tsv.stats.QueryTimingsByTabletType.Record(target.TabletType.String(), time.Now()) | |||
// With a tabletenv.LocalContext() the target can be nil. | |||
if target != 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.
I think what LocalContext means is that this tablet is talking to itself versus another tablet.
In which case, if we care about these stats, we can use tsv.sm.Target()
to get what the current target is, and get the tablet type from that.
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
@@ -846,7 +880,7 @@ func (tsv *TabletServer) execute(ctx context.Context, target *querypb.Target, sq | |||
ctx: ctx, | |||
logStats: logStats, | |||
tsv: tsv, | |||
tabletType: target.GetTabletType(), |
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 returned UNKNOWN
if the method receiver (target) is nil.
Signed-off-by: Matt Lord <[email protected]>
if tsv.sm.Target() == nil { | ||
return topodatapb.ShardReplicationError_UNKNOWN.String(), vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION, "TabletServer has no current target") | ||
} | ||
return tsv.sm.Target().String(), 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.
Interestingly:
https://github.com/vitessio/vitess/blob/main/go/vt/vttablet/tabletserver/tabletserver.go#L168-L172
Should we add a nil check on tsv.sm.Target()
in line 172 while we are at it?
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
…14734) (#14741) Signed-off-by: Matt Lord <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Signed-off-by: Matt Lord <[email protected]>
Description
When executing queries locally using the local TabletServer, you use a
tabletenv.LocalContext
: https://github.com/vitessio/vitess/blob/main/go/vt/vttablet/tabletserver/tabletenv/local_context.goAnd when using this the target tablet is
nil
(or at least it can be) — otherwise an error is returned. For example:vitess/go/vt/vttablet/tabletserver/state_manager.go
Lines 419 to 440 in 08b2c8b
You can see all checks for it here: https://github.com/search?q=repo%3Avitessio%2Fvitess%20IsLocalContext&type=code
And you can see the uses of it here (all the locations impacted by the bug): https://github.com/search?q=repo%3Avitessio%2Fvitess%20tabletenv.LocalContext&type=code
This means that in the TabletServer code we can never assume that the target is not nil and we need to check for it. We added some new places where we use that variable in #13521 for stats, but we didn't add a nil check. So this PR adds that along with a unit test.
The new unit test fails on
main
:Related Issue(s)
Checklist