diff --git a/go/cmd/vtctldclient/command/root.go b/go/cmd/vtctldclient/command/root.go index 92d30ff4b8b..7a9f59ad3a4 100644 --- a/go/cmd/vtctldclient/command/root.go +++ b/go/cmd/vtctldclient/command/root.go @@ -24,15 +24,13 @@ import ( "strconv" "time" - common "vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/common" + "github.com/spf13/cobra" - // these immports ensure init()s within them get called and they register their commands/subcommands. + // These imports ensure init()s within them get called and they register their commands/subcommands. + vreplcommon "vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/common" _ "vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/movetables" _ "vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/reshard" _ "vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/workflow" - - "github.com/spf13/cobra" - "vitess.io/vitess/go/trace" "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/servenv" @@ -67,8 +65,8 @@ var ( ctx = context.Background() } commandCtx, commandCancel = context.WithTimeout(ctx, actionTimeout) - common.SetClient(client) - common.SetCommandCtx(commandCtx) + vreplcommon.SetClient(client) + vreplcommon.SetCommandCtx(commandCtx) return err }, // Similarly, PersistentPostRun cleans up the resources spawned by @@ -142,5 +140,5 @@ func getClientForCommand(cmd *cobra.Command) (vtctldclient.VtctldClient, error) func init() { Root.PersistentFlags().StringVar(&server, "server", "", "server to use for connection (required)") Root.PersistentFlags().DurationVar(&actionTimeout, "action_timeout", time.Hour, "timeout for the total command") - common.RegisterCommands(Root) + vreplcommon.RegisterCommands(Root) } diff --git a/go/cmd/vtctldclient/command/vreplication/common/cancel.go b/go/cmd/vtctldclient/command/vreplication/common/cancel.go index cccde435cb0..1b43634b112 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/cancel.go +++ b/go/cmd/vtctldclient/command/vreplication/common/cancel.go @@ -46,7 +46,7 @@ func GetCancelCommand(opts *SubCommandsOpts) *cobra.Command { } func commandCancel(cmd *cobra.Command, args []string) error { - format, err := ParseAndValidateFormat(cmd, &CommonVROptions.VrCommonOptions) + format, err := GetOutputFormat(cmd) if err != nil { return err } @@ -54,8 +54,8 @@ func commandCancel(cmd *cobra.Command, args []string) error { cli.FinishedParsing(cmd) req := &vtctldatapb.WorkflowDeleteRequest{ - Keyspace: CommonVROptions.TargetKeyspace, - Workflow: CommonVROptions.Workflow, + Keyspace: BaseOptions.TargetKeyspace, + Workflow: BaseOptions.Workflow, KeepData: cancelOptions.KeepData, KeepRoutingRules: cancelOptions.KeepRoutingRules, } diff --git a/go/cmd/vtctldclient/command/vreplication/common/complete.go b/go/cmd/vtctldclient/command/vreplication/common/complete.go index 69a5a4c017f..14a1a524e71 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/complete.go +++ b/go/cmd/vtctldclient/command/vreplication/common/complete.go @@ -11,7 +11,7 @@ import ( vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" ) -var completeOptions = struct { +var CompleteOptions = struct { KeepData bool KeepRoutingRules bool RenameTables bool @@ -32,19 +32,19 @@ func GetCompleteCommand(opts *SubCommandsOpts) *cobra.Command { } func commandComplete(cmd *cobra.Command, args []string) error { - format, err := ParseAndValidateFormat(cmd, &CommonVROptions.VrCommonOptions) + format, err := GetOutputFormat(cmd) if err != nil { return err } cli.FinishedParsing(cmd) req := &vtctldatapb.MoveTablesCompleteRequest{ - Workflow: CommonVROptions.Workflow, - TargetKeyspace: CommonVROptions.TargetKeyspace, - KeepData: completeOptions.KeepData, - KeepRoutingRules: completeOptions.KeepRoutingRules, - RenameTables: completeOptions.RenameTables, - DryRun: completeOptions.DryRun, + Workflow: BaseOptions.Workflow, + TargetKeyspace: BaseOptions.TargetKeyspace, + KeepData: CompleteOptions.KeepData, + KeepRoutingRules: CompleteOptions.KeepRoutingRules, + RenameTables: CompleteOptions.RenameTables, + DryRun: CompleteOptions.DryRun, } resp, err := GetClient().MoveTablesComplete(GetCommandCtx(), req) if err != nil { diff --git a/go/cmd/vtctldclient/command/vreplication/common/show.go b/go/cmd/vtctldclient/command/vreplication/common/show.go index bfc7ab73324..f6e4853d428 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/show.go +++ b/go/cmd/vtctldclient/command/vreplication/common/show.go @@ -43,8 +43,8 @@ func commandShow(cmd *cobra.Command, args []string) error { cli.FinishedParsing(cmd) req := &vtctldatapb.GetWorkflowsRequest{ - Keyspace: CommonVROptions.TargetKeyspace, - Workflow: CommonVROptions.Workflow, + Keyspace: BaseOptions.TargetKeyspace, + Workflow: BaseOptions.Workflow, } resp, err := GetClient().GetWorkflows(GetCommandCtx(), req) if err != nil { diff --git a/go/cmd/vtctldclient/command/vreplication/common/status.go b/go/cmd/vtctldclient/command/vreplication/common/status.go index d5057a3088d..2a7327fe40c 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/status.go +++ b/go/cmd/vtctldclient/command/vreplication/common/status.go @@ -43,8 +43,8 @@ func commandStatus(cmd *cobra.Command, args []string) error { cli.FinishedParsing(cmd) req := &vtctldatapb.WorkflowStatusRequest{ - Keyspace: CommonVROptions.TargetKeyspace, - Workflow: CommonVROptions.Workflow, + Keyspace: BaseOptions.TargetKeyspace, + Workflow: BaseOptions.Workflow, } resp, err := GetClient().WorkflowStatus(GetCommandCtx(), req) if err != nil { diff --git a/go/cmd/vtctldclient/command/vreplication/common/switchtraffic.go b/go/cmd/vtctldclient/command/vreplication/common/switchtraffic.go index dd604a0cc97..befdb36eb48 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/switchtraffic.go +++ b/go/cmd/vtctldclient/command/vreplication/common/switchtraffic.go @@ -39,10 +39,10 @@ func GetSwitchTrafficCommand(opts *SubCommandsOpts) *cobra.Command { Aliases: []string{"switchtraffic"}, Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { - CommonSwitchTrafficOptions.Direction = workflow.DirectionForward + SwitchTrafficOptions.Direction = workflow.DirectionForward if !cmd.Flags().Lookup("tablet-types").Changed { // We switch traffic for all tablet types if none are provided. - CommonSwitchTrafficOptions.TabletTypes = []topodatapb.TabletType{ + SwitchTrafficOptions.TabletTypes = []topodatapb.TabletType{ topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY, @@ -64,10 +64,10 @@ func GetReverseTrafficCommand(opts *SubCommandsOpts) *cobra.Command { Aliases: []string{"reversetraffic"}, Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { - CommonSwitchTrafficOptions.Direction = workflow.DirectionBackward + SwitchTrafficOptions.Direction = workflow.DirectionBackward if !cmd.Flags().Lookup("tablet-types").Changed { // We switch traffic for all tablet types if none are provided. - CommonSwitchTrafficOptions.TabletTypes = []topodatapb.TabletType{ + SwitchTrafficOptions.TabletTypes = []topodatapb.TabletType{ topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY, @@ -81,7 +81,7 @@ func GetReverseTrafficCommand(opts *SubCommandsOpts) *cobra.Command { } func commandSwitchTraffic(cmd *cobra.Command, args []string) error { - format, err := ParseAndValidateFormat(cmd, &CommonVROptions.VrCommonOptions) + format, err := GetOutputFormat(cmd) if err != nil { return err } @@ -89,15 +89,15 @@ func commandSwitchTraffic(cmd *cobra.Command, args []string) error { cli.FinishedParsing(cmd) req := &vtctldatapb.WorkflowSwitchTrafficRequest{ - Keyspace: CommonVROptions.TargetKeyspace, - Workflow: CommonVROptions.Workflow, - TabletTypes: CommonSwitchTrafficOptions.TabletTypes, - MaxReplicationLagAllowed: protoutil.DurationToProto(CommonSwitchTrafficOptions.MaxReplicationLagAllowed), - Timeout: protoutil.DurationToProto(CommonSwitchTrafficOptions.Timeout), - DryRun: CommonSwitchTrafficOptions.DryRun, - EnableReverseReplication: CommonSwitchTrafficOptions.EnableReverseReplication, - InitializeTargetSequences: CommonSwitchTrafficOptions.InitializeTargetSequences, - Direction: int32(CommonSwitchTrafficOptions.Direction), + Keyspace: BaseOptions.TargetKeyspace, + Workflow: BaseOptions.Workflow, + TabletTypes: SwitchTrafficOptions.TabletTypes, + MaxReplicationLagAllowed: protoutil.DurationToProto(SwitchTrafficOptions.MaxReplicationLagAllowed), + Timeout: protoutil.DurationToProto(SwitchTrafficOptions.Timeout), + DryRun: SwitchTrafficOptions.DryRun, + EnableReverseReplication: SwitchTrafficOptions.EnableReverseReplication, + InitializeTargetSequences: SwitchTrafficOptions.InitializeTargetSequences, + Direction: int32(SwitchTrafficOptions.Direction), } resp, err := GetClient().WorkflowSwitchTraffic(GetCommandCtx(), req) if err != nil { diff --git a/go/cmd/vtctldclient/command/vreplication/common/update.go b/go/cmd/vtctldclient/command/vreplication/common/update.go index acbac360149..5d2c42ada9a 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/update.go +++ b/go/cmd/vtctldclient/command/vreplication/common/update.go @@ -36,8 +36,8 @@ import ( ) func bridgeToWorkflow(cmd *cobra.Command, args []string) { - workflowUpdateOptions.Workflow = CommonVROptions.Workflow - workflowOptions.Keyspace = CommonVROptions.TargetKeyspace + workflowUpdateOptions.Workflow = BaseOptions.Workflow + workflowOptions.Keyspace = BaseOptions.TargetKeyspace } var ( diff --git a/go/cmd/vtctldclient/command/vreplication/common/utils.go b/go/cmd/vtctldclient/command/vreplication/common/utils.go index 94c82e2f5c4..2bc34f13436 100644 --- a/go/cmd/vtctldclient/command/vreplication/common/utils.go +++ b/go/cmd/vtctldclient/command/vreplication/common/utils.go @@ -48,13 +48,20 @@ var ( MaxReplicationLagDefault = 30 * time.Second TimeoutDefault = 30 * time.Second - // CommonVROptions are common options for all vreplication commands. - CommonVROptions = struct { - VrCommonOptions + BaseOptions = struct { + Workflow string + TargetKeyspace string + Format string }{} - CommonVRCreateOptions = struct { - VrCreateCommonOptions + CreateOptions = struct { + Cells []string + TabletTypes []topodatapb.TabletType + TabletTypesInPreferenceOrder bool + OnDDL string + DeferSecondaryKeys bool + AutoStart bool + StopAfterCopy bool }{} ) @@ -70,22 +77,6 @@ func RegisterCommands(root *cobra.Command) { } } -type VrCommonOptions = struct { - Workflow string - TargetKeyspace string - Format string -} - -type VrCreateCommonOptions = struct { - Cells []string - TabletTypes []topodatapb.TabletType - TabletTypesInPreferenceOrder bool - OnDDL string - DeferSecondaryKeys bool - AutoStart bool - StopAfterCopy bool -} - type SubCommandsOpts struct { SubCommand string Workflow string @@ -107,57 +98,49 @@ func GetCommandCtx() context.Context { return commandCtx } -func ParseCells(cmd *cobra.Command, opts *VrCreateCommonOptions) { +func ParseCells(cmd *cobra.Command) { if cmd.Flags().Lookup("cells").Changed { // Validate the provided value(s) - for i, cell := range opts.Cells { // Which only means trimming whitespace - opts.Cells[i] = strings.TrimSpace(cell) + for i, cell := range CreateOptions.Cells { // Which only means trimming whitespace + CreateOptions.Cells[i] = strings.TrimSpace(cell) } } } -func ParseTabletTypes(cmd *cobra.Command, opts *VrCreateCommonOptions) { +func ParseTabletTypes(cmd *cobra.Command) { if !cmd.Flags().Lookup("tablet-types").Changed { - opts.TabletTypes = tabletTypesDefault + CreateOptions.TabletTypes = tabletTypesDefault } } -func validateOnDDL(cmd *cobra.Command, opts *VrCreateCommonOptions) error { - if _, ok := binlogdatapb.OnDDLAction_value[strings.ToUpper(opts.OnDDL)]; !ok { - return fmt.Errorf("invalid on-ddl value: %s", opts.OnDDL) +func validateOnDDL(cmd *cobra.Command) error { + if _, ok := binlogdatapb.OnDDLAction_value[strings.ToUpper(CreateOptions.OnDDL)]; !ok { + return fmt.Errorf("invalid on-ddl value: %s", CreateOptions.OnDDL) } return nil } -func ParseAndValidateCreateOptions(cmd *cobra.Command, opts *VrCreateCommonOptions) error { - if err := validateOnDDL(cmd, opts); err != nil { +func ParseAndValidateCreateOptions(cmd *cobra.Command) error { + if err := validateOnDDL(cmd); err != nil { return err } - ParseCells(cmd, opts) - ParseTabletTypes(cmd, opts) + ParseCells(cmd) + ParseTabletTypes(cmd) return nil } -func ParseAndValidateFormat(cmd *cobra.Command, opts *VrCommonOptions) (string, error) { - format := strings.ToLower(strings.TrimSpace(opts.Format)) +func GetOutputFormat(cmd *cobra.Command) (string, error) { + format := strings.ToLower(strings.TrimSpace(BaseOptions.Format)) switch format { case "text", "json": return format, nil default: - return "", fmt.Errorf("invalid output format, got %s", opts.Format) - } -} - -func GetCommonOptions(cmd *cobra.Command, opts *VrCommonOptions) (string, error) { - format, err := ParseAndValidateFormat(cmd, opts) - if err != nil { - return "", err + return "", fmt.Errorf("invalid output format, got %s", BaseOptions.Format) } - return format, nil } -func GetCreateOptions(cmd *cobra.Command, opts *VrCreateCommonOptions) tabletmanagerdatapb.TabletSelectionPreference { +func GetTabletSelectionPreference(cmd *cobra.Command) tabletmanagerdatapb.TabletSelectionPreference { tsp := tabletmanagerdatapb.TabletSelectionPreference_ANY - if opts.TabletTypesInPreferenceOrder { + if CreateOptions.TabletTypesInPreferenceOrder { tsp = tabletmanagerdatapb.TabletSelectionPreference_INORDER } return tsp @@ -174,12 +157,12 @@ func OutputStatusResponse(resp *vtctldatapb.WorkflowStatusResponse, format strin } else { tout := bytes.Buffer{} tout.WriteString(fmt.Sprintf("The following vreplication streams exist for workflow %s.%s:\n\n", - CommonVROptions.TargetKeyspace, CommonVROptions.Workflow)) + BaseOptions.TargetKeyspace, BaseOptions.Workflow)) for _, shardstreams := range resp.ShardStreams { for _, shardstream := range shardstreams.Streams { tablet := fmt.Sprintf("%s-%d", shardstream.Tablet.Cell, shardstream.Tablet.Uid) tout.WriteString(fmt.Sprintf("id=%d on %s/%s: Status: %s. %s.\n", - shardstream.Id, CommonVROptions.TargetKeyspace, tablet, shardstream.Status, shardstream.Info)) + shardstream.Id, BaseOptions.TargetKeyspace, tablet, shardstream.Status, shardstream.Info)) } } output = tout.Bytes() @@ -189,24 +172,24 @@ func OutputStatusResponse(resp *vtctldatapb.WorkflowStatusResponse, format strin } func AddCommonFlags(cmd *cobra.Command) { - cmd.Flags().StringVar(&CommonVROptions.TargetKeyspace, "target-keyspace", "", "Target keyspace for this workflow exists (required)") + cmd.Flags().StringVar(&BaseOptions.TargetKeyspace, "target-keyspace", "", "Target keyspace for this workflow exists (required)") cmd.MarkFlagRequired("target-keyspace") - cmd.Flags().StringVarP(&CommonVROptions.Workflow, "workflow", "w", "", "The workflow you want to perform the command on (required)") + cmd.Flags().StringVarP(&BaseOptions.Workflow, "workflow", "w", "", "The workflow you want to perform the command on (required)") cmd.MarkFlagRequired("workflow") - cmd.Flags().StringVar(&CommonVROptions.Format, "format", "text", "The format of the output; supported formats are: text,json") + cmd.Flags().StringVar(&BaseOptions.Format, "format", "text", "The format of the output; supported formats are: text,json") } func AddCommonCreateFlags(cmd *cobra.Command) { - cmd.Flags().StringSliceVarP(&CommonVRCreateOptions.Cells, "cells", "c", nil, "Cells and/or CellAliases to copy table data from") - cmd.Flags().Var((*topoproto.TabletTypeListFlag)(&CommonVRCreateOptions.TabletTypes), "tablet-types", "Source tablet types to replicate table data from (e.g. PRIMARY,REPLICA,RDONLY)") - cmd.Flags().BoolVar(&CommonVRCreateOptions.TabletTypesInPreferenceOrder, "tablet-types-in-preference-order", true, "When performing source tablet selection, look for candidates in the type order as they are listed in the tablet-types flag") - cmd.Flags().StringVar(&CommonVRCreateOptions.OnDDL, "on-ddl", onDDLDefault, "What to do when DDL is encountered in the VReplication stream. Possible values are IGNORE, STOP, EXEC, and EXEC_IGNORE") - cmd.Flags().BoolVar(&CommonVRCreateOptions.DeferSecondaryKeys, "defer-secondary-keys", false, "Defer secondary index creation for a table until after it has been copied") - cmd.Flags().BoolVar(&CommonVRCreateOptions.AutoStart, "auto-start", true, "Start the MoveTables workflow after creating it") - cmd.Flags().BoolVar(&CommonVRCreateOptions.StopAfterCopy, "stop-after-copy", false, "Stop the MoveTables workflow after it's finished copying the existing rows and before it starts replicating changes") + cmd.Flags().StringSliceVarP(&CreateOptions.Cells, "cells", "c", nil, "Cells and/or CellAliases to copy table data from") + cmd.Flags().Var((*topoproto.TabletTypeListFlag)(&CreateOptions.TabletTypes), "tablet-types", "Source tablet types to replicate table data from (e.g. PRIMARY,REPLICA,RDONLY)") + cmd.Flags().BoolVar(&CreateOptions.TabletTypesInPreferenceOrder, "tablet-types-in-preference-order", true, "When performing source tablet selection, look for candidates in the type order as they are listed in the tablet-types flag") + cmd.Flags().StringVar(&CreateOptions.OnDDL, "on-ddl", onDDLDefault, "What to do when DDL is encountered in the VReplication stream. Possible values are IGNORE, STOP, EXEC, and EXEC_IGNORE") + cmd.Flags().BoolVar(&CreateOptions.DeferSecondaryKeys, "defer-secondary-keys", false, "Defer secondary index creation for a table until after it has been copied") + cmd.Flags().BoolVar(&CreateOptions.AutoStart, "auto-start", true, "Start the MoveTables workflow after creating it") + cmd.Flags().BoolVar(&CreateOptions.StopAfterCopy, "stop-after-copy", false, "Stop the MoveTables workflow after it's finished copying the existing rows and before it starts replicating changes") } -var CommonSwitchTrafficOptions = struct { +var SwitchTrafficOptions = struct { Cells []string TabletTypes []topodatapb.TabletType Timeout time.Duration @@ -218,13 +201,13 @@ var CommonSwitchTrafficOptions = struct { }{} func AddCommonSwitchTrafficFlags(cmd *cobra.Command, initializeTargetSequences bool) { - cmd.Flags().StringSliceVarP(&CommonSwitchTrafficOptions.Cells, "cells", "c", nil, "Cells and/or CellAliases to switch traffic in") - cmd.Flags().Var((*topoproto.TabletTypeListFlag)(&CommonSwitchTrafficOptions.TabletTypes), "tablet-types", "Tablet types to switch traffic for") - cmd.Flags().DurationVar(&CommonSwitchTrafficOptions.Timeout, "timeout", TimeoutDefault, "Specifies the maximum time to wait, in seconds, for VReplication to catch up on primary tablets. The traffic switch will be cancelled on timeout.") - cmd.Flags().DurationVar(&CommonSwitchTrafficOptions.MaxReplicationLagAllowed, "max-replication-lag-allowed", MaxReplicationLagDefault, "Allow traffic to be switched only if VReplication lag is below this") - cmd.Flags().BoolVar(&CommonSwitchTrafficOptions.EnableReverseReplication, "enable-reverse-replication", true, "Setup replication going back to the original source keyspace to support rolling back the traffic cutover") - cmd.Flags().BoolVar(&CommonSwitchTrafficOptions.DryRun, "dry-run", false, "Print the actions that would be taken and report any known errors that would have occurred") + cmd.Flags().StringSliceVarP(&SwitchTrafficOptions.Cells, "cells", "c", nil, "Cells and/or CellAliases to switch traffic in") + cmd.Flags().Var((*topoproto.TabletTypeListFlag)(&SwitchTrafficOptions.TabletTypes), "tablet-types", "Tablet types to switch traffic for") + cmd.Flags().DurationVar(&SwitchTrafficOptions.Timeout, "timeout", TimeoutDefault, "Specifies the maximum time to wait, in seconds, for VReplication to catch up on primary tablets. The traffic switch will be cancelled on timeout.") + cmd.Flags().DurationVar(&SwitchTrafficOptions.MaxReplicationLagAllowed, "max-replication-lag-allowed", MaxReplicationLagDefault, "Allow traffic to be switched only if VReplication lag is below this") + cmd.Flags().BoolVar(&SwitchTrafficOptions.EnableReverseReplication, "enable-reverse-replication", true, "Setup replication going back to the original source keyspace to support rolling back the traffic cutover") + cmd.Flags().BoolVar(&SwitchTrafficOptions.DryRun, "dry-run", false, "Print the actions that would be taken and report any known errors that would have occurred") if initializeTargetSequences { - cmd.Flags().BoolVar(&CommonSwitchTrafficOptions.InitializeTargetSequences, "initialize-target-sequences", false, "When moving tables from an unsharded keyspace to a sharded keyspace, initialize any sequences that are being used on the target when switching writes.") + cmd.Flags().BoolVar(&SwitchTrafficOptions.InitializeTargetSequences, "initialize-target-sequences", false, "When moving tables from an unsharded keyspace to a sharded keyspace, initialize any sequences that are being used on the target when switching writes.") } } diff --git a/go/cmd/vtctldclient/command/vreplication/movetables/create.go b/go/cmd/vtctldclient/command/vreplication/movetables/create.go index 8b714d764e9..0828ff31a52 100644 --- a/go/cmd/vtctldclient/command/vreplication/movetables/create.go +++ b/go/cmd/vtctldclient/command/vreplication/movetables/create.go @@ -55,7 +55,7 @@ var ( if !cmd.Flags().Lookup("tables").Changed && !cmd.Flags().Lookup("all-tables").Changed { return fmt.Errorf("tables or all-tables are required to specify which tables to move") } - if err := common.ParseAndValidateCreateOptions(cmd, &common.CommonVRCreateOptions.VrCreateCommonOptions); err != nil { + if err := common.ParseAndValidateCreateOptions(cmd); err != nil { return err } checkAtomicCopyOptions := func() error { @@ -64,14 +64,13 @@ var ( return nil } if !moveTablesCreateOptions.AllTables { - errors = append(errors, "atomic copy requires --all-tables.") + errors = append(errors, "atomic copy requires --all-tables") } if len(moveTablesCreateOptions.IncludeTables) > 0 || len(moveTablesCreateOptions.ExcludeTables) > 0 { - errors = append(errors, "atomic copy does not support specifying tables.") + errors = append(errors, "atomic copy does not support specifying tables") } if len(errors) > 0 { - errors = append(errors, "Found options incompatible with atomic copy:") - return fmt.Errorf(strings.Join(errors, " ")) + return fmt.Errorf("found options incompatible with atomic copy: %s", strings.Join(errors, ", ")) } return nil } @@ -85,31 +84,29 @@ var ( ) func commandMoveTablesCreate(cmd *cobra.Command, args []string) error { - - cli.FinishedParsing(cmd) - - format, err := common.GetCommonOptions(cmd, &common.CommonVROptions.VrCommonOptions) + format, err := common.GetOutputFormat(cmd) if err != nil { return err } - tsp := common.GetCreateOptions(cmd, &common.CommonVRCreateOptions.VrCreateCommonOptions) + tsp := common.GetTabletSelectionPreference(cmd) + cli.FinishedParsing(cmd) req := &vtctldatapb.MoveTablesCreateRequest{ - Workflow: common.CommonVROptions.Workflow, - TargetKeyspace: common.CommonVROptions.TargetKeyspace, + Workflow: common.BaseOptions.Workflow, + TargetKeyspace: common.BaseOptions.TargetKeyspace, SourceKeyspace: moveTablesCreateOptions.SourceKeyspace, SourceShards: moveTablesCreateOptions.SourceShards, SourceTimeZone: moveTablesCreateOptions.SourceTimeZone, - Cells: common.CommonVRCreateOptions.Cells, - TabletTypes: common.CommonVRCreateOptions.TabletTypes, + Cells: common.CreateOptions.Cells, + TabletTypes: common.CreateOptions.TabletTypes, TabletSelectionPreference: tsp, AllTables: moveTablesCreateOptions.AllTables, IncludeTables: moveTablesCreateOptions.IncludeTables, ExcludeTables: moveTablesCreateOptions.ExcludeTables, - OnDdl: common.CommonVRCreateOptions.OnDDL, - DeferSecondaryKeys: common.CommonVRCreateOptions.DeferSecondaryKeys, - AutoStart: common.CommonVRCreateOptions.AutoStart, - StopAfterCopy: common.CommonVRCreateOptions.StopAfterCopy, + OnDdl: common.CreateOptions.OnDDL, + DeferSecondaryKeys: common.CreateOptions.DeferSecondaryKeys, + AutoStart: common.CreateOptions.AutoStart, + StopAfterCopy: common.CreateOptions.StopAfterCopy, NoRoutingRules: moveTablesCreateOptions.NoRoutingRules, AtomicCopy: moveTablesCreateOptions.AtomicCopy, } @@ -126,13 +123,13 @@ func commandMoveTablesCreate(cmd *cobra.Command, args []string) error { func registerCreateCommand(root *cobra.Command) { common.AddCommonCreateFlags(moveTablesCreate) - moveTablesCreate.PersistentFlags().StringVar(&moveTablesCreateOptions.SourceKeyspace, "source-keyspace", "", "Keyspace where the tables are being moved from (required)") + moveTablesCreate.PersistentFlags().StringVar(&moveTablesCreateOptions.SourceKeyspace, "source-keyspace", "", "Keyspace where the tables are being moved from (required).") moveTablesCreate.MarkPersistentFlagRequired("source-keyspace") - moveTablesCreate.Flags().StringSliceVar(&moveTablesCreateOptions.SourceShards, "source-shards", nil, "Source shards to copy data from when performing a partial moveTables (experimental)") - moveTablesCreate.Flags().StringVar(&moveTablesCreateOptions.SourceTimeZone, "source-time-zone", "", "Specifying this causes any DATETIME fields to be converted from the given time zone into UTC") - moveTablesCreate.Flags().BoolVar(&moveTablesCreateOptions.AllTables, "all-tables", false, "Copy all tables from the source") - moveTablesCreate.Flags().StringSliceVar(&moveTablesCreateOptions.IncludeTables, "tables", nil, "Source tables to copy") - moveTablesCreate.Flags().StringSliceVar(&moveTablesCreateOptions.ExcludeTables, "exclude-tables", nil, "Source tables to exclude from copying") + moveTablesCreate.Flags().StringSliceVar(&moveTablesCreateOptions.SourceShards, "source-shards", nil, "Source shards to copy data from when performing a partial moveTables (experimental).") + moveTablesCreate.Flags().StringVar(&moveTablesCreateOptions.SourceTimeZone, "source-time-zone", "", "Specifying this causes any DATETIME fields to be converted from the given time zone into UTC.") + moveTablesCreate.Flags().BoolVar(&moveTablesCreateOptions.AllTables, "all-tables", false, "Copy all tables from the source.") + moveTablesCreate.Flags().StringSliceVar(&moveTablesCreateOptions.IncludeTables, "tables", nil, "Source tables to copy.") + moveTablesCreate.Flags().StringSliceVar(&moveTablesCreateOptions.ExcludeTables, "exclude-tables", nil, "Source tables to exclude from copying.") moveTablesCreate.Flags().BoolVar(&moveTablesCreateOptions.NoRoutingRules, "no-routing-rules", false, "(Advanced) Do not create routing rules while creating the workflow. See the reference documentation for limitations if you use this flag.") moveTablesCreate.Flags().BoolVar(&moveTablesCreateOptions.AtomicCopy, "atomic-copy", false, "(EXPERIMENTAL) A single copy phase is run for all tables from the source. Use this, for example, if your source keyspace has tables which use foreign key constraints.") moveTables.AddCommand(moveTablesCreate) diff --git a/go/cmd/vtctldclient/command/vreplication/movetables/movetables.go b/go/cmd/vtctldclient/command/vreplication/movetables/movetables.go index 43058abf1dc..ca71a8a1901 100644 --- a/go/cmd/vtctldclient/command/vreplication/movetables/movetables.go +++ b/go/cmd/vtctldclient/command/vreplication/movetables/movetables.go @@ -41,8 +41,7 @@ func registerMoveTablesCommands(root *cobra.Command) { registerCreateCommand(moveTables) opts := &common.SubCommandsOpts{ - SubCommand: "moveTables", - Workflow: "cust2cust", + SubCommand: "MoveTables", } moveTables.AddCommand(common.GetShowCommand(opts)) moveTables.AddCommand(common.GetStatusCommand(opts)) diff --git a/go/cmd/vtctldclient/command/vreplication/reshard/create.go b/go/cmd/vtctldclient/command/vreplication/reshard/create.go index 9f42407ec04..d6b04fe8f07 100644 --- a/go/cmd/vtctldclient/command/vreplication/reshard/create.go +++ b/go/cmd/vtctldclient/command/vreplication/reshard/create.go @@ -32,7 +32,7 @@ var ( skipSchemaCopy bool }{} - // reshardCreate makes a reshardCreate gRPC call to a vtctld. + // reshardCreate makes a ReshardCreate gRPC call to a vtctld. reshardCreate = &cobra.Command{ Use: "Create", Short: "Create and optionally run a reshard VReplication workflow.", @@ -42,7 +42,7 @@ var ( Aliases: []string{"create"}, Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { - if err := common.ParseAndValidateCreateOptions(cmd, &common.CommonVRCreateOptions.VrCreateCommonOptions); err != nil { + if err := common.ParseAndValidateCreateOptions(cmd); err != nil { return err } return nil @@ -52,25 +52,24 @@ var ( ) func commandReshardCreate(cmd *cobra.Command, args []string) error { - cli.FinishedParsing(cmd) - - format, err := common.GetCommonOptions(cmd, &common.CommonVROptions.VrCommonOptions) + format, err := common.GetOutputFormat(cmd) if err != nil { return err } - tsp := common.GetCreateOptions(cmd, &common.CommonVRCreateOptions.VrCreateCommonOptions) + tsp := common.GetTabletSelectionPreference(cmd) + cli.FinishedParsing(cmd) req := &vtctldatapb.ReshardCreateRequest{ - Workflow: common.CommonVROptions.Workflow, - Keyspace: common.CommonVROptions.TargetKeyspace, + Workflow: common.BaseOptions.Workflow, + Keyspace: common.BaseOptions.TargetKeyspace, - TabletTypes: common.CommonVRCreateOptions.TabletTypes, + TabletTypes: common.CreateOptions.TabletTypes, TabletSelectionPreference: tsp, - Cells: common.CommonVRCreateOptions.Cells, - OnDdl: common.CommonVRCreateOptions.OnDDL, - DeferSecondaryKeys: common.CommonVRCreateOptions.DeferSecondaryKeys, - AutoStart: common.CommonVRCreateOptions.AutoStart, - StopAfterCopy: common.CommonVRCreateOptions.StopAfterCopy, + Cells: common.CreateOptions.Cells, + OnDdl: common.CreateOptions.OnDDL, + DeferSecondaryKeys: common.CreateOptions.DeferSecondaryKeys, + AutoStart: common.CreateOptions.AutoStart, + StopAfterCopy: common.CreateOptions.StopAfterCopy, SourceShards: reshardCreateOptions.sourceShards, TargetShards: reshardCreateOptions.targetShards, @@ -88,8 +87,8 @@ func commandReshardCreate(cmd *cobra.Command, args []string) error { func registerCreateCommand(root *cobra.Command) { common.AddCommonCreateFlags(reshardCreate) - reshardCreate.Flags().StringSliceVar(&reshardCreateOptions.sourceShards, "source-shards", nil, "Comma-separated list of source shards.") - reshardCreate.Flags().StringSliceVar(&reshardCreateOptions.targetShards, "target-shards", nil, "Comma-separated list of target shards.") - reshardCreate.Flags().BoolVar(&reshardCreateOptions.skipSchemaCopy, "skip-schema-copy", false, "Skip copying the schema from the source shards to the target shards.") + reshardCreate.Flags().StringSliceVar(&reshardCreateOptions.sourceShards, "source-shards", nil, "Comma-separated list of source shards") + reshardCreate.Flags().StringSliceVar(&reshardCreateOptions.targetShards, "target-shards", nil, "Comma-separated list of target shards") + reshardCreate.Flags().BoolVar(&reshardCreateOptions.skipSchemaCopy, "skip-schema-copy", false, "Skip copying the schema from the source shards to the target shards") root.AddCommand(reshardCreate) } diff --git a/go/cmd/vtctldclient/command/vreplication/reshard/reshard.go b/go/cmd/vtctldclient/command/vreplication/reshard/reshard.go index 674f16142a4..67cc18797c6 100644 --- a/go/cmd/vtctldclient/command/vreplication/reshard/reshard.go +++ b/go/cmd/vtctldclient/command/vreplication/reshard/reshard.go @@ -42,8 +42,7 @@ func registerReshardCommands(root *cobra.Command) { registerCreateCommand(reshard) opts := &common.SubCommandsOpts{ - SubCommand: "reshard", - Workflow: "cust2cust", + SubCommand: "Reshard", } reshard.AddCommand(common.GetShowCommand(opts)) reshard.AddCommand(common.GetStatusCommand(opts)) @@ -64,5 +63,5 @@ func registerReshardCommands(root *cobra.Command) { } func init() { - common.RegisterCommandHandler("reshard", registerReshardCommands) + common.RegisterCommandHandler("Reshard", registerReshardCommands) }