Skip to content

Commit

Permalink
Also validate SrvKeyspace during SwitchWrites
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Feb 19, 2021
1 parent eb49bee commit cd3a200
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions go/vt/wrangler/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,6 @@ func (wr *Wrangler) SwitchReads(ctx context.Context, targetKeyspace, workflow st
return sw.logs(), nil
}
wr.Logger().Infof("About to switchShardReads: %+v, %+v, %+v", cells, servedTypes, direction)
if err := wr.ts.ValidateSrvKeyspace(ctx, targetKeyspace, strings.Join(cells, ",")); err != nil {
err2 := vterrors.Wrapf(err, "Before switching shard reads, found SrvKeyspace for %s is corrupt in cell %s",
targetKeyspace, strings.Join(cells, ","))
log.Errorf("%w", err2)
return nil, err2
}

if err := ts.switchShardReads(ctx, cells, servedTypes, direction); err != nil {
ts.wr.Logger().Errorf("switchShardReads failed: %v", err)
return nil, err
Expand Down Expand Up @@ -1035,6 +1028,12 @@ func (ts *trafficSwitcher) switchShardReads(ctx context.Context, cells []string,
} else {
fromShards, toShards = ts.targetShards(), ts.sourceShards()
}
if err := ts.wr.ts.ValidateSrvKeyspace(ctx, ts.targetKeyspace, strings.Join(cells, ",")); err != nil {
err2 := vterrors.Wrapf(err, "Before switching shard reads, found SrvKeyspace for %s is corrupt in cell %s",
ts.targetKeyspace, strings.Join(cells, ","))
log.Errorf("%w", err2)
return err2
}
for _, servedType := range servedTypes {
if err := ts.wr.updateShardRecords(ctx, ts.sourceKeyspace, fromShards, cells, servedType, true /* isFrom */, false /* clearSourceShards */); err != nil {
return err
Expand All @@ -1047,6 +1046,12 @@ func (ts *trafficSwitcher) switchShardReads(ctx context.Context, cells []string,
return err
}
}
if err := ts.wr.ts.ValidateSrvKeyspace(ctx, ts.targetKeyspace, strings.Join(cells, ",")); err != nil {
err2 := vterrors.Wrapf(err, "After switching shard reads, found SrvKeyspace for %s is corrupt in cell %s",
ts.targetKeyspace, strings.Join(cells, ","))
log.Errorf("%w", err2)
return err2
}
return nil
}

Expand Down Expand Up @@ -1389,6 +1394,11 @@ func (ts *trafficSwitcher) changeWriteRoute(ctx context.Context) error {
}

func (ts *trafficSwitcher) changeShardRouting(ctx context.Context) error {
if err := ts.wr.ts.ValidateSrvKeyspace(ctx, ts.targetKeyspace, ""); err != nil {
err2 := vterrors.Wrapf(err, "Before changing shard routes, found SrvKeyspace for %s is corrupt", ts.targetKeyspace)
log.Errorf("%w", err2)
return err2
}
err := ts.forAllSources(func(source *tsSource) error {
_, err := ts.wr.ts.UpdateShardFields(ctx, ts.sourceKeyspace, source.si.ShardName(), func(si *topo.ShardInfo) error {
si.IsMasterServing = false
Expand All @@ -1409,7 +1419,16 @@ func (ts *trafficSwitcher) changeShardRouting(ctx context.Context) error {
if err != nil {
return err
}
return ts.wr.ts.MigrateServedType(ctx, ts.targetKeyspace, ts.targetShards(), ts.sourceShards(), topodatapb.TabletType_MASTER, nil)
err = ts.wr.ts.MigrateServedType(ctx, ts.targetKeyspace, ts.targetShards(), ts.sourceShards(), topodatapb.TabletType_MASTER, nil)
if err != nil {
return err
}
if err := ts.wr.ts.ValidateSrvKeyspace(ctx, ts.targetKeyspace, ""); err != nil {
err2 := vterrors.Wrapf(err, "After changing shard routes, found SrvKeyspace for %s is corrupt", ts.targetKeyspace)
log.Errorf("%w", err2)
return err2
}
return nil
}

func (ts *trafficSwitcher) startReverseVReplication(ctx context.Context) error {
Expand Down

0 comments on commit cd3a200

Please sign in to comment.