Skip to content

Commit

Permalink
Filter out primary tablet type in switch reads from the tablet types …
Browse files Browse the repository at this point in the history
…passed in the request

Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Oct 25, 2023
1 parent cd2babb commit 81f5cbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3017,10 +3017,16 @@ func (s *Server) switchReads(ctx context.Context, req *vtctldatapb.WorkflowSwitc
}
defer unlock(&err)

var tabletTypes []topodatapb.TabletType
for _, tabletType := range req.TabletTypes {
if tabletType != topodatapb.TabletType_PRIMARY {
tabletTypes = append(tabletTypes, tabletType)
}
}
if ts.MigrationType() == binlogdatapb.MigrationType_TABLES {
if ts.isPartialMigration {
ts.Logger().Infof("Partial migration, skipping switchTableReads as traffic is all or nothing per shard and overridden for reads AND writes in the ShardRoutingRule created when switching writes.")
} else if err := sw.switchTableReads(ctx, cells, req.TabletTypes, direction); err != nil {
} else if err := sw.switchTableReads(ctx, cells, tabletTypes, direction); err != nil {
return handleError("failed to switch read traffic for the tables", err)
}
return sw.logs(), nil
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtctl/workflow/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ func (ts *trafficSwitcher) switchTableReads(ctx context.Context, cells []string,
// For forward migration, we add tablet type specific rules to redirect traffic to the target.
// For backward, we redirect to source.
for _, servedType := range servedTypes {
if servedType != topodatapb.TabletType_REPLICA && servedType != topodatapb.TabletType_RDONLY {
return fmt.Errorf("invalid tablet type specified for switchTableReads: %v", servedType)
}

tt := strings.ToLower(servedType.String())
for _, table := range ts.Tables() {
if direction == DirectionForward {
Expand Down

0 comments on commit 81f5cbb

Please sign in to comment.