Skip to content

Commit 3c768db

Browse files
committed
Revert "[release-21.0] VReplication: Support reversing read-only traffic in vtctldclient (vitessio#16920) (vitessio#17015)"
This reverts commit ecb4ae1.
1 parent ecb4ae1 commit 3c768db

File tree

9 files changed

+101
-1102
lines changed

9 files changed

+101
-1102
lines changed

go/test/endtoend/vreplication/helper_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,8 @@ func executeOnTablet(t *testing.T, conn *mysql.Conn, tablet *cluster.VttabletPro
339339

340340
func assertQueryExecutesOnTablet(t *testing.T, conn *mysql.Conn, tablet *cluster.VttabletProcess, ksName string, query string, matchQuery string) {
341341
t.Helper()
342-
rr, err := vc.VtctldClient.ExecuteCommandWithOutput("GetRoutingRules")
343-
require.NoError(t, err)
344342
count0, body0, count1, body1 := executeOnTablet(t, conn, tablet, ksName, query, matchQuery)
345-
require.Equalf(t, count0+1, count1, "query %q did not execute on destination %s (%s-%d);\ntried to match %q\nbefore:\n%s\n\nafter:\n%s\n\nrouting rules:\n%s\n\n",
346-
query, ksName, tablet.Cell, tablet.TabletUID, matchQuery, body0, body1, rr)
343+
assert.Equalf(t, count0+1, count1, "query %q did not execute in target;\ntried to match %q\nbefore:\n%s\n\nafter:\n%s\n\n", query, matchQuery, body0, body1)
347344
}
348345

349346
func assertQueryDoesNotExecutesOnTablet(t *testing.T, conn *mysql.Conn, tablet *cluster.VttabletProcess, ksName string, query string, matchQuery string) {

go/test/endtoend/vreplication/movetables_buffering_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ import (
1212
)
1313

1414
func TestMoveTablesBuffering(t *testing.T) {
15-
ogReplicas := defaultReplicas
16-
ogRdOnly := defaultRdonly
17-
defer func() {
18-
defaultReplicas = ogReplicas
19-
defaultRdonly = ogRdOnly
20-
}()
21-
defaultRdonly = 0
22-
defaultReplicas = 0
15+
defaultRdonly = 1
2316
vc = setupMinimalCluster(t)
2417
defer vc.TearDown()
2518

go/test/endtoend/vreplication/resharding_workflows_v2_test.go

Lines changed: 31 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"net"
23-
"slices"
2423
"strconv"
2524
"strings"
2625
"testing"
@@ -32,11 +31,9 @@ import (
3231

3332
"vitess.io/vitess/go/test/endtoend/cluster"
3433
"vitess.io/vitess/go/vt/log"
35-
"vitess.io/vitess/go/vt/topo/topoproto"
3634
"vitess.io/vitess/go/vt/wrangler"
3735

3836
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
39-
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
4037
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
4138
)
4239

@@ -166,7 +163,9 @@ func tstWorkflowExec(t *testing.T, cells, workflow, sourceKs, targetKs, tables,
166163
args = append(args, "--tablet-types", tabletTypes)
167164
}
168165
args = append(args, "--action_timeout=10m") // At this point something is up so fail the test
169-
t.Logf("Executing workflow command: vtctldclient %s", strings.Join(args, " "))
166+
if debugMode {
167+
t.Logf("Executing workflow command: vtctldclient %v", strings.Join(args, " "))
168+
}
170169
output, err := vc.VtctldClient.ExecuteCommandWithOutput(args...)
171170
lastOutput = output
172171
if err != nil {
@@ -327,45 +326,27 @@ func tstWorkflowCancel(t *testing.T) error {
327326
return tstWorkflowAction(t, workflowActionCancel, "", "")
328327
}
329328

330-
func validateReadsRoute(t *testing.T, tabletType string, tablet *cluster.VttabletProcess) {
331-
if tablet == nil {
332-
return
329+
func validateReadsRoute(t *testing.T, tabletTypes string, tablet *cluster.VttabletProcess) {
330+
if tabletTypes == "" {
331+
tabletTypes = "replica,rdonly"
333332
}
334333
vtgateConn, closeConn := getVTGateConn()
335334
defer closeConn()
336-
// We do NOT want to target a shard as that goes around the routing rules and
337-
// defeats the purpose here. We are using a query w/o a WHERE clause so for
338-
// sharded keyspaces it should hit all shards as a SCATTER query. So all we
339-
// care about is the keyspace and tablet type.
340-
destination := fmt.Sprintf("%s@%s", tablet.Keyspace, strings.ToLower(tabletType))
341-
readQuery := "select cid from customer limit 50"
342-
assertQueryExecutesOnTablet(t, vtgateConn, tablet, destination, readQuery, "select cid from customer limit :vtg1")
335+
for _, tt := range []string{"replica", "rdonly"} {
336+
destination := fmt.Sprintf("%s:%s@%s", tablet.Keyspace, tablet.Shard, tt)
337+
if strings.Contains(tabletTypes, tt) {
338+
readQuery := "select * from customer"
339+
assertQueryExecutesOnTablet(t, vtgateConn, tablet, destination, readQuery, readQuery)
340+
}
341+
}
343342
}
344343

345344
func validateReadsRouteToSource(t *testing.T, tabletTypes string) {
346-
tt, err := topoproto.ParseTabletTypes(tabletTypes)
347-
require.NoError(t, err)
348-
if slices.Contains(tt, topodatapb.TabletType_REPLICA) {
349-
require.NotNil(t, sourceReplicaTab)
350-
validateReadsRoute(t, topodatapb.TabletType_REPLICA.String(), sourceReplicaTab)
351-
}
352-
if slices.Contains(tt, topodatapb.TabletType_RDONLY) {
353-
require.NotNil(t, sourceRdonlyTab)
354-
validateReadsRoute(t, topodatapb.TabletType_RDONLY.String(), sourceRdonlyTab)
355-
}
345+
validateReadsRoute(t, tabletTypes, sourceReplicaTab)
356346
}
357347

358348
func validateReadsRouteToTarget(t *testing.T, tabletTypes string) {
359-
tt, err := topoproto.ParseTabletTypes(tabletTypes)
360-
require.NoError(t, err)
361-
if slices.Contains(tt, topodatapb.TabletType_REPLICA) {
362-
require.NotNil(t, targetReplicaTab1)
363-
validateReadsRoute(t, topodatapb.TabletType_REPLICA.String(), targetReplicaTab1)
364-
}
365-
if slices.Contains(tt, topodatapb.TabletType_RDONLY) {
366-
require.NotNil(t, targetRdonlyTab1)
367-
validateReadsRoute(t, topodatapb.TabletType_RDONLY.String(), targetRdonlyTab1)
368-
}
349+
validateReadsRoute(t, tabletTypes, targetReplicaTab1)
369350
}
370351

371352
func validateWritesRouteToSource(t *testing.T) {
@@ -415,13 +396,6 @@ func getCurrentStatus(t *testing.T) string {
415396
// but CI currently fails on creating multiple clusters even after the previous ones are torn down
416397

417398
func TestBasicV2Workflows(t *testing.T) {
418-
ogReplicas := defaultReplicas
419-
ogRdOnly := defaultRdonly
420-
defer func() {
421-
defaultReplicas = ogReplicas
422-
defaultRdonly = ogRdOnly
423-
}()
424-
defaultReplicas = 1
425399
defaultRdonly = 1
426400
extraVTTabletArgs = []string{
427401
parallelInsertWorkers,
@@ -659,12 +633,6 @@ func testPartialSwitches(t *testing.T) {
659633
tstWorkflowSwitchReads(t, "", "")
660634
checkStates(t, nextState, nextState) // idempotency
661635

662-
tstWorkflowReverseReads(t, "replica,rdonly", "")
663-
checkStates(t, wrangler.WorkflowStateReadsSwitched, wrangler.WorkflowStateNotSwitched)
664-
665-
tstWorkflowSwitchReads(t, "", "")
666-
checkStates(t, wrangler.WorkflowStateNotSwitched, wrangler.WorkflowStateReadsSwitched)
667-
668636
tstWorkflowSwitchWrites(t)
669637
currentState = nextState
670638
nextState = wrangler.WorkflowStateAllSwitched
@@ -701,12 +669,12 @@ func testRestOfWorkflow(t *testing.T) {
701669
waitForLowLag(t, "customer", "wf1")
702670
tstWorkflowSwitchReads(t, "", "")
703671
checkStates(t, wrangler.WorkflowStateNotSwitched, wrangler.WorkflowStateReadsSwitched)
704-
validateReadsRouteToTarget(t, "replica,rdonly")
672+
validateReadsRouteToTarget(t, "replica")
705673
validateWritesRouteToSource(t)
706674

707675
tstWorkflowSwitchWrites(t)
708676
checkStates(t, wrangler.WorkflowStateReadsSwitched, wrangler.WorkflowStateAllSwitched)
709-
validateReadsRouteToTarget(t, "replica,rdonly")
677+
validateReadsRouteToTarget(t, "replica")
710678
validateWritesRouteToTarget(t)
711679

712680
// this function is called for both MoveTables and Reshard, so the reverse workflows exist in different keyspaces
@@ -717,45 +685,42 @@ func testRestOfWorkflow(t *testing.T) {
717685
waitForLowLag(t, keyspace, "wf1_reverse")
718686
tstWorkflowReverseReads(t, "", "")
719687
checkStates(t, wrangler.WorkflowStateAllSwitched, wrangler.WorkflowStateWritesSwitched)
720-
validateReadsRouteToSource(t, "replica,rdonly")
688+
validateReadsRouteToSource(t, "replica")
721689
validateWritesRouteToTarget(t)
722690

723691
tstWorkflowReverseWrites(t)
724692
checkStates(t, wrangler.WorkflowStateWritesSwitched, wrangler.WorkflowStateNotSwitched)
725-
validateReadsRouteToSource(t, "replica,rdonly")
693+
validateReadsRouteToSource(t, "replica")
726694
validateWritesRouteToSource(t)
727695

728696
waitForLowLag(t, "customer", "wf1")
729697
tstWorkflowSwitchWrites(t)
730698
checkStates(t, wrangler.WorkflowStateNotSwitched, wrangler.WorkflowStateWritesSwitched)
731-
validateReadsRouteToSource(t, "replica,rdonly")
699+
validateReadsRouteToSource(t, "replica")
732700
validateWritesRouteToTarget(t)
733701

734702
waitForLowLag(t, keyspace, "wf1_reverse")
735703
tstWorkflowReverseWrites(t)
736-
checkStates(t, wrangler.WorkflowStateWritesSwitched, wrangler.WorkflowStateNotSwitched)
737-
validateReadsRouteToSource(t, "replica,rdonly")
704+
validateReadsRouteToSource(t, "replica")
738705
validateWritesRouteToSource(t)
739706

740707
waitForLowLag(t, "customer", "wf1")
741708
tstWorkflowSwitchReads(t, "", "")
742-
checkStates(t, wrangler.WorkflowStateNotSwitched, wrangler.WorkflowStateReadsSwitched)
743-
validateReadsRouteToTarget(t, "replica,rdonly")
709+
validateReadsRouteToTarget(t, "replica")
744710
validateWritesRouteToSource(t)
745711

746712
tstWorkflowReverseReads(t, "", "")
747-
checkStates(t, wrangler.WorkflowStateReadsSwitched, wrangler.WorkflowStateNotSwitched)
748-
validateReadsRouteToSource(t, "replica,rdonly")
713+
validateReadsRouteToSource(t, "replica")
749714
validateWritesRouteToSource(t)
750715

751716
tstWorkflowSwitchReadsAndWrites(t)
752-
checkStates(t, wrangler.WorkflowStateNotSwitched, wrangler.WorkflowStateAllSwitched)
753-
validateReadsRouteToTarget(t, "replica,rdonly")
717+
validateReadsRouteToTarget(t, "replica")
718+
validateReadsRoute(t, "rdonly", targetRdonlyTab1)
754719
validateWritesRouteToTarget(t)
755720
waitForLowLag(t, keyspace, "wf1_reverse")
756721
tstWorkflowReverseReadsAndWrites(t)
757-
checkStates(t, wrangler.WorkflowStateAllSwitched, wrangler.WorkflowStateNotSwitched)
758-
validateReadsRouteToSource(t, "replica,rdonly")
722+
validateReadsRoute(t, "rdonly", sourceRdonlyTab)
723+
validateReadsRouteToSource(t, "replica")
759724
validateWritesRouteToSource(t)
760725

761726
// trying to complete an unswitched workflow should error
@@ -766,7 +731,8 @@ func testRestOfWorkflow(t *testing.T) {
766731
// fully switch and complete
767732
waitForLowLag(t, "customer", "wf1")
768733
tstWorkflowSwitchReadsAndWrites(t)
769-
validateReadsRouteToTarget(t, "replica,rdonly")
734+
validateReadsRoute(t, "rdonly", targetRdonlyTab1)
735+
validateReadsRouteToTarget(t, "replica")
770736
validateWritesRouteToTarget(t)
771737

772738
err = tstWorkflowComplete(t)
@@ -821,7 +787,7 @@ func setupMinimalCluster(t *testing.T) *VitessCluster {
821787

822788
zone1 := vc.Cells["zone1"]
823789

824-
vc.AddKeyspace(t, []*Cell{zone1}, "product", "0", initialProductVSchema, initialProductSchema, defaultReplicas, defaultRdonly, 100, nil)
790+
vc.AddKeyspace(t, []*Cell{zone1}, "product", "0", initialProductVSchema, initialProductSchema, 0, 0, 100, nil)
825791

826792
verifyClusterHealth(t, vc)
827793
insertInitialData(t)
@@ -834,7 +800,7 @@ func setupMinimalCluster(t *testing.T) *VitessCluster {
834800
func setupMinimalCustomerKeyspace(t *testing.T) map[string]*cluster.VttabletProcess {
835801
tablets := make(map[string]*cluster.VttabletProcess)
836802
if _, err := vc.AddKeyspace(t, []*Cell{vc.Cells["zone1"]}, "customer", "-80,80-",
837-
customerVSchema, customerSchema, defaultReplicas, defaultRdonly, 200, nil); err != nil {
803+
customerVSchema, customerSchema, 0, 0, 200, nil); err != nil {
838804
t.Fatal(err)
839805
}
840806
defaultCell := vc.Cells[vc.CellNames[0]]
@@ -970,7 +936,6 @@ func createAdditionalCustomerShards(t *testing.T, shards string) {
970936
targetTab2 = custKs.Shards["80-c0"].Tablets["zone1-600"].Vttablet
971937
targetTab1 = custKs.Shards["40-80"].Tablets["zone1-500"].Vttablet
972938
targetReplicaTab1 = custKs.Shards["-40"].Tablets["zone1-401"].Vttablet
973-
targetRdonlyTab1 = custKs.Shards["-40"].Tablets["zone1-402"].Vttablet
974939

975940
sourceTab = custKs.Shards["-80"].Tablets["zone1-200"].Vttablet
976941
sourceReplicaTab = custKs.Shards["-80"].Tablets["zone1-201"].Vttablet
@@ -982,34 +947,3 @@ func tstApplySchemaOnlineDDL(t *testing.T, sql string, keyspace string) {
982947
"--sql", sql, keyspace)
983948
require.NoError(t, err, fmt.Sprintf("ApplySchema Error: %s", err))
984949
}
985-
986-
func validateTableRoutingRule(t *testing.T, table, tabletType, fromKeyspace, toKeyspace string) {
987-
tabletType = strings.ToLower(strings.TrimSpace(tabletType))
988-
rr := getRoutingRules(t)
989-
// We set matched = true by default because it is possible, if --no-routing-rules is set while creating
990-
// a workflow, that the routing rules are empty when the workflow starts.
991-
// We set it to false below when the rule is found, but before matching the routed keyspace.
992-
matched := true
993-
for _, r := range rr.GetRules() {
994-
fromRule := fmt.Sprintf("%s.%s", fromKeyspace, table)
995-
if tabletType != "" && tabletType != "primary" {
996-
fromRule = fmt.Sprintf("%s@%s", fromRule, tabletType)
997-
}
998-
if r.FromTable == fromRule {
999-
// We found the rule, so we can set matched to false here and check for the routed keyspace below.
1000-
matched = false
1001-
require.NotEmpty(t, r.ToTables)
1002-
toTable := r.ToTables[0]
1003-
// The ToTables value is of the form "routedKeyspace.table".
1004-
routedKeyspace, routedTable, ok := strings.Cut(toTable, ".")
1005-
require.True(t, ok)
1006-
require.Equal(t, table, routedTable)
1007-
if routedKeyspace == toKeyspace {
1008-
// We found the rule, the table and keyspace matches, so our search is done.
1009-
matched = true
1010-
break
1011-
}
1012-
}
1013-
}
1014-
require.Truef(t, matched, "routing rule for %s.%s from %s to %s not found", fromKeyspace, table, tabletType, toKeyspace)
1015-
}

0 commit comments

Comments
 (0)