Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where topo func was called instead of dry run func. Improve SwitchReads dry run output #6497

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions go/vt/wrangler/switcher_dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ type switcherDryRun struct {
ts *trafficSwitcher
}

func getCellString(cells []string) string {
cellString := strings.Join(cells, ",")
if cellString == "" {
cellString = "all cells"
} else {
cellString = "cells: " + cellString
}
return cellString
}

func (dr *switcherDryRun) switchShardReads(ctx context.Context, cells []string, servedType topodatapb.TabletType, direction TrafficSwitchDirection) error {
sourceShards := make([]string, 0)
targetShards := make([]string, 0)
Expand All @@ -48,12 +58,13 @@ func (dr *switcherDryRun) switchShardReads(ctx context.Context, cells []string,
}
sort.Strings(sourceShards)
sort.Strings(targetShards)
cellString := getCellString(cells)
if direction == DirectionForward {
dr.drLog.Log(fmt.Sprintf("Switch reads from keyspace %s to keyspace %s for shards %s to shards %s",
dr.ts.sourceKeyspace, dr.ts.targetKeyspace, strings.Join(sourceShards, ","), strings.Join(targetShards, ",")))
dr.drLog.Log(fmt.Sprintf("Switch reads for %s tablets in %s from keyspace %s to keyspace %s for shards %s to shards %s",
servedType.String(), cellString, dr.ts.sourceKeyspace, dr.ts.targetKeyspace, strings.Join(sourceShards, ","), strings.Join(targetShards, ",")))
} else {
dr.drLog.Log(fmt.Sprintf("Switch reads from keyspace %s to keyspace %s for shards %s to shards %s",
dr.ts.targetKeyspace, dr.ts.sourceKeyspace, strings.Join(targetShards, ","), strings.Join(sourceShards, ",")))
dr.drLog.Log(fmt.Sprintf("Switch reads for %s tablets in %s from keyspace %s to keyspace %s for shards %s to shards %s",
servedType.String(), cellString, dr.ts.targetKeyspace, dr.ts.sourceKeyspace, strings.Join(targetShards, ","), strings.Join(sourceShards, ",")))
}
return nil
}
Expand All @@ -63,7 +74,9 @@ func (dr *switcherDryRun) switchTableReads(ctx context.Context, cells []string,
if direction == DirectionBackward {
ks = dr.ts.sourceKeyspace
}
dr.drLog.Log(fmt.Sprintf("Switch reads for tables %s to keyspace %s", strings.Join(dr.ts.tables, ","), ks))
cellString := getCellString(cells)
dr.drLog.Log(fmt.Sprintf("Switch reads for tables %s in %s tablets in %s to keyspace %s",
strings.Join(dr.ts.tables, ","), servedType.String(), cellString, ks))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/traffic_switcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (wr *Wrangler) SwitchReads(ctx context.Context, targetKeyspace, workflow st
}
return sw.logs(), nil
}
if err := ts.switchShardReads(ctx, cells, servedType, direction); err != nil {
if err := sw.switchShardReads(ctx, cells, servedType, direction); err != nil {
ts.wr.Logger().Errorf("switchShardReads failed: %v", err)
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/wrangler/traffic_switcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ func TestTableMigrateOneToManyDryRun(t *testing.T) {

wantdryRunReads := []string{
"Lock keyspace ks1",
"Switch reads for tables t1,t2 to keyspace ks2",
"Switch reads for tables t1,t2 in RDONLY tablets in all cells to keyspace ks2",
"Unlock keyspace ks1",
}
wantdryRunWrites := []string{
Expand Down