Skip to content

Commit

Permalink
go/vt/wrangler: pass reparent options structs (#15251)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <[email protected]>
  • Loading branch information
mdlayher authored Feb 19, 2024
1 parent c4afae2 commit 4ddb705
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
19 changes: 16 additions & 3 deletions go/vt/vtctl/reparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 4 additions & 17 deletions go/vt/wrangler/reparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,38 +78,26 @@ 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
}

// 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
Expand Down
9 changes: 8 additions & 1 deletion go/vt/wrangler/testlib/emergency_reparent_shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4ddb705

Please sign in to comment.