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

vtctldclient OnlineDDL CANCEL #13860

Merged
merged 7 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading