Skip to content

Commit

Permalink
slack-15.0: backport PR vitessio#16852 (#529)
Browse files Browse the repository at this point in the history
* `slack-15.0`: backport PR vitessio#16852

Signed-off-by: Tim Vaillancourt <[email protected]>

* make vtadmin_web_proto_types

Signed-off-by: Tim Vaillancourt <[email protected]>

* fix v15 tests

Signed-off-by: Tim Vaillancourt <[email protected]>

---------

Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt authored Oct 10, 2024
1 parent 0f201a6 commit 4cc762f
Show file tree
Hide file tree
Showing 11 changed files with 1,354 additions and 1,000 deletions.
32 changes: 27 additions & 5 deletions go/cmd/vtctldclient/command/reparents.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var emergencyReparentShardOptions = struct {
Force bool
WaitReplicasTimeout time.Duration
NewPrimaryAliasStr string
ExpectedPrimaryAliasStr string
IgnoreReplicaAliasStrList []string
PreventCrossCellPromotion bool
}{}
Expand All @@ -104,6 +105,7 @@ func commandEmergencyReparentShard(cmd *cobra.Command, args []string) error {

var (
newPrimaryAlias *topodatapb.TabletAlias
expectedPrimaryAlias *topodatapb.TabletAlias
ignoreReplicaAliases = make([]*topodatapb.TabletAlias, len(emergencyReparentShardOptions.IgnoreReplicaAliasStrList))
)

Expand All @@ -114,6 +116,13 @@ func commandEmergencyReparentShard(cmd *cobra.Command, args []string) error {
}
}

if emergencyReparentShardOptions.ExpectedPrimaryAliasStr != "" {
expectedPrimaryAlias, err = topoproto.ParseTabletAlias(emergencyReparentShardOptions.ExpectedPrimaryAliasStr)
if err != nil {
return err
}
}

for i, aliasStr := range emergencyReparentShardOptions.IgnoreReplicaAliasStrList {
alias, err := topoproto.ParseTabletAlias(aliasStr)
if err != nil {
Expand All @@ -129,6 +138,7 @@ func commandEmergencyReparentShard(cmd *cobra.Command, args []string) error {
Keyspace: keyspace,
Shard: shard,
NewPrimary: newPrimaryAlias,
ExpectedPrimary: expectedPrimaryAlias,
IgnoreReplicas: ignoreReplicaAliases,
WaitReplicasTimeout: protoutil.DurationToProto(emergencyReparentShardOptions.WaitReplicasTimeout),
PreventCrossCellPromotion: emergencyReparentShardOptions.PreventCrossCellPromotion,
Expand Down Expand Up @@ -181,9 +191,10 @@ func commandInitShardPrimary(cmd *cobra.Command, args []string) error {
}

var plannedReparentShardOptions = struct {
NewPrimaryAliasStr string
AvoidPrimaryAliasStr string
WaitReplicasTimeout time.Duration
NewPrimaryAliasStr string
AvoidPrimaryAliasStr string
ExpectedPrimaryAliasStr string
WaitReplicasTimeout time.Duration
}{}

func commandPlannedReparentShard(cmd *cobra.Command, args []string) error {
Expand All @@ -193,8 +204,9 @@ func commandPlannedReparentShard(cmd *cobra.Command, args []string) error {
}

var (
newPrimaryAlias *topodatapb.TabletAlias
avoidPrimaryAlias *topodatapb.TabletAlias
newPrimaryAlias *topodatapb.TabletAlias
avoidPrimaryAlias *topodatapb.TabletAlias
expectedPrimaryAlias *topodatapb.TabletAlias
)

if plannedReparentShardOptions.NewPrimaryAliasStr != "" {
Expand All @@ -211,13 +223,21 @@ func commandPlannedReparentShard(cmd *cobra.Command, args []string) error {
}
}

if plannedReparentShardOptions.ExpectedPrimaryAliasStr != "" {
expectedPrimaryAlias, err = topoproto.ParseTabletAlias(plannedReparentShardOptions.ExpectedPrimaryAliasStr)
if err != nil {
return err
}
}

cli.FinishedParsing(cmd)

resp, err := client.PlannedReparentShard(commandCtx, &vtctldatapb.PlannedReparentShardRequest{
Keyspace: keyspace,
Shard: shard,
NewPrimary: newPrimaryAlias,
AvoidPrimary: avoidPrimaryAlias,
ExpectedPrimary: expectedPrimaryAlias,
WaitReplicasTimeout: protoutil.DurationToProto(plannedReparentShardOptions.WaitReplicasTimeout),
})
if err != nil {
Expand Down Expand Up @@ -280,6 +300,7 @@ func commandTabletExternallyReparented(cmd *cobra.Command, args []string) error
func init() {
EmergencyReparentShard.Flags().DurationVar(&emergencyReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", topo.RemoteOperationTimeout, "Time to wait for replicas to catch up in reparenting.")
EmergencyReparentShard.Flags().StringVar(&emergencyReparentShardOptions.NewPrimaryAliasStr, "new-primary", "", "Alias of a tablet that should be the new primary. If not specified, the vtctld will select the best candidate to promote.")
EmergencyReparentShard.Flags().StringVar(&emergencyReparentShardOptions.ExpectedPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
EmergencyReparentShard.Flags().BoolVar(&emergencyReparentShardOptions.PreventCrossCellPromotion, "prevent-cross-cell-promotion", false, "Only promotes a new primary from the same cell as the previous primary.")
EmergencyReparentShard.Flags().StringSliceVarP(&emergencyReparentShardOptions.IgnoreReplicaAliasStrList, "ignore-replicas", "i", nil, "Comma-separated, repeated list of replica tablet aliases to ignore during the emergency reparent.")
Root.AddCommand(EmergencyReparentShard)
Expand All @@ -291,6 +312,7 @@ func init() {
PlannedReparentShard.Flags().DurationVar(&plannedReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", topo.RemoteOperationTimeout, "Time to wait for replicas to catch up on replication both before and after reparenting.")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.NewPrimaryAliasStr, "new-primary", "", "Alias of a tablet that should be the new primary.")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.AvoidPrimaryAliasStr, "avoid-primary", "", "Alias of a tablet that should not be the primary; i.e. \"reparent to any other tablet if this one is the primary\".")
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.ExpectedPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
Root.AddCommand(PlannedReparentShard)

Root.AddCommand(ReparentTablet)
Expand Down
Loading

0 comments on commit 4cc762f

Please sign in to comment.