Skip to content

Commit

Permalink
Include PRS too
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Oct 2, 2024
1 parent c0abfdc commit 383cdcb
Show file tree
Hide file tree
Showing 9 changed files with 1,166 additions and 967 deletions.
15 changes: 13 additions & 2 deletions go/cmd/vtctldclient/command/reparents.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func commandInitShardPrimary(cmd *cobra.Command, args []string) error {
var plannedReparentShardOptions = struct {
NewPrimaryAliasStr string
AvoidPrimaryAliasStr string
ExpectedPrimaryAliasStr string
WaitReplicasTimeout time.Duration
TolerableReplicationLag time.Duration
AllowCrossCellPromotion bool
Expand All @@ -207,8 +208,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 @@ -225,13 +227,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),
TolerableReplicationLag: protoutil.DurationToProto(plannedReparentShardOptions.TolerableReplicationLag),
AllowCrossCellPromotion: plannedReparentShardOptions.AllowCrossCellPromotion,
Expand Down Expand Up @@ -310,6 +320,7 @@ func init() {
PlannedReparentShard.Flags().DurationVar(&plannedReparentShardOptions.TolerableReplicationLag, "tolerable-replication-lag", 0, "Amount of replication lag that is considered acceptable for a tablet to be eligible for promotion when Vitess makes the choice of a new primary.")
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.NewPrimaryAliasStr, "expected-primary", "", "Alias of a tablet that must be the current primary in order for the reparent to be processed.")
PlannedReparentShard.Flags().BoolVar(&plannedReparentShardOptions.AllowCrossCellPromotion, "allow-cross-cell-promotion", false, "Allow cross cell promotion")
Root.AddCommand(PlannedReparentShard)

Expand Down
1,943 changes: 979 additions & 964 deletions go/vt/proto/vtctldata/vtctldata.pb.go

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions go/vt/proto/vtctldata/vtctldata_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3072,6 +3072,10 @@ func (s *VtctldServer) PlannedReparentShard(ctx context.Context, req *vtctldatap
span.Annotate("avoid_primary_alias", topoproto.TabletAliasString(req.AvoidPrimary))
}

if req.ExpectedPrimary != nil {
span.Annotate("expected_primary_alias", topoproto.TabletAliasString(req.ExpectedPrimary))
}

if req.NewPrimary != nil {
span.Annotate("new_primary_alias", topoproto.TabletAliasString(req.NewPrimary))
}
Expand All @@ -3091,6 +3095,7 @@ func (s *VtctldServer) PlannedReparentShard(ctx context.Context, req *vtctldatap
reparentutil.PlannedReparentOptions{
AvoidPrimaryAlias: req.AvoidPrimary,
NewPrimaryAlias: req.NewPrimary,
ExpectedPrimaryAlias: req.ExpectedPrimary,
WaitReplicasTimeout: waitReplicasTimeout,
TolerableReplLag: tolerableReplLag,
AllowCrossCellPromotion: req.AllowCrossCellPromotion,
Expand Down
8 changes: 8 additions & 0 deletions go/vt/vtctl/reparentutil/planned_reparenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type PlannedReparenter struct {
type PlannedReparentOptions struct {
NewPrimaryAlias *topodatapb.TabletAlias
AvoidPrimaryAlias *topodatapb.TabletAlias
ExpectedPrimaryAlias *topodatapb.TabletAlias
WaitReplicasTimeout time.Duration
TolerableReplLag time.Duration
AllowCrossCellPromotion bool
Expand Down Expand Up @@ -507,6 +508,13 @@ func (pr *PlannedReparenter) reparentShardLocked(
return err
}

if opts.ExpectedPrimaryAlias != nil && !topoproto.TabletAliasEqual(opts.ExpectedPrimaryAlias, shardInfo.PrimaryAlias) {
return vterrors.Errorf(vtrpc.Code_FAILED_PRECONDITION, "primary %s is not equal to expected alias %s",
topoproto.TabletAliasString(shardInfo.PrimaryAlias),
topoproto.TabletAliasString(opts.ExpectedPrimaryAlias),
)
}

keyspaceDurability, err := pr.ts.GetKeyspaceDurability(ctx, keyspace)
if err != nil {
return err
Expand Down
74 changes: 73 additions & 1 deletion go/vt/vtctl/reparentutil/planned_reparenter_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,7 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
name string
tmc tmclient.TabletManagerClient
tablets []*topodatapb.Tablet
shards []*vtctldatapb.Shard
unlockTopo bool

ev *events.Reparent
Expand Down Expand Up @@ -3296,6 +3297,73 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
},
},
},
{
name: "expected primary mismatch",
tmc: &testutil.TabletManagerClient{
GetGlobalStatusVarsResults: map[string]struct {
Statuses map[string]string
Error error
}{
"zone1-0000000200": {
Statuses: map[string]string{
InnodbBufferPoolsDataVar: "123",
},
},
"zone1-0000000100": {
Statuses: map[string]string{
InnodbBufferPoolsDataVar: "123",
},
},
},
},
shards: []*vtctldatapb.Shard{
{
Keyspace: "testkeyspace",
Name: "-",
Shard: &topodatapb.Shard{
IsPrimaryServing: true,
PrimaryAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
},
},
},
tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Type: topodatapb.TabletType_PRIMARY,
Keyspace: "testkeyspace",
Shard: "-",
},
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 200,
},
Type: topodatapb.TabletType_REPLICA,
Keyspace: "testkeyspace",
Shard: "-",
},
},

ev: &events.Reparent{},
keyspace: "testkeyspace",
shard: "-",
opts: PlannedReparentOptions{
// This is not the shard primary, so it should cause an error.
ExpectedPrimaryAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 200,
},
},

shouldErr: true,
expectedEvent: nil,
},
}

logger := logutil.NewMemoryLogger()
Expand All @@ -3312,9 +3380,13 @@ func TestPlannedReparenter_reparentShardLocked(t *testing.T) {
testutil.AddTablets(ctx, t, ts, &testutil.AddTabletOptions{
AlsoSetShardPrimary: true,
ForceSetShardPrimary: true, // Some of our test cases count on having multiple primaries, so let the last one "win".
SkipShardCreation: false,
SkipShardCreation: len(tt.shards) > 0,
}, tt.tablets...)

if len(tt.shards) > 0 {
testutil.AddShards(ctx, t, ts, tt.shards...)
}

if !tt.unlockTopo {
lctx, unlock, err := ts.LockShard(ctx, tt.keyspace, tt.shard, "locking for testing")
require.NoError(t, err, "could not lock %s/%s for testing", tt.keyspace, tt.shard)
Expand Down
3 changes: 3 additions & 0 deletions proto/vtctldata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,9 @@ message PlannedReparentShardRequest {
vttime.Duration tolerable_replication_lag = 6;
// AllowCrossCellPromotion allows cross cell promotion,
bool allow_cross_cell_promotion = 7;
// ExpectedPrimary is the optional alias we expect to be the current primary in order for
// the reparent operation to succeed.
topodata.TabletAlias expected_primary = 8;
}

message PlannedReparentShardResponse {
Expand Down
6 changes: 6 additions & 0 deletions web/vtadmin/src/proto/vtadmin.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions web/vtadmin/src/proto/vtadmin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 383cdcb

Please sign in to comment.