@@ -20,7 +20,6 @@ import (
20
20
"encoding/json"
21
21
"fmt"
22
22
"net"
23
- "slices"
24
23
"strconv"
25
24
"strings"
26
25
"testing"
@@ -32,11 +31,9 @@ import (
32
31
33
32
"vitess.io/vitess/go/test/endtoend/cluster"
34
33
"vitess.io/vitess/go/vt/log"
35
- "vitess.io/vitess/go/vt/topo/topoproto"
36
34
"vitess.io/vitess/go/vt/wrangler"
37
35
38
36
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
39
- topodatapb "vitess.io/vitess/go/vt/proto/topodata"
40
37
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
41
38
)
42
39
@@ -166,7 +163,9 @@ func tstWorkflowExec(t *testing.T, cells, workflow, sourceKs, targetKs, tables,
166
163
args = append (args , "--tablet-types" , tabletTypes )
167
164
}
168
165
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
+ }
170
169
output , err := vc .VtctldClient .ExecuteCommandWithOutput (args ... )
171
170
lastOutput = output
172
171
if err != nil {
@@ -327,45 +326,27 @@ func tstWorkflowCancel(t *testing.T) error {
327
326
return tstWorkflowAction (t , workflowActionCancel , "" , "" )
328
327
}
329
328
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"
333
332
}
334
333
vtgateConn , closeConn := getVTGateConn ()
335
334
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
+ }
343
342
}
344
343
345
344
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 )
356
346
}
357
347
358
348
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 )
369
350
}
370
351
371
352
func validateWritesRouteToSource (t * testing.T ) {
@@ -415,13 +396,6 @@ func getCurrentStatus(t *testing.T) string {
415
396
// but CI currently fails on creating multiple clusters even after the previous ones are torn down
416
397
417
398
func TestBasicV2Workflows (t * testing.T ) {
418
- ogReplicas := defaultReplicas
419
- ogRdOnly := defaultRdonly
420
- defer func () {
421
- defaultReplicas = ogReplicas
422
- defaultRdonly = ogRdOnly
423
- }()
424
- defaultReplicas = 1
425
399
defaultRdonly = 1
426
400
extraVTTabletArgs = []string {
427
401
parallelInsertWorkers ,
@@ -659,12 +633,6 @@ func testPartialSwitches(t *testing.T) {
659
633
tstWorkflowSwitchReads (t , "" , "" )
660
634
checkStates (t , nextState , nextState ) // idempotency
661
635
662
- tstWorkflowReverseReads (t , "replica,rdonly" , "" )
663
- checkStates (t , wrangler .WorkflowStateReadsSwitched , wrangler .WorkflowStateNotSwitched )
664
-
665
- tstWorkflowSwitchReads (t , "" , "" )
666
- checkStates (t , wrangler .WorkflowStateNotSwitched , wrangler .WorkflowStateReadsSwitched )
667
-
668
636
tstWorkflowSwitchWrites (t )
669
637
currentState = nextState
670
638
nextState = wrangler .WorkflowStateAllSwitched
@@ -701,12 +669,12 @@ func testRestOfWorkflow(t *testing.T) {
701
669
waitForLowLag (t , "customer" , "wf1" )
702
670
tstWorkflowSwitchReads (t , "" , "" )
703
671
checkStates (t , wrangler .WorkflowStateNotSwitched , wrangler .WorkflowStateReadsSwitched )
704
- validateReadsRouteToTarget (t , "replica,rdonly " )
672
+ validateReadsRouteToTarget (t , "replica" )
705
673
validateWritesRouteToSource (t )
706
674
707
675
tstWorkflowSwitchWrites (t )
708
676
checkStates (t , wrangler .WorkflowStateReadsSwitched , wrangler .WorkflowStateAllSwitched )
709
- validateReadsRouteToTarget (t , "replica,rdonly " )
677
+ validateReadsRouteToTarget (t , "replica" )
710
678
validateWritesRouteToTarget (t )
711
679
712
680
// 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) {
717
685
waitForLowLag (t , keyspace , "wf1_reverse" )
718
686
tstWorkflowReverseReads (t , "" , "" )
719
687
checkStates (t , wrangler .WorkflowStateAllSwitched , wrangler .WorkflowStateWritesSwitched )
720
- validateReadsRouteToSource (t , "replica,rdonly " )
688
+ validateReadsRouteToSource (t , "replica" )
721
689
validateWritesRouteToTarget (t )
722
690
723
691
tstWorkflowReverseWrites (t )
724
692
checkStates (t , wrangler .WorkflowStateWritesSwitched , wrangler .WorkflowStateNotSwitched )
725
- validateReadsRouteToSource (t , "replica,rdonly " )
693
+ validateReadsRouteToSource (t , "replica" )
726
694
validateWritesRouteToSource (t )
727
695
728
696
waitForLowLag (t , "customer" , "wf1" )
729
697
tstWorkflowSwitchWrites (t )
730
698
checkStates (t , wrangler .WorkflowStateNotSwitched , wrangler .WorkflowStateWritesSwitched )
731
- validateReadsRouteToSource (t , "replica,rdonly " )
699
+ validateReadsRouteToSource (t , "replica" )
732
700
validateWritesRouteToTarget (t )
733
701
734
702
waitForLowLag (t , keyspace , "wf1_reverse" )
735
703
tstWorkflowReverseWrites (t )
736
- checkStates (t , wrangler .WorkflowStateWritesSwitched , wrangler .WorkflowStateNotSwitched )
737
- validateReadsRouteToSource (t , "replica,rdonly" )
704
+ validateReadsRouteToSource (t , "replica" )
738
705
validateWritesRouteToSource (t )
739
706
740
707
waitForLowLag (t , "customer" , "wf1" )
741
708
tstWorkflowSwitchReads (t , "" , "" )
742
- checkStates (t , wrangler .WorkflowStateNotSwitched , wrangler .WorkflowStateReadsSwitched )
743
- validateReadsRouteToTarget (t , "replica,rdonly" )
709
+ validateReadsRouteToTarget (t , "replica" )
744
710
validateWritesRouteToSource (t )
745
711
746
712
tstWorkflowReverseReads (t , "" , "" )
747
- checkStates (t , wrangler .WorkflowStateReadsSwitched , wrangler .WorkflowStateNotSwitched )
748
- validateReadsRouteToSource (t , "replica,rdonly" )
713
+ validateReadsRouteToSource (t , "replica" )
749
714
validateWritesRouteToSource (t )
750
715
751
716
tstWorkflowSwitchReadsAndWrites (t )
752
- checkStates (t , wrangler . WorkflowStateNotSwitched , wrangler . WorkflowStateAllSwitched )
753
- validateReadsRouteToTarget (t , "replica, rdonly" )
717
+ validateReadsRouteToTarget (t , "replica" )
718
+ validateReadsRoute (t , "rdonly" , targetRdonlyTab1 )
754
719
validateWritesRouteToTarget (t )
755
720
waitForLowLag (t , keyspace , "wf1_reverse" )
756
721
tstWorkflowReverseReadsAndWrites (t )
757
- checkStates (t , wrangler . WorkflowStateAllSwitched , wrangler . WorkflowStateNotSwitched )
758
- validateReadsRouteToSource (t , "replica,rdonly " )
722
+ validateReadsRoute (t , "rdonly" , sourceRdonlyTab )
723
+ validateReadsRouteToSource (t , "replica" )
759
724
validateWritesRouteToSource (t )
760
725
761
726
// trying to complete an unswitched workflow should error
@@ -766,7 +731,8 @@ func testRestOfWorkflow(t *testing.T) {
766
731
// fully switch and complete
767
732
waitForLowLag (t , "customer" , "wf1" )
768
733
tstWorkflowSwitchReadsAndWrites (t )
769
- validateReadsRouteToTarget (t , "replica,rdonly" )
734
+ validateReadsRoute (t , "rdonly" , targetRdonlyTab1 )
735
+ validateReadsRouteToTarget (t , "replica" )
770
736
validateWritesRouteToTarget (t )
771
737
772
738
err = tstWorkflowComplete (t )
@@ -821,7 +787,7 @@ func setupMinimalCluster(t *testing.T) *VitessCluster {
821
787
822
788
zone1 := vc .Cells ["zone1" ]
823
789
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 )
825
791
826
792
verifyClusterHealth (t , vc )
827
793
insertInitialData (t )
@@ -834,7 +800,7 @@ func setupMinimalCluster(t *testing.T) *VitessCluster {
834
800
func setupMinimalCustomerKeyspace (t * testing.T ) map [string ]* cluster.VttabletProcess {
835
801
tablets := make (map [string ]* cluster.VttabletProcess )
836
802
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 {
838
804
t .Fatal (err )
839
805
}
840
806
defaultCell := vc .Cells [vc .CellNames [0 ]]
@@ -970,7 +936,6 @@ func createAdditionalCustomerShards(t *testing.T, shards string) {
970
936
targetTab2 = custKs .Shards ["80-c0" ].Tablets ["zone1-600" ].Vttablet
971
937
targetTab1 = custKs .Shards ["40-80" ].Tablets ["zone1-500" ].Vttablet
972
938
targetReplicaTab1 = custKs .Shards ["-40" ].Tablets ["zone1-401" ].Vttablet
973
- targetRdonlyTab1 = custKs .Shards ["-40" ].Tablets ["zone1-402" ].Vttablet
974
939
975
940
sourceTab = custKs .Shards ["-80" ].Tablets ["zone1-200" ].Vttablet
976
941
sourceReplicaTab = custKs .Shards ["-80" ].Tablets ["zone1-201" ].Vttablet
@@ -982,34 +947,3 @@ func tstApplySchemaOnlineDDL(t *testing.T, sql string, keyspace string) {
982
947
"--sql" , sql , keyspace )
983
948
require .NoError (t , err , fmt .Sprintf ("ApplySchema Error: %s" , err ))
984
949
}
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