Skip to content

Vtctldclient MoveTables#13015

Merged
mattlord merged 104 commits intovitessio:mainfrom
planetscale:vtctldclient_movetables
Jul 25, 2023
Merged

Vtctldclient MoveTables#13015
mattlord merged 104 commits intovitessio:mainfrom
planetscale:vtctldclient_movetables

Conversation

@mattlord
Copy link
Member

@mattlord mattlord commented May 2, 2023

Description

This work migrates the vtctl MoveTables client command to vtctldclient. In the process we also do some refactoring to eliminate at least some of the generation of SQL statements in vtctld which are sent to vttablets using the VReplicationExec tabletmanager RPC and instead call purpose-built tabletmanager RPCs so that the tablet controls the implementation and we eliminate upgrade/downgrade issues.

This PR also moves the MoveTables related steps in the local examples to vtctldclient. Finally, it also moves all MoveTables related steps in the endtoend tests to use vtctldclient except for the vreplication_v2 workflow (we will have the vtctlclient implementation around still for quite some time and need to test that as well).

Example Output
❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" Create --source-keyspace "commerce" --tables "customer,corder"
The following vreplication streams exist for workflow customer.commerce2customer:

id=1 on customer/zone1-201: Status: Copying. VStream Lag: 0s.

❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format text Cancel
Successfully cancelled the commerce2customer workflow in the customer keyspace


❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format json Create --source-keyspace "commerce" --tables "customer,corder"
{
  "table_copy_state": {},
  "shard_streams": {
    "customer/0": {
      "streams": [
        {
          "id": 2,
          "tablet": {
            "cell": "zone1",
            "uid": 201
          },
          "source_shard": "commerce/0",
          "position": "",
          "status": "Copying",
          "info": "VStream has not started"
        }
      ]
    }
  }
}

❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format json Cancel
{
  "summary": "Successfully cancelled the commerce2customer workflow in the customer keyspace",
  "details": [
    {
      "tablet": {
        "cell": "zone1",
        "uid": 201
      },
      "deleted": true
    }
  ]
}

❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" SwitchTraffic --dry-run
SwitchTraffic dry run results for workflow customer.commerce2customer at 10 Jul 23 16:54 UTC

Lock keyspace commerce
Switch reads for tables [corder,customer] to keyspace customer for tablet types [PRIMARY,REPLICA,RDONLY]
Routing rules for tables [corder,customer] will be updated
Unlock keyspace commerce
Lock keyspace commerce
Lock keyspace customer
Stop writes on keyspace commerce for tables [corder,customer]: [keyspace:commerce;shard:0;position:MySQL56/1f5a0d8c-1f42-11ee-8b4e-b10505092187:1-51]
Wait for vreplication on stopped streams to catchup for up to 30s
Create reverse vreplication workflow commerce2customer_reverse
Create journal entries on source databases
Enable writes on keyspace customer for tables [corder,customer]
Switch routing from keyspace commerce to keyspace customer
Routing rules for tables [corder,customer] will be updated
Switch writes completed, freeze and delete vreplication streams on: [tablet:201]
Start reverse vreplication streams on: [tablet:101]
Mark vreplication streams frozen on: [keyspace:customer;shard:0;tablet:201;workflow:commerce2customer;dbname:vt_customer]
Unlock keyspace customer
Unlock keyspace commerce


❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format json SwitchTraffic --dry-run
{
  "summary": "SwitchTraffic dry run results for workflow customer.commerce2customer at 10 Jul 23 16:57 UTC",
  "dry_run_results": [
    "Lock keyspace commerce",
    "Switch reads for tables [corder,customer] to keyspace customer for tablet types [PRIMARY,REPLICA,RDONLY]",
    "Routing rules for tables [corder,customer] will be updated",
    "Unlock keyspace commerce",
    "Lock keyspace commerce",
    "Lock keyspace customer",
    "Stop writes on keyspace commerce for tables [corder,customer]: [keyspace:commerce;shard:0;position:MySQL56/adfe5ffc-1f42-11ee-8b41-4c6d40f922ba:1-47]",
    "Wait for vreplication on stopped streams to catchup for up to 30s",
    "Create reverse vreplication workflow commerce2customer_reverse",
    "Create journal entries on source databases",
    "Enable writes on keyspace customer for tables [corder,customer]",
    "Switch routing from keyspace commerce to keyspace customer",
    "Routing rules for tables [corder,customer] will be updated",
    "Switch writes completed, freeze and delete vreplication streams on: [tablet:201]",
    "Start reverse vreplication streams on: [tablet:100]",
    "Mark vreplication streams frozen on: [keyspace:customer;shard:0;tablet:201;workflow:commerce2customer;dbname:vt_customer]",
    "Unlock keyspace customer",
    "Unlock keyspace commerce"
  ]
}

❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" SwitchTraffic --tablet-types "rdonly,replica"
SwitchTraffic was successful for workflow customer.commerce2customer

Start State: Reads Not Switched. Writes Not Switched
Current State: All Reads Switched. Writes Not Switched


❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format json SwitchTraffic --tablet-types primary
{
  "summary": "SwitchTraffic was successful for workflow customer.commerce2customer",
  "start_state": "All Reads Switched. Writes Not Switched",
  "current_state": "All Reads Switched. Writes Switched"
}

❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" Complete --dry-run
Complete dry run results for workflow customer.commerce2customer at 10 Jul 23 17:07 UTC

Lock keyspace commerce
Lock keyspace customer
Dropping these tables from the database and removing them from the vschema for keyspace commerce: [keyspace:commerce;shard:0;dbname:vt_commerce;tablet:100;table:corder,keyspace:commerce;shard:0;dbname:vt_commerce;tablet:100;table:customer]
Denied tables records on [corder,customer] will be removed from: [keyspace:commerce;shard:0;tablet:100]
Delete reverse vreplication streams on sources: [keyspace:commerce;shard:0;workflow:commerce2customer_reverse;dbname:vt_commerce;tablet:100]
Delete vreplication streams on targets: [keyspace:customer;shard:0;workflow:commerce2customer;dbname:vt_customer;tablet:201]
Routing rules for participating tables will be deleted
Unlock keyspace customer
Unlock keyspace commerce


❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format json Complete --dry-run
{
  "summary": "Complete dry run results for workflow customer.commerce2customer at 10 Jul 23 17:07 UTC",
  "dry_run_results": [
    "Lock keyspace commerce",
    "Lock keyspace customer",
    "Dropping these tables from the database and removing them from the vschema for keyspace commerce: [keyspace:commerce;shard:0;dbname:vt_commerce;tablet:100;table:corder,keyspace:commerce;shard:0;dbname:vt_commerce;tablet:100;table:customer]",
    "Denied tables records on [corder,customer] will be removed from: [keyspace:commerce;shard:0;tablet:100]",
    "Delete reverse vreplication streams on sources: [keyspace:commerce;shard:0;workflow:commerce2customer_reverse;dbname:vt_commerce;tablet:100]",
    "Delete vreplication streams on targets: [keyspace:customer;shard:0;workflow:commerce2customer;dbname:vt_customer;tablet:201]",
    "Routing rules for participating tables will be deleted",
    "Unlock keyspace customer",
    "Unlock keyspace commerce"
  ]
}

❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" Complete
Successfully completed the commerce2customer workflow in the customer keyspace


❯ vtctldclient MoveTables --workflow "commerce2customer" --target-keyspace "customer" --format json Complete
{
  "summary": "Successfully completed the commerce2customer workflow in the customer keyspace"
}

Related Issue(s)

Checklist

mattlord added 6 commits May 2, 2023 10:33
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says labels May 2, 2023
@vitess-bot
Copy link
Contributor

vitess-bot bot commented May 2, 2023

Review Checklist

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

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.
  • If a test is added or modified, there should be a documentation on top of the test to explain what the expected behavior is what the test does.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

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

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

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.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

@github-actions github-actions bot added this to the v17.0.0 milestone May 2, 2023
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the vtctldclient_movetables branch from fb7c442 to f31ff17 Compare May 2, 2023 23:53
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the vtctldclient_movetables branch from f31ff17 to 0763cf1 Compare May 3, 2023 00:26
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the vtctldclient_movetables branch 9 times, most recently from 0735046 to d7543f1 Compare May 3, 2023 14:38
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the vtctldclient_movetables branch from d7543f1 to 28c1c84 Compare May 3, 2023 14:39
mattlord added 3 commits May 4, 2023 14:38
Next step is to try and remove wrangler.TrafficSwitcher and
have the wrangler use the workflow implementation if
possible.

Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
@mattlord mattlord force-pushed the vtctldclient_movetables branch from dfd2782 to 89b6b1f Compare May 6, 2023 17:02
@mattlord mattlord removed the NeedsWebsiteDocsUpdate What it says label Jul 14, 2023
@mattlord mattlord marked this pull request as ready for review July 14, 2023 20:14
@mattlord mattlord requested a review from deepthi as a code owner July 14, 2023 20:14
Signed-off-by: Matt Lord <mattalord@gmail.com>
@ajm188 ajm188 mentioned this pull request Jul 17, 2023
4 tasks
mattlord added 14 commits July 17, 2023 12:33
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
})
}

func Materialize(ctx context.Context, ts *topo.Server, tmc tmclient.TabletManagerClient, ms *vtctldatapb.MaterializeSettings) error {
Copy link
Member

Choose a reason for hiding this comment

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

We are not using this method now as part of this PR, right? And the related functions that use VReplicationExec etc? We will need to write updated functions for Materialize when we port over that method, right?

Copy link
Member Author

@mattlord mattlord Jul 25, 2023

Choose a reason for hiding this comment

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

Correct. I moved it over with the other materializer functions -- many of which are used for various other workflow types. MoveTables uses most of them.

Yes, I do think we'll want to update the Materialize specific functions when we migrate that command.

}

/*
func TestMoveTablesV2(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need to port these commented tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had left them in as a reminder for myself. I think that we have the main ones covered now and I added a ticket to the tracking issue to do a final pass to make sure we have good/equivalent coverage for things: #12152

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove those commented tests from the file for now.

var dryRunResults *[]string

if state.WorkflowType == TypeMigrate {
dryRunResults, err = s.finalizeMigrateWorkflow(ctx, req.TargetKeyspace, req.Workflow, strings.Join(ts.tables, ","),
Copy link
Member

Choose a reason for hiding this comment

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

The Migrate command is not yet ported over to vtctld, right? This code path will be exercised once we do that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. I started by copying existing wrangler code and then modifying it -- so I didn't see any point in removing this type of code as I expected that we'll be using it again shortly as we migrate the other commands over.

Copy link
Member

@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.

Great work on this.

A huge step towards deprecating vtctlclient! ❤️

mattlord added 2 commits July 25, 2023 08:01
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
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.

looking awesome!! everything i have is non-blocking, either because we'll ignore it (😂) or because it's minor changes

MoveTablesShow = &cobra.Command{
Use: "show",
Short: "Show the details for a MoveTables VReplication workflow.",
Example: `vtctldclient --server localhost:15999 movetables --workflow commerce2customer --target-keyspace customer show`,
Copy link
Contributor

Choose a reason for hiding this comment

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

these examples are still using the lowercase version of MoveTables

also ... is it going to be strange the parent command is BigCamelCase while the subcommand is alllowercase?

Copy link
Contributor

Choose a reason for hiding this comment

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

(i see they have aliases to their lowercase versions, but now my second question is "is it weird that the parent command is uppercase with alias to lowercase while the child is lowercase with alias to upper?")

Copy link
Member Author

@mattlord mattlord Jul 25, 2023

Choose a reason for hiding this comment

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

I was using lowercase for the new commands but then when building the docs realized that ALL of the existing commands started with an uppercase letter. Otherwise I would have stuck with everything being lowercase. I thought that the current mix made it uniform while also supporting / showing all lowercase.

mattlord added 3 commits July 25, 2023 12:16
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Signed-off-by: Matt Lord <mattalord@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: CLI Component: VReplication Type: Enhancement Logical improvement (somewhere between a bug and feature)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Workflow Command to Vtctldclient Migrate MoveTables Command to Vtctldclient

4 participants