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

[onlineddl] retry and cleanup #13830

Merged
merged 6 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion go/cmd/vtctld/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"vitess.io/vitess/go/vt/logutil"
"vitess.io/vitess/go/vt/schemamanager"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver"
"vitess.io/vitess/go/vt/vttablet/tmclient"
"vitess.io/vitess/go/vt/wrangler"
)
Expand All @@ -36,7 +37,7 @@ var (
schemaChangeController string
schemaChangeUser string
schemaChangeCheckInterval = time.Minute
schemaChangeReplicasTimeout = wrangler.DefaultWaitReplicasTimeout
schemaChangeReplicasTimeout = grpcvtctldserver.DefaultWaitReplicasTimeout
)

func init() {
Expand Down
71 changes: 71 additions & 0 deletions go/cmd/vtctldclient/command/onlineddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ var (
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(2),
}
OnlineDDLCleanup = &cobra.Command{
Use: "cleanup <keyspace> <uuid>",
Short: "Mark a given schema migration ready for artifact cleanup.",
Example: "OnlineDDL cleanup test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLCleanup,
}
OnlineDDLRetry = &cobra.Command{
Use: "retry <keyspace> <uuid>",
Short: "Mark a given schema migration for retry.",
Example: "vtctl OnlineDDL retry test_keyspace 82fa54ac_e83e_11ea_96b7_f875a4d24e90",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(2),
RunE: commandOnlineDDLRetry,
}
OnlineDDLShow = &cobra.Command{
Use: "show",
Short: "Display information about online DDL operations.",
Expand All @@ -56,6 +72,58 @@ OnlineDDL show test_keyspace failed`,
}
)

func commandOnlineDDLCleanup(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)
uuid := cmd.Flags().Arg(1)
if !schema.IsOnlineDDLUUID(uuid) {
return fmt.Errorf("%s is not a valid UUID", uuid)
}

cli.FinishedParsing(cmd)

resp, err := client.CleanupSchemaMigration(commandCtx, &vtctldatapb.CleanupSchemaMigrationRequest{
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)
if !schema.IsOnlineDDLUUID(uuid) {
return fmt.Errorf("%s is not a valid UUID", uuid)
}

cli.FinishedParsing(cmd)

resp, err := client.RetrySchemaMigration(commandCtx, &vtctldatapb.RetrySchemaMigrationRequest{
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
}

var onlineDDLShowArgs = struct {
JSON bool
OrderStr string
Expand Down Expand Up @@ -126,6 +194,9 @@ func commandOnlineDDLShow(cmd *cobra.Command, args []string) error {
}

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

OnlineDDLShow.Flags().BoolVar(&onlineDDLShowArgs.JSON, "json", false, "Output JSON instead of human-readable table.")
OnlineDDLShow.Flags().StringVar(&onlineDDLShowArgs.OrderStr, "order", "asc", "Sort the results by `id` property of the Schema migration.")
OnlineDDLShow.Flags().Uint64Var(&onlineDDLShowArgs.Limit, "limit", 0, "Limit number of rows returned in output.")
Expand Down
4 changes: 2 additions & 2 deletions go/cmd/vtctldclient/command/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"vitess.io/vitess/go/vt/schema"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/wrangler"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
"vitess.io/vitess/go/vt/proto/vtrpc"
Expand Down Expand Up @@ -294,7 +294,7 @@ func init() {
ApplySchema.Flags().StringVar(&applySchemaOptions.DDLStrategy, "ddl-strategy", string(schema.DDLStrategyDirect), "Online DDL strategy, compatible with @@ddl_strategy session variable (examples: 'gh-ost', 'pt-osc', 'gh-ost --max-load=Threads_running=100'.")
ApplySchema.Flags().StringSliceVar(&applySchemaOptions.UUIDList, "uuid", nil, "Optional, comma-delimited, repeatable, explicit UUIDs for migration. If given, must match number of DDL changes.")
ApplySchema.Flags().StringVar(&applySchemaOptions.MigrationContext, "migration-context", "", "For Online DDL, optionally supply a custom unique string used as context for the migration(s) in this command. By default a unique context is auto-generated by Vitess.")
ApplySchema.Flags().DurationVar(&applySchemaOptions.WaitReplicasTimeout, "wait-replicas-timeout", wrangler.DefaultWaitReplicasTimeout, "Amount of time to wait for replicas to receive the schema change via replication.")
ApplySchema.Flags().DurationVar(&applySchemaOptions.WaitReplicasTimeout, "wait-replicas-timeout", grpcvtctldserver.DefaultWaitReplicasTimeout, "Amount of time to wait for replicas to receive the schema change via replication.")
ApplySchema.Flags().StringVar(&applySchemaOptions.CallerID, "caller-id", "", "Effective caller ID used for the operation and should map to an ACL name which grants this identity the necessary permissions to perform the operation (this is only necessary when strict table ACLs are used).")
ApplySchema.Flags().StringArrayVar(&applySchemaOptions.SQL, "sql", nil, "Semicolon-delimited, repeatable SQL commands to apply. Exactly one of --sql|--sql-file is required.")
ApplySchema.Flags().StringVar(&applySchemaOptions.SQLFile, "sql-file", "", "Path to a file containing semicolon-delimited SQL commands to apply. Exactly one of --sql|--sql-file is required.")
Expand Down
Loading