-
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
increase vtctlclient backupShard command success rate #14604
increase vtctlclient backupShard command success rate #14604
Conversation
Signed-off-by: Jun Wang <[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: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[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.
LGTM. We can potentially rewrite the if/else/loop logic somewhat to unify the different scenarios, but it's also good as it is. Thank you!
Hi @shlomi-noach Correct, it could be more precise in the future, what I proposed was the simplest format to be less buggy. With this change, our current way of backup method would be happy. Thanks for the review and approval. |
// Only return err when all tablets have errors | ||
if len(tablets) == 0 { | ||
return err |
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 is a small chance that we are doing BackupShard --allow-primary
and the shard has exactly one tablet (the primary), and this could incorrectly fail. i'd suggest: if len(tablets) < len(shardTablets)
instead
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.
Hi @ajm188 do you mean that the shard is built only with 1 tablet, so it's the only 1 and primary?
if the code changed to:
if err != nil {
...
if len(tablets) < len(shardTablets) {
return err
}
}
In normal cases (tablets >= 2), then it should equivelant to before and does not fix the bug, becase len(tablets) < len(shardTablets) should always true when err != nil
if err != nil {
return err
}
Instead, can I suggest tablets should always include the PRIMARY and no matter it's stat nil or non-nil?
shardTablets, stats, err := reparentutil.ShardReplicationStatuses(ctx, s.ts, s.tmc, req.Keyspace, req.Shard)
var tablets []*topo.TabletInfo
// Instead of return on err directly, only return when no healthy tablets at all
if err != nil {
for i, stat := range stats {
// Always include TabletType_PRIMARY
if shardTablets[i].Type == topodatapb.TabletType_PRIMARY {
tablets = append(tablets, shardTablets[i])
continue
}
// shardTablets[i] and stats[i] is 1:1 mapping
// Healthy shardTablets[i] will be added to tablets
if stat != nil {
tablets = append(tablets, shardTablets[i])
}
}
// Only return err when no usable tablet
if len(tablets) == 0 {
return err
}
} else {
tablets = shardTablets
}
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.
ah good point.
do you mean that the shard is built only with 1 tablet, so it's the only 1 and primary?
yes, that's what i mean.
i missed that the if len(tablets) == 0
happened inside the if err != nil
check, not outside, so i think this is a moot point. sorry for the confusion!
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.
OK, given the intricate logic here I'd like to suggest extracting the logic into a separate function and adding a unit test suite to validate expected outcome of different scenarios 🙏
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 agree with Shlomi here
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.
updated PR
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[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.
Looks great, appreciate the unit tests!
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.
couple small things, but looking good!
go/vt/vtctl/reparentutil/util.go
Outdated
if tablets[i].Type == topodatapb.TabletType_PRIMARY { | ||
res = append(res, tablets[i]) | ||
continue | ||
} | ||
// shardTablets[i] and stats[i] is 1:1 mapping | ||
// Healthy shardTablets[i] will be added to tablets | ||
if stat != nil { | ||
res = append(res, tablets[i]) | ||
} |
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.
suggest condensing this into either a switch
or if/else
and avoiding the continue
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.
alternatively:
if tablets[i].Type == topodatapb.TabletType_PRIMARY || stats != nil {
res = append(...)
}
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.
Good approach.
Co-authored-by: Andrew Mason <[email protected]> Signed-off-by: jwangace <[email protected]>
Signed-off-by: Jun Wang <[email protected]>
Signed-off-by: Jun Wang <[email protected]> Signed-off-by: jwangace <[email protected]> Co-authored-by: Jun Wang <[email protected]> Co-authored-by: Andrew Mason <[email protected]>
…14604) (#14639) Signed-off-by: Jun Wang <[email protected]> Signed-off-by: jwangace <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com> Co-authored-by: Jun Wang <[email protected]> Co-authored-by: Andrew Mason <[email protected]>
Signed-off-by: Jun Wang <[email protected]> Signed-off-by: jwangace <[email protected]> Co-authored-by: Jun Wang <[email protected]> Co-authored-by: Andrew Mason <[email protected]>
Description
In the case of at least one tablet being healthy, this PR would increase the chance of successful backup, by only returning Primary + healthy tablets.
In the case of all Non-Primary tablets having errors, vtctlclient should fail in the same way.
Related Issue(s)
#14602