Skip to content
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

Merged
merged 13 commits into from
Nov 30, 2023

Conversation

jwangace
Copy link
Contributor

@jwangace jwangace commented Nov 24, 2023

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

Signed-off-by: Jun Wang <[email protected]>
Copy link
Contributor

vitess-bot bot commented Nov 24, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Nov 24, 2023
@github-actions github-actions bot added this to the v19.0.0 milestone Nov 24, 2023
Jun Wang added 5 commits November 24, 2023 14:32
@shlomi-noach shlomi-noach self-requested a review November 26, 2023 07:43
Copy link
Contributor

@shlomi-noach shlomi-noach left a 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!

@shlomi-noach shlomi-noach removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels Nov 26, 2023
@jwangace
Copy link
Contributor Author

jwangace commented Nov 27, 2023

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.

Comment on lines 445 to 447
// Only return err when all tablets have errors
if len(tablets) == 0 {
return err
Copy link
Contributor

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

Copy link
Contributor Author

@jwangace jwangace Nov 27, 2023

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
}

Copy link
Contributor

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!

Copy link
Contributor

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 🙏

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated PR

@jwangace jwangace requested a review from ajm188 November 27, 2023 18:52
Copy link
Contributor

@shlomi-noach shlomi-noach left a 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!

Copy link
Contributor

@ajm188 ajm188 left a 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_test.go Outdated Show resolved Hide resolved
Comment on lines 351 to 359
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])
}
Copy link
Contributor

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

Copy link
Contributor

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(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good approach.

jwangace and others added 2 commits November 29, 2023 08:23
Co-authored-by: Andrew Mason <[email protected]>
Signed-off-by: jwangace <[email protected]>
@shlomi-noach shlomi-noach added Backport to: release-18.0 Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Backup and Restore labels Nov 30, 2023
@shlomi-noach shlomi-noach merged commit 43f754e into vitessio:main Nov 30, 2023
116 of 118 checks passed
vitess-bot pushed a commit that referenced this pull request Nov 30, 2023
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]>
shlomi-noach pushed a commit that referenced this pull request Nov 30, 2023
…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]>
@jwangace jwangace deleted the update_method_backupShard branch November 30, 2023 19:50
ejortegau pushed a commit to slackhq/vitess that referenced this pull request Dec 13, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Backup and Restore Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants