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 4 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
82 changes: 80 additions & 2 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 Down Expand Up @@ -89,7 +105,7 @@ func commandOnlineDDLCancel(cmd *cobra.Command, args []string) error {
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)
Expand Down Expand Up @@ -140,6 +156,66 @@ func commandOnlineDDLCleanup(cmd *cobra.Command, args []string) error {
return nil
}

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

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

Choose a reason for hiding this comment

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

don't have suggestion for a good name, but want to pull this duplicate check out to something like:

func whatever(cmd *cobra.Command) (keyspace, uuid string, err error) {
	keyspace = cmd.Flags().Arg(0)
	uuid = cmd.Flags().Arg(1)

	switch {
	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 keyspace, uuid, nil
}

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


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 := cmd.Flags().Arg(0)
uuid := cmd.Flags().Arg(1)

switch {
case strings.ToLower(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.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 +314,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