Skip to content

Commit

Permalink
Minor changes after final self review
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Oct 20, 2024
1 parent 3fa88df commit e9685d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
32 changes: 18 additions & 14 deletions go/test/endtoend/vreplication/resharding_workflows_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,28 +1089,32 @@ func tstApplySchemaOnlineDDL(t *testing.T, sql string, keyspace string) {
}

func validateTableRoutingRule(t *testing.T, table, tabletType, fromKeyspace, toKeyspace string) {
tabletType = strings.ToLower(strings.TrimSpace(tabletType))
rr := getRoutingRules(t)
// We set matched = true by default because it is possible, if --no-routing-rules is set while creating a workflow,
// that the routing rules are empty when the workflow starts.
// We set matched = true by default because it is possible, if --no-routing-rules is set while creating
// a workflow, that the routing rules are empty when the workflow starts.
// We set it to false below when the rule is found, but before matching the routed keyspace.
matched := true
for _, r := range rr.GetRules() {
ruleKey := fmt.Sprintf("%s.%s", fromKeyspace, table)
fromRule := fmt.Sprintf("%s.%s", fromKeyspace, table)
if tabletType != "" && tabletType != "primary" {
ruleKey = fmt.Sprintf("%s@%s", ruleKey, tabletType)
fromRule = fmt.Sprintf("%s@%s", fromRule, tabletType)
}
if r.FromTable == ruleKey {
matched = false // We found the rule, so we can set matched to false here and check for the routed keyspace below.
if r.FromTable == fromRule {
// We found the rule, so we can set matched to false here and check for the routed keyspace below.
matched = false
require.NotEmpty(t, r.ToTables)
toTable := r.ToTables[0]
arr := strings.Split(toTable, ".") // The ToTables value is of the form "routedKeyspace".table".
if len(arr) == 2 { // Should always be true.
routedKeyspace := arr[0]
if routedKeyspace == toKeyspace {
matched = true // We found the rule and the keyspace matches.
break
}
// The ToTables value is of the form "routedKeyspace.table".
routedKeyspace, routedTable, ok := strings.Cut(toTable, ".")
require.True(t, ok)
require.Equal(t, table, routedTable)
if routedKeyspace == toKeyspace {
// We found the rule, the table and keyspace matches, so our search is done.
matched = true
break
}
}
}
require.Truef(t, matched, "Routing rule for %s.%s from %s to %s not found", fromKeyspace, table, tabletType, toKeyspace)
require.Truef(t, matched, "routing rule for %s.%s from %s to %s not found", fromKeyspace, table, tabletType, toKeyspace)
}
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3143,7 +3143,7 @@ func (s *Server) WorkflowSwitchTraffic(ctx context.Context, req *vtctldatapb.Wor
span.Annotate("tablet-types", req.TabletTypes)
span.Annotate("direction", req.Direction)
span.Annotate("enable-reverse-replication", req.EnableReverseReplication)
span.Annotate("shards", req.GetShards)
span.Annotate("shards", req.Shards)
span.Annotate("force", req.Force)

var (
Expand Down Expand Up @@ -3195,7 +3195,7 @@ func (s *Server) WorkflowSwitchTraffic(ctx context.Context, req *vtctldatapb.Wor
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "cannot reverse traffic for multi-tenant migrations")
}

// We need this to know when there isn't a reverse workflow to use.
// We need this to know when there isn't a (non-FROZEN) reverse workflow to use.
onlySwitchingReads := !startState.WritesSwitched && !switchPrimary

// We need this for idempotency and to avoid unnecessary work and resulting risk.
Expand Down

0 comments on commit e9685d5

Please sign in to comment.