Skip to content

Commit 128198d

Browse files
committed
test(LookupVindex): Add tests for internalize and complete
Signed-off-by: Noble Mittal <noblemittal@outlook.com>
1 parent 7038c78 commit 128198d

File tree

6 files changed

+592
-7
lines changed

6 files changed

+592
-7
lines changed

go/test/endtoend/vreplication/lookup_vindex_helper_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ func (lv *lookupVindex) externalize() {
8686
lv.expectWriteOnly(false)
8787
}
8888

89+
func (lv *lookupVindex) internalize() {
90+
args := []string{
91+
"LookupVindex",
92+
"--name", lv.name,
93+
"--table-keyspace=" + lv.ownerTableKeyspace,
94+
"internalize",
95+
"--keyspace=" + lv.tableKeyspace,
96+
}
97+
err := vc.VtctldClient.ExecuteCommand(args...)
98+
require.NoError(lv.t, err, "error executing LookupVindex internalize: %v", err)
99+
lv.expectWriteOnly(true)
100+
}
101+
89102
func (lv *lookupVindex) show() error {
90103
return nil
91104
}

go/test/endtoend/vreplication/lookup_vindex_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type lookupTestCase struct {
8484
initQuery string
8585
runningQuery string
8686
postExternalizeQuery string
87+
postInternalizeQuery string
8788
cleanupQuery string
8889
}
8990

@@ -106,6 +107,7 @@ func TestLookupVindex(t *testing.T) {
106107
initQuery := "insert into t1 (c1, c2, val) values (1, 1, 'val1'), (2, 2, 'val2'), (3, 3, 'val3')"
107108
runningQuery := "insert into t1 (c1, c2, val) values (4, 4, 'val4'), (5, 5, 'val5'), (6, 6, 'val6')"
108109
postExternalizeQuery := "insert into t1 (c1, c2, val) values (7, 7, 'val7'), (8, 8, 'val8'), (9, 9, 'val9')"
110+
postInternalizeQuery := "insert into t1 (c1, c2, val) values (10, 10, 'val10'), (11, 11, 'val11'), (12, 12, 'val12')"
109111
cleanupQuery := "delete from t1"
110112

111113
testCases := []lookupTestCase{
@@ -158,6 +160,7 @@ func TestLookupVindex(t *testing.T) {
158160
tc.initQuery = initQuery
159161
tc.runningQuery = runningQuery
160162
tc.postExternalizeQuery = postExternalizeQuery
163+
tc.postInternalizeQuery = postInternalizeQuery
161164
tc.cleanupQuery = cleanupQuery
162165
testLookupVindex(t, &tc)
163166
})
@@ -196,6 +199,14 @@ func testLookupVindex(t *testing.T, tc *lookupTestCase) {
196199
waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, totalRows)
197200
})
198201

202+
t.Run("internalize", func(t *testing.T) {
203+
tc.lv.internalize()
204+
totalRows += getNumRowsInQuery(t, tc.postInternalizeQuery)
205+
_, err := vtgateConn.ExecuteFetch(tc.postInternalizeQuery, 1000, false)
206+
require.NoError(t, err)
207+
waitForRowCount(t, vtgateConn, tc.lv.ownerTableKeyspace, lv.name, totalRows)
208+
})
209+
199210
t.Run("cleanup", func(t *testing.T) {
200211
_, err := vtgateConn.ExecuteFetch(tc.cleanupQuery, 1000, false)
201212
require.NoError(t, err)

go/test/endtoend/vreplication/vreplication_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ func testVreplicationWorkflows(t *testing.T, limited bool, binlogRowImage string
417417
vdx = gjson.Get(customerVSchema, fmt.Sprintf("vindexes.%s", vindexName))
418418
require.NotNil(t, vdx, "lookup vindex %s not found", vindexName)
419419
require.NotEqual(t, "true", vdx.Get("params.write_only").String(), "did not expect write_only parameter to be true")
420+
421+
err = vc.VtctldClient.ExecuteCommand("LookupVindex", "--name", vindexName, "--table-keyspace=product", "internalize", "--keyspace=customer")
422+
require.NoError(t, err, "error executing LookupVindex internalize: %v", err)
423+
customerVSchema, err = vc.VtctldClient.ExecuteCommandWithOutput("GetVSchema", "customer")
424+
require.NoError(t, err, "error executing GetVSchema: %v", err)
425+
vdx = gjson.Get(customerVSchema, fmt.Sprintf("vindexes.%s", vindexName))
426+
require.NotNil(t, vdx, "lookup vindex %s not found", vindexName)
427+
require.Equal(t, "true", vdx.Get("params.write_only").String(), "expected write_only parameter to be true")
420428
})
421429
}
422430

go/vt/vtctl/workflow/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ const (
127127
lockTablesCycles = 2
128128
// Time to wait between LOCK TABLES cycles on the sources during SwitchWrites.
129129
lockTablesCycleDelay = time.Duration(100 * time.Millisecond)
130+
131+
SqlFreezeWorkflow = "update _vt.vreplication set message = '%s' where db_name=%s and workflow=%s"
132+
SqlUnfreezeWorkflow = "update _vt.vreplication set state='Running', message='' where db_name=%s and workflow=%s"
130133
)
131134

132135
var (
@@ -762,7 +765,7 @@ func (s *Server) LookupVindexExternalize(ctx context.Context, req *vtctldatapb.L
762765
return vterrors.Wrapf(err, "failed to stop workflow %s on shard %s/%s", req.Name, tabletInfo.Keyspace, tabletInfo.Shard)
763766
}
764767
// Mark workflow as frozen.
765-
query := fmt.Sprintf("update _vt.vreplication set message = '%s' where db_name=%s and workflow=%s", Frozen,
768+
query := fmt.Sprintf(SqlFreezeWorkflow, Frozen,
766769
encodeString(tabletInfo.DbName()), encodeString(req.Name))
767770
_, err = s.tmc.VReplicationExec(ctx, tabletInfo.Tablet, query)
768771
return err
@@ -849,7 +852,7 @@ func (s *Server) LookupVindexInternalize(ctx context.Context, req *vtctldatapb.L
849852
if err != nil {
850853
return err
851854
}
852-
query := fmt.Sprintf("update _vt.vreplication set state='Running', message='' where db_name=%s and workflow=%s",
855+
query := fmt.Sprintf(SqlUnfreezeWorkflow,
853856
encodeString(tabletInfo.DbName()), encodeString(req.Name))
854857
_, err = s.tmc.VReplicationExec(ctx, tabletInfo.Tablet, query)
855858
return err

go/vt/vttablet/tabletmanager/framework_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ type fakeTMClient struct {
399399
getSchemaCounts map[string]int
400400
// Used to confirm the number of times WorkflowDelete was called.
401401
workflowDeleteCalls int
402+
// Used to confirm the number of times UpdateVReplicationWorkflow with state as Stopped was called.
403+
workflowStopCalls int
402404
}
403405

404406
func newFakeTMClient() *fakeTMClient {
@@ -580,5 +582,8 @@ func (tmc *fakeTMClient) ReadVReplicationWorkflows(ctx context.Context, tablet *
580582
func (tmc *fakeTMClient) UpdateVReplicationWorkflow(ctx context.Context, tablet *topodatapb.Tablet, req *tabletmanagerdatapb.UpdateVReplicationWorkflowRequest) (*tabletmanagerdatapb.UpdateVReplicationWorkflowResponse, error) {
581583
tmc.mu.Lock()
582584
defer tmc.mu.Unlock()
585+
if *req.State == binlogdatapb.VReplicationWorkflowState_Stopped {
586+
tmc.workflowStopCalls++
587+
}
583588
return tmc.tablets[int(tablet.Alias.Uid)].tm.UpdateVReplicationWorkflow(ctx, req)
584589
}

0 commit comments

Comments
 (0)