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

SwitchTraffic: use separate context while canceling a migration #17340

Merged

Conversation

rohit-nayak-ps
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps commented Dec 5, 2024

Description

Use a fresh context in cancelMigration() so that the rollback steps will happen independent of any timeouts on the client side.

We should backport this to supported versions since failures in SwitchTraffic can cause cluster unavailability.

Related Issue(s)

#17326

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Copy link
Contributor

vitess-bot bot commented Dec 5, 2024

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 NeedsBackportReason If backport labels have been applied to a PR, a justification is required 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 Dec 5, 2024
@github-actions github-actions bot added this to the v22.0.0 milestone Dec 5, 2024
@rohit-nayak-ps rohit-nayak-ps added Type: Bug Component: VReplication Backport to: release-19.0 Needs to be back ported to release-19.0 Backport to: release-20.0 Needs to be backport to release-20.0 Backport to: release-21.0 Needs to be backport to release-21.0 and 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 NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Dec 5, 2024
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Project coverage is 67.46%. Comparing base (ab7b516) to head (1ab5b14).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtctl/workflow/traffic_switcher.go 0.00% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17340      +/-   ##
==========================================
+ Coverage   67.41%   67.46%   +0.04%     
==========================================
  Files        1576     1581       +5     
  Lines      253417   253944     +527     
==========================================
+ Hits       170846   171328     +482     
- Misses      82571    82616      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// We create a new context while canceling the migration, so that we are independent of the original
// context being cancelled prior to or during the cancel operation.
cmTimeout := 60 * time.Second
cmCtx, cmCancel := context.WithTimeout(context.Background(), cmTimeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

It probably does not matter logically, but I'm often wondering whether semantically context.WithoutCancel would be more accurate in this situation?

Suggested change
cmCtx, cmCancel := context.WithTimeout(context.Background(), cmTimeout)
cmCtx, cmCancel := context.WithTimeout(context.WithoutCancel(ctx), cmTimeout)

It probably makes no difference as we're not using values stored on the context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is possible that we get here when the ctx is already cancelled. In the specific case which lead us to this issue the client had a short timeout and original context's deadline had already expired.

@arthurschreiber
Copy link
Contributor

arthurschreiber commented Dec 6, 2024

I think I've run into this before, where switching traffic back and forth could lead to one side of the workflow (either the reverse or the original one) being deleted if a timeout is hit. Does this sound familiar? 🤔

@rohit-nayak-ps
Copy link
Contributor Author

I think I've run into this before, where switching traffic back and forth could lead to one side of the workflow (either the reverse or the original one) being deleted if a timeout is hit. Does this sound familiar? 🤔

If you reverse traffic then the source should not have any reverse workflow running since we are still doing forward vreplication (no traffic is switched). So the reverse workflow will get deleted.

Signed-off-by: Rohit Nayak <[email protected]>
@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review December 9, 2024 07:55
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

❤️ IMO it's worth adding a unit test [case] where we call cancel with a canceled context but it's such a simple and obvious change that it's not required.

} else {
err = ts.changeShardsAccess(ctx, ts.SourceKeyspaceName(), ts.SourceShards(), allowWrites)
err = ts.changeShardsAccess(cmCtx, ts.SourceKeyspaceName(), ts.SourceShards(), allowWrites)
}
if err != nil {
ts.Logger().Errorf("Cancel migration failed: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should take this opportunity to improve the log message:

ts.Logger().Errorf("Cancel migration failed: could not revert denied tables / shared access: %v", err)

I also think that we should accumulate these and return them to the caller. But we could defer that change.

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 the log message. Let's make the changes to pass them to the caller separately since we are not returning the error at the moment.

Signed-off-by: Rohit Nayak <[email protected]>
@rohit-nayak-ps rohit-nayak-ps merged commit e4dc872 into vitessio:main Dec 10, 2024
101 checks passed
@rohit-nayak-ps rohit-nayak-ps deleted the rohit/cancel-migration-own-context branch December 10, 2024 20:18
vitess-bot pushed a commit that referenced this pull request Dec 10, 2024
vitess-bot pushed a commit that referenced this pull request Dec 10, 2024
frouioui pushed a commit that referenced this pull request Dec 11, 2024
…migration (#17340) (#17366)

Signed-off-by: Rohit Nayak <[email protected]>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
frouioui pushed a commit that referenced this pull request Dec 11, 2024
…migration (#17340) (#17365)

Signed-off-by: Rohit Nayak <[email protected]>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport to: release-19.0 Needs to be back ported to release-19.0 Backport to: release-20.0 Needs to be backport to release-20.0 Backport to: release-21.0 Needs to be backport to release-21.0 Component: VReplication Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants