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

Workflow Status: change logic to determine whether MoveTables writes are switched #16731

Conversation

rohit-nayak-ps
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps commented Sep 7, 2024

Description

We use the table routing rules to decide where reads and writes are routed for tables which are part of MoveTables workflows.

For each table we have rules like

t1 => source.t1 
source.t1 => source.t1
t1@replica => source.t1@replica
source.t1@replica => source.t1@replica
target.t1 => source.t1

when no traffic is switched, or when all traffic is switched:

t1 => target.t1 
source.t1 => target.t1
t1@replica => target.t1@replica
source.t1@replica => target.t1@replica
target.t1 => target.t1

To determine whether writes are switched, we check the route for t1. If it is pointing to target it is considered that writes have been switched.

The problem comes the same table exists in different source keyspaces. For example if there are two workflows one from source1=>target1 and another from source2=>target2, both with a table t1.

Now if one workflow's writes are switched we end up with the route for t1 pointing to target1.t1. When the next workflow's writes are switched we now overwrite that rule so that it points to target2.t1. The logic now assumes writes for the first workflow have not been switched.

Fix:
In general, global routing rules don't make sense in such cases. But as an initial quick fix we change the logic to looking at the source.t1 key instead of t1. In our case then after the two workflows have been switched we will get source1.t1 => target1.t1 and source2.t1 => target2.t1, resulting in the right state being deduced.

We do the same for for replica/rdonly types as well.

Related Issue(s)

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

…ting rule state for given workflow

Signed-off-by: Rohit Nayak <[email protected]>
…o check for where writes are routed

Signed-off-by: Rohit Nayak <[email protected]>
…rget keyspaces. Add test to simulate this in routing rules

Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Copy link
Contributor

vitess-bot bot commented Sep 7, 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 Sep 7, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Sep 7, 2024
Signed-off-by: Rohit Nayak <[email protected]>
@rohit-nayak-ps rohit-nayak-ps added Type: Bug Component: VReplication and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels Sep 7, 2024
Copy link

codecov bot commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 68.92%. Comparing base (538dd4c) to head (a847429).
Report is 88 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtctl/workflow/server.go 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16731      +/-   ##
==========================================
- Coverage   68.98%   68.92%   -0.06%     
==========================================
  Files        1562     1565       +3     
  Lines      200690   201748    +1058     
==========================================
+ Hits       138449   139058     +609     
- Misses      62241    62690     +449     

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

@rohit-nayak-ps rohit-nayak-ps removed the NeedsIssue A linked issue is missing for this Pull Request label Sep 8, 2024
Signed-off-by: Rohit Nayak <[email protected]>
@rohit-nayak-ps rohit-nayak-ps removed the NeedsBackportReason If backport labels have been applied to a PR, a justification is required label Sep 9, 2024
@rohit-nayak-ps rohit-nayak-ps marked this pull request as ready for review September 9, 2024 10:28
go/vt/vtctl/workflow/framework_test.go Show resolved Hide resolved
go/vt/vtctl/workflow/framework_test.go Outdated Show resolved Hide resolved
go/vt/vtctl/workflow/server.go Show resolved Hide resolved
Comment on lines 1037 to 1038
rr := globalRules[fmt.Sprintf("%s.%s", sourceKeyspace, table)]
if len(rr) > 0 && rr[0] != fmt.Sprintf("%s.%s", sourceKeyspace, table) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can calculate this key once. That's more efficient and prevents any accidental drift.

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)

func setupMoveTables(t *testing.T, ctx context.Context) *testEnv {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really usable outside of this file and its test? If not, better IMO to include it in the test (can be a func var).

go/vt/vtctl/workflow/workflow_state_test.go Outdated Show resolved Hide resolved
go/vt/vtctl/workflow/workflow_state_test.go Show resolved Hide resolved
Signed-off-by: Rohit Nayak <[email protected]>
go/vt/vtctl/workflow/server.go Show resolved Hide resolved
@rohit-nayak-ps rohit-nayak-ps merged commit 490bb0c into vitessio:main Sep 20, 2024
129 checks passed
@rohit-nayak-ps rohit-nayak-ps deleted the rohit/workflow-state-use-scoped-routing-rule branch September 20, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants