Skip to content

Commit

Permalink
vtctldclient: support OnlineDDL complete, launch commands (vitess…
Browse files Browse the repository at this point in the history
…io#13896)

Signed-off-by: Shlomi Noach <[email protected]>
Co-authored-by: Andrew Mason <[email protected]>
  • Loading branch information
shlomi-noach and ajm188 committed Aug 30, 2023
1 parent c2b62b7 commit 1e82c0c
Show file tree
Hide file tree
Showing 13 changed files with 14,438 additions and 11,272 deletions.
87 changes: 81 additions & 6 deletions go/cmd/vtctldclient/command/onlineddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
}
OnlineDDLCancel = &cobra.Command{
Use: "cancel <keyspace> <uuid|all>",
Short: "CancelSchemaMigration cancels one or all migrations, terminating any running ones as needed.",
Short: "cancel one or all migrations, terminating any running ones as needed.",
Example: "OnlineDDL cancel test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
Expand All @@ -59,6 +59,22 @@ var (
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLCleanup,
}
OnlineDDLComplete = &cobra.Command{
Use: "complete <keyspace> <uuid|all>",
Short: "complete one or all migrations executed with --postpone-completion",
Example: "OnlineDDL complete test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLComplete,
}
OnlineDDLLaunch = &cobra.Command{
Use: "launch <keyspace> <uuid|all>",
Short: "launch one or all migrations executed with --postpone-launch",
Example: "OnlineDDL launch test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLLaunch,
}
OnlineDDLRetry = &cobra.Command{
Use: "retry <keyspace> <uuid>",
Short: "Mark a given schema migration for retry.",
Expand All @@ -84,17 +100,26 @@ OnlineDDL show test_keyspace failed`,
}
)

func commandOnlineDDLCancel(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)
uuid := cmd.Flags().Arg(1)
// analyzeOnlineDDLCommandWithUuidOrAllArgument is a general helper function for OnlineDDL commands that
// accept either a valid UUID or the "all" argument.
func analyzeOnlineDDLCommandWithUuidOrAllArgument(cmd *cobra.Command) (keyspace, uuid string, err error) {
keyspace = cmd.Flags().Arg(0)
uuid = cmd.Flags().Arg(1)

switch {
case uuid == AllMigrationsIndicator:
case strings.ToLower(uuid) == AllMigrationsIndicator:
case schema.IsOnlineDDLUUID(uuid):
default:
return fmt.Errorf("argument must be 'all' or a valid UUID. Got '%s'", uuid)
return "", "", fmt.Errorf("argument must be 'all' or a valid UUID. Got '%s'", uuid)
}
return keyspace, uuid, nil
}

func commandOnlineDDLCancel(cmd *cobra.Command, args []string) error {
keyspace, uuid, err := analyzeOnlineDDLCommandWithUuidOrAllArgument(cmd)
if err != nil {
return err
}
cli.FinishedParsing(cmd)

resp, err := client.CancelSchemaMigration(commandCtx, &vtctldatapb.CancelSchemaMigrationRequest{
Expand Down Expand Up @@ -140,6 +165,54 @@ func commandOnlineDDLCleanup(cmd *cobra.Command, args []string) error {
return nil
}

func commandOnlineDDLComplete(cmd *cobra.Command, args []string) error {
keyspace, uuid, err := analyzeOnlineDDLCommandWithUuidOrAllArgument(cmd)
if err != nil {
return err
}
cli.FinishedParsing(cmd)

resp, err := client.CompleteSchemaMigration(commandCtx, &vtctldatapb.CompleteSchemaMigrationRequest{
Keyspace: keyspace,
Uuid: uuid,
})
if err != nil {
return err
}

data, err := cli.MarshalJSON(resp)
if err != nil {
return err
}

fmt.Printf("%s\n", data)
return nil
}

func commandOnlineDDLLaunch(cmd *cobra.Command, args []string) error {
keyspace, uuid, err := analyzeOnlineDDLCommandWithUuidOrAllArgument(cmd)
if err != nil {
return err
}
cli.FinishedParsing(cmd)

resp, err := client.LaunchSchemaMigration(commandCtx, &vtctldatapb.LaunchSchemaMigrationRequest{
Keyspace: keyspace,
Uuid: uuid,
})
if err != nil {
return err
}

data, err := cli.MarshalJSON(resp)
if err != nil {
return err
}

fmt.Printf("%s\n", data)
return nil
}

func commandOnlineDDLRetry(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)
uuid := cmd.Flags().Arg(1)
Expand Down Expand Up @@ -238,6 +311,8 @@ func commandOnlineDDLShow(cmd *cobra.Command, args []string) error {
func init() {
OnlineDDL.AddCommand(OnlineDDLCancel)
OnlineDDL.AddCommand(OnlineDDLCleanup)
OnlineDDL.AddCommand(OnlineDDLComplete)
OnlineDDL.AddCommand(OnlineDDLLaunch)
OnlineDDL.AddCommand(OnlineDDLRetry)

OnlineDDLShow.Flags().BoolVar(&onlineDDLShowArgs.JSON, "json", false, "Output JSON instead of human-readable table.")
Expand Down
Loading

0 comments on commit 1e82c0c

Please sign in to comment.