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: support OnlineDDL complete, launch commands #13896

Merged
Merged
Show file tree
Hide file tree
Changes from 8 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
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