@@ -390,7 +390,8 @@ func TestMoveTables(t *testing.T) {
390
390
391
391
for _ , ftc := range targetShards {
392
392
addInvariants (ftc .vrdbClient , vreplID , sourceTabletUID , position , wf , tenv .cells [0 ])
393
-
393
+ getCopyStateQuery := fmt .Sprintf (sqlGetVReplicationCopyStatus , sidecar .GetIdentifier (), vreplID )
394
+ ftc .vrdbClient .AddInvariant (getCopyStateQuery , & sqltypes.Result {})
394
395
tenv .tmc .setVReplicationExecResults (ftc .tablet , getCopyState , & sqltypes.Result {})
395
396
ftc .vrdbClient .ExpectRequest (fmt .Sprintf (readAllWorkflows , tenv .dbName , "" ), & sqltypes.Result {}, nil )
396
397
insert := fmt .Sprintf (`%s values ('%s', 'keyspace:\"%s\" shard:\"%s\" filter:{rules:{match:\"t1\" filter:\"select * from t1 where in_keyrange(id, \'%s.hash\', \'%s\')\"}}', '', 0, 0, '%s', 'primary,replica,rdonly', now(), 0, 'Stopped', '%s', %d, 0, 0, '{}')` ,
@@ -574,6 +575,7 @@ func TestUpdateVReplicationWorkflow(t *testing.T) {
574
575
),
575
576
fmt .Sprintf ("%d|%s|%s|%s|Running|" , vreplID , blsStr , cells [0 ], tabletTypes [0 ]),
576
577
)
578
+
577
579
idQuery , err := sqlparser .ParseAndBind ("select id from _vt.vreplication where id = %a" ,
578
580
sqltypes .Int64BindVariable (int64 (vreplID )))
579
581
require .NoError (t , err )
@@ -585,10 +587,19 @@ func TestUpdateVReplicationWorkflow(t *testing.T) {
585
587
fmt .Sprintf ("%d" , vreplID ),
586
588
)
587
589
590
+ getCopyStateQuery := fmt .Sprintf (sqlGetVReplicationCopyStatus , sidecar .GetIdentifier (), int64 (vreplID ))
591
+ copyStatusFields := sqltypes .MakeTestFields (
592
+ "id" ,
593
+ "int64" ,
594
+ )
595
+ notCopying := sqltypes .MakeTestResult (copyStatusFields )
596
+ copying := sqltypes .MakeTestResult (copyStatusFields , "1" )
597
+
588
598
tests := []struct {
589
- name string
590
- request * tabletmanagerdatapb.UpdateVReplicationWorkflowRequest
591
- query string
599
+ name string
600
+ request * tabletmanagerdatapb.UpdateVReplicationWorkflowRequest
601
+ query string
602
+ isCopying bool
592
603
}{
593
604
{
594
605
name : "update cells" ,
@@ -668,6 +679,19 @@ func TestUpdateVReplicationWorkflow(t *testing.T) {
668
679
query : fmt .Sprintf (`update _vt.vreplication set state = '%s', source = 'keyspace:\"%s\" shard:\"%s\" filter:{rules:{match:\"corder\" filter:\"select * from corder\"} rules:{match:\"customer\" filter:\"select * from customer\"}}', cell = '%s', tablet_types = '%s' where id in (%d)` ,
669
680
binlogdatapb .VReplicationWorkflowState_Stopped .String (), keyspace , shard , cells [0 ], tabletTypes [0 ], vreplID ),
670
681
},
682
+ {
683
+ name : "update to running while copying" ,
684
+ request : & tabletmanagerdatapb.UpdateVReplicationWorkflowRequest {
685
+ Workflow : workflow ,
686
+ State : binlogdatapb .VReplicationWorkflowState_Running ,
687
+ Cells : textutil .SimulatedNullStringSlice ,
688
+ TabletTypes : []topodatapb.TabletType {topodatapb .TabletType (textutil .SimulatedNullInt )},
689
+ OnDdl : binlogdatapb .OnDDLAction (textutil .SimulatedNullInt ),
690
+ },
691
+ isCopying : true ,
692
+ query : fmt .Sprintf (`update _vt.vreplication set state = 'Copying', source = 'keyspace:\"%s\" shard:\"%s\" filter:{rules:{match:\"corder\" filter:\"select * from corder\"} rules:{match:\"customer\" filter:\"select * from customer\"}}', cell = '%s', tablet_types = '%s' where id in (%d)` ,
693
+ keyspace , shard , cells [0 ], tabletTypes [0 ], vreplID ),
694
+ },
671
695
}
672
696
673
697
for _ , tt := range tests {
@@ -686,12 +710,21 @@ func TestUpdateVReplicationWorkflow(t *testing.T) {
686
710
// These are the same for each RPC call.
687
711
tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (fmt .Sprintf ("use %s" , sidecar .GetIdentifier ()), & sqltypes.Result {}, nil )
688
712
tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (selectQuery , selectRes , nil )
689
- tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (fmt .Sprintf ("use %s" , sidecar .GetIdentifier ()), & sqltypes.Result {}, nil )
690
- tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (idQuery , idRes , nil )
713
+ if tt .request .State == binlogdatapb .VReplicationWorkflowState_Running ||
714
+ tt .request .State == binlogdatapb .VReplicationWorkflowState (textutil .SimulatedNullInt ) {
715
+ tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (fmt .Sprintf ("use %s" , sidecar .GetIdentifier ()), & sqltypes.Result {}, nil )
716
+ if tt .isCopying {
717
+ tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (getCopyStateQuery , copying , nil )
718
+ } else {
719
+ tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (getCopyStateQuery , notCopying , nil )
691
720
721
+ }
722
+ }
692
723
// This is our expected query, which will also short circuit
693
724
// the test with an error as at this point we've tested what
694
725
// we wanted to test.
726
+ tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (fmt .Sprintf ("use %s" , sidecar .GetIdentifier ()), & sqltypes.Result {}, nil )
727
+ tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (idQuery , idRes , nil )
695
728
tenv .tmc .tablets [tabletUID ].vrdbClient .ExpectRequest (tt .query , & sqltypes.Result {RowsAffected : 1 }, errShortCircuit )
696
729
_ , err = tenv .tmc .tablets [tabletUID ].tm .UpdateVReplicationWorkflow (ctx , tt .request )
697
730
tenv .tmc .tablets [tabletUID ].vrdbClient .Wait ()
0 commit comments