diff --git a/go/vt/vtctl/reparent.go b/go/vt/vtctl/reparent.go index cd6cfe3fb6d..4498228d9c7 100644 --- a/go/vt/vtctl/reparent.go +++ b/go/vt/vtctl/reparent.go @@ -25,6 +25,7 @@ import ( "vitess.io/vitess/go/vt/mysqlctl" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" + "vitess.io/vitess/go/vt/vtctl/reparentutil" "vitess.io/vitess/go/vt/wrangler" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -150,7 +151,13 @@ func commandPlannedReparentShard(ctx context.Context, wr *wrangler.Wrangler, sub return err } } - return wr.PlannedReparentShard(ctx, keyspace, shard, newPrimaryAlias, avoidTabletAlias, *waitReplicasTimeout, *tolerableReplicationLag) + + return wr.PlannedReparentShard(ctx, keyspace, shard, reparentutil.PlannedReparentOptions{ + NewPrimaryAlias: newPrimaryAlias, + AvoidPrimaryAlias: avoidTabletAlias, + WaitReplicasTimeout: *waitReplicasTimeout, + TolerableReplLag: *tolerableReplicationLag, + }) } func commandEmergencyReparentShard(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error { @@ -190,8 +197,14 @@ func commandEmergencyReparentShard(ctx context.Context, wr *wrangler.Wrangler, s return err } } - unreachableReplicas := topoproto.ParseTabletSet(*ignoreReplicasList) - return wr.EmergencyReparentShard(ctx, keyspace, shard, tabletAlias, *waitReplicasTimeout, unreachableReplicas, *preventCrossCellPromotion, *waitForAllTablets) + + return wr.EmergencyReparentShard(ctx, keyspace, shard, reparentutil.EmergencyReparentOptions{ + NewPrimaryAlias: tabletAlias, + WaitAllTablets: *waitForAllTablets, + WaitReplicasTimeout: *waitReplicasTimeout, + IgnoreReplicas: topoproto.ParseTabletSet(*ignoreReplicasList), + PreventCrossCellPromotion: *preventCrossCellPromotion, + }) } func commandTabletExternallyReparented(ctx context.Context, wr *wrangler.Wrangler, subFlags *pflag.FlagSet, args []string) error { diff --git a/go/vt/wrangler/reparent.go b/go/vt/wrangler/reparent.go index 98c5821f7c3..1a3a45cf99b 100644 --- a/go/vt/wrangler/reparent.go +++ b/go/vt/wrangler/reparent.go @@ -26,7 +26,6 @@ import ( "time" "vitess.io/vitess/go/event" - "vitess.io/vitess/go/sets" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/topotools/events" @@ -79,19 +78,13 @@ func (wr *Wrangler) InitShardPrimary(ctx context.Context, keyspace, shard string func (wr *Wrangler) PlannedReparentShard( ctx context.Context, keyspace, shard string, - primaryElectTabletAlias, avoidTabletAlias *topodatapb.TabletAlias, - waitReplicasTimeout, tolerableReplicationLag time.Duration, + opts reparentutil.PlannedReparentOptions, ) (err error) { _, err = reparentutil.NewPlannedReparenter(wr.ts, wr.tmc, wr.logger).ReparentShard( ctx, keyspace, shard, - reparentutil.PlannedReparentOptions{ - AvoidPrimaryAlias: avoidTabletAlias, - NewPrimaryAlias: primaryElectTabletAlias, - WaitReplicasTimeout: waitReplicasTimeout, - TolerableReplLag: tolerableReplicationLag, - }, + opts, ) return err @@ -99,18 +92,12 @@ func (wr *Wrangler) PlannedReparentShard( // EmergencyReparentShard will make the provided tablet the primary for // the shard, when the old primary is completely unreachable. -func (wr *Wrangler) EmergencyReparentShard(ctx context.Context, keyspace, shard string, primaryElectTabletAlias *topodatapb.TabletAlias, waitReplicasTimeout time.Duration, ignoredTablets sets.Set[string], preventCrossCellPromotion bool, waitForAllTablets bool) (err error) { +func (wr *Wrangler) EmergencyReparentShard(ctx context.Context, keyspace, shard string, opts reparentutil.EmergencyReparentOptions) (err error) { _, err = reparentutil.NewEmergencyReparenter(wr.ts, wr.tmc, wr.logger).ReparentShard( ctx, keyspace, shard, - reparentutil.EmergencyReparentOptions{ - NewPrimaryAlias: primaryElectTabletAlias, - WaitReplicasTimeout: waitReplicasTimeout, - IgnoreReplicas: ignoredTablets, - PreventCrossCellPromotion: preventCrossCellPromotion, - WaitAllTablets: waitForAllTablets, - }, + opts, ) return err diff --git a/go/vt/wrangler/testlib/emergency_reparent_shard_test.go b/go/vt/wrangler/testlib/emergency_reparent_shard_test.go index efdca1fc725..6cafe83b684 100644 --- a/go/vt/wrangler/testlib/emergency_reparent_shard_test.go +++ b/go/vt/wrangler/testlib/emergency_reparent_shard_test.go @@ -32,6 +32,7 @@ import ( "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/topo/memorytopo" "vitess.io/vitess/go/vt/topo/topoproto" + "vitess.io/vitess/go/vt/vtctl/reparentutil" "vitess.io/vitess/go/vt/vtctl/reparentutil/reparenttestutil" "vitess.io/vitess/go/vt/vtenv" "vitess.io/vitess/go/vt/vttablet/tmclient" @@ -279,7 +280,13 @@ func TestEmergencyReparentShardPrimaryElectNotBest(t *testing.T) { defer moreAdvancedReplica.StopActionLoop(t) // run EmergencyReparentShard - err := wr.EmergencyReparentShard(ctx, newPrimary.Tablet.Keyspace, newPrimary.Tablet.Shard, newPrimary.Tablet.Alias, 10*time.Second, sets.New[string](), false, false) + err := wr.EmergencyReparentShard(ctx, newPrimary.Tablet.Keyspace, newPrimary.Tablet.Shard, reparentutil.EmergencyReparentOptions{ + NewPrimaryAlias: newPrimary.Tablet.Alias, + WaitAllTablets: false, + WaitReplicasTimeout: 10 * time.Second, + IgnoreReplicas: sets.New[string](), + PreventCrossCellPromotion: false, + }) cancel() assert.NoError(t, err)