TabletServer: Handle nil targets properly everywhere#14734
TabletServer: Handle nil targets properly everywhere#14734mattlord merged 10 commits intovitessio:mainfrom
Conversation
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
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 <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
deepthi
left a comment
There was a problem hiding this comment.
Can you amend the description with a link to all places where we call tabletenv.LocalContext()? All of those are potentially affected.
| 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.
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 <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
| ctx: ctx, | ||
| logStats: logStats, | ||
| tsv: tsv, | ||
| tabletType: target.GetTabletType(), |
There was a problem hiding this comment.
This returned UNKNOWN if the method receiver (target) is nil.
Signed-off-by: Matt Lord <mattalord@gmail.com>
| 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.
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 <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
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