Skip to content

Commit

Permalink
vtctldclient OnlineDDL CANCEL (#13860)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Co-authored-by: Andrew Mason <amason@hey.com>
  • Loading branch information
shlomi-noach and ajm188 committed Aug 28, 2023
1 parent ad6b5df commit ab7bfe7
Show file tree
Hide file tree
Showing 15 changed files with 4,989 additions and 3,358 deletions.
43 changes: 43 additions & 0 deletions go/cmd/vtctldclient/command/onlineddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ import (
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

const (
AllMigrationsIndicator = "all"
)

var (
OnlineDDL = &cobra.Command{
Use: "OnlineDDL <cmd> <keyspace> [args]",
Short: "Operates on online DDL (schema migrations).",
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(2),
}
OnlineDDLCancel = &cobra.Command{
Use: "cancel <keyspace> <uuid|all>",
Short: "CancelSchemaMigration cancels 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),
RunE: commandOnlineDDLCancel,
}
OnlineDDLCleanup = &cobra.Command{
Use: "cleanup <keyspace> <uuid>",
Short: "Mark a given schema migration ready for artifact cleanup.",
Expand Down Expand Up @@ -72,6 +84,36 @@ OnlineDDL show test_keyspace failed`,
}
)

func commandOnlineDDLCancel(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)
uuid := cmd.Flags().Arg(1)

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

cli.FinishedParsing(cmd)

resp, err := client.CancelSchemaMigration(commandCtx, &vtctldatapb.CancelSchemaMigrationRequest{
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 commandOnlineDDLCleanup(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)
uuid := cmd.Flags().Arg(1)
Expand Down Expand Up @@ -194,6 +236,7 @@ func commandOnlineDDLShow(cmd *cobra.Command, args []string) error {
}

func init() {
OnlineDDL.AddCommand(OnlineDDLCancel)
OnlineDDL.AddCommand(OnlineDDLCleanup)
OnlineDDL.AddCommand(OnlineDDLRetry)

Expand Down
Loading

0 comments on commit ab7bfe7

Please sign in to comment.