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 should switch everything when no tablet_types provided #10434

Merged
merged 6 commits into from
Jun 6, 2022

Conversation

mattlord
Copy link
Contributor

@mattlord mattlord commented Jun 5, 2022

Description

The default --tablet_types value for the SwitchTraffic command was errantly changed in #10040 where we generally made in_order:REPLICA,PRIMARY the default --tablet_types value in VReplication. For SwitchTraffic, we should be switching traffic for all tablet types when none are specified: https://vitess.io/docs/14.0/reference/vreplication/switchtraffic/#--tablet_types

⚠️ After further testing, however, it became clear that we never handled SwitchedTraffic for RDONLY tablets when no value was specified for --tablet_types. That's because the flag has a default value so it was never an empty string here and the override was never applied (before or after changing what we overrode it to). From v13:

vitess/go/vt/vtctl/vtctl.go

Lines 2443 to 2448 in 12fc1f0

case vReplicationWorkflowActionSwitchTraffic, vReplicationWorkflowActionReverseTraffic:
vrwp.Cells = *cells
vrwp.TabletTypes = *tabletTypes
if vrwp.TabletTypes == "" {
vrwp.TabletTypes = "primary,replica,rdonly"
}

So, in this PR we do the following:

  1. Check if the --tablet_types flag was passed on the command line, and if not then we use the new override to switch everything by default
  2. Updated the endtoend test so that it explicitly tests the behavior when no --tablet_flag value was provided on the command-line when we intend to switch all traffic
  3. Added to the endtoend tests so that we are using RDONLY tablets and confirm that traffic for them is also switched when doing SwitchTraffic w/o a --tablet_types flag value

I will also update the v14 docs to the new default here of: in_order:RDONLY,REPLICA,PRIMARY

Related Issue(s)

Checklist

@mattlord mattlord added Type: Bug Component: VReplication release notes none release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) and removed release notes none labels Jun 5, 2022
@mattlord mattlord requested a review from rohit-nayak-ps June 5, 2022 07:00
@mattlord mattlord removed the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Jun 5, 2022
@mattlord mattlord marked this pull request as ready for review June 5, 2022 17:38
@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2022

Review Checklist

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

General

  • Ensure that the Pull Request has the correct release notes label. release notes none should only be used for PRs that are so trivial that they need not be included.
  • If a new flag is being introduced, review whether it is really needed. The flag names should be clear and intuitive (as far as possible), and the flag's help should be descriptive.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should either include a link to an issue that describes the bug OR an actual description of the bug and how to reproduce, along with a description of the fix.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.

@mattlord mattlord force-pushed the switch_all_traffic branch from 4cb388d to 7dbbd96 Compare June 6, 2022 02:27
Meaning that we don't explicitly specify a tablet_types value and
leverage the command default which should be:
in_order:RDONLY,REPLICA,PRIMARY

This also requires that the tests actually create RDONLY tablets, so
do that for the basic v2 workflow tests.

Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the switch_all_traffic branch from 7dbbd96 to 8f41bcf Compare June 6, 2022 02:33
mattlord added 2 commits June 6, 2022 01:42
And test traffic switching of RDONLY tablets

Signed-off-by: Matt Lord <[email protected]>
@mattlord mattlord force-pushed the switch_all_traffic branch from c103ad8 to 88392e2 Compare June 6, 2022 06:23

// userPassedFlag returns true if the flag name given was provided
// as a command-line argument by the user.
func userPassedFlag(flags *flag.FlagSet, name string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

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

lgtm
nice catch

@mattlord
Copy link
Contributor Author

mattlord commented Jun 6, 2022

Manual test to confirm fix for #10421:

$ cd examples/local

$ ./101_initial_cluster.sh ; ./201_customer_tablets.sh ; ./202_move_tables.sh

$ vtctlclient --server=localhost:15999 MoveTables SwitchTraffic customer.commerce2customer
SwitchTraffic was successful for workflow customer.commerce2customer
Start State: Reads Not Switched. Writes Not Switched
Current State: All Reads Switched. Writes Switched

@mattlord mattlord deleted the switch_all_traffic branch June 6, 2022 16:08
DeathBorn pushed a commit to vinted/vitess that referenced this pull request Apr 12, 2024
…itessio#10434)

* We should switch everything when no tablet_types provided

* Update help output to clarify behavior

* Update SwitchTraffic [all|default] tests for user facing client behavior

Meaning that we don't explicitly specify a tablet_types value and
leverage the command default which should be:
in_order:RDONLY,REPLICA,PRIMARY

This also requires that the tests actually create RDONLY tablets, so
do that for the basic v2 workflow tests.

* Properly handle SwitchTraffic default

And test traffic switching of RDONLY tablets

* Only add RDONLY tables in default Cell

Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Vilius Okockis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: vtctlclient MoveTables SwitchTraffic doesnt switch readonly traffic
2 participants