Skip to content

Commit

Permalink
Migrate side-by-side from v1/v2 to vtctlclient/vtctldclient
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Sep 20, 2023
1 parent 342e2b9 commit 0810146
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 100 deletions.
2 changes: 1 addition & 1 deletion go/test/endtoend/vreplication/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestMigrate(t *testing.T) {
execVtgateQuery(t, extVtgateConn, "rating", "insert into rating(gid, pid, rating) values(3, 1, 3);")
waitForRowCount(t, vtgateConn, "product:0", "rating", 3)
waitForRowCount(t, vtgateConn, "product:0", "review", 4)
vdiff1(t, ksWorkflow, "extcell1")
vdiffSideBySide(t, ksWorkflow, "extcell1")

if output, err = vc.VtctlClient.ExecuteCommandWithOutput("Migrate", "complete", ksWorkflow); err != nil {
t.Fatalf("Migrate command failed with %+v : %s\n", err, output)
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vreplication/movetables_buffering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestMoveTablesBuffering(t *testing.T) {

catchup(t, targetTab1, workflowName, "MoveTables")
catchup(t, targetTab2, workflowName, "MoveTables")
vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")
waitForLowLag(t, "customer", workflowName)
tstWorkflowSwitchReads(t, "", "")
tstWorkflowSwitchWrites(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (wf *workflow) create() {
catchup(t, tab, wf.name, wf.typ)
i += 100
}
doVdiff2(t, wf.toKeyspace, wf.name, cell, nil)
doVtctldclientVDiff(t, wf.toKeyspace, wf.name, cell, nil)

}

Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/vreplication/partial_movetables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestPartialMoveTablesBasic(t *testing.T) {

targetTab1 = vc.getPrimaryTablet(t, targetKs, shard)
catchup(t, targetTab1, wfName, "Partial MoveTables Customer to Customer2")
vdiff1(t, ksWf, "")
vdiffSideBySide(t, ksWf, "")

waitForRowCount(t, vtgateConn, "customer", "customer", 3) // customer: all shards
waitForRowCount(t, vtgateConn, "customer2", "customer", 3) // customer2: all shards
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestPartialMoveTablesBasic(t *testing.T) {
require.NoError(t, err)
targetTab2 := vc.getPrimaryTablet(t, targetKs, shard)
catchup(t, targetTab2, wfName, "Partial MoveTables Customer to Customer2: -80")
vdiff1(t, ksWf, "")
vdiffSideBySide(t, ksWf, "")

// Switch all traffic for the shard
require.NoError(t, tstWorkflowExec(t, "", wfName, "", targetKs, "", workflowActionSwitchTraffic, "", "", "", false))
Expand Down
10 changes: 5 additions & 5 deletions go/test/endtoend/vreplication/resharding_workflows_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func createReshardWorkflow(t *testing.T, sourceShards, targetShards string) erro
confirmTablesHaveSecondaryKeys(t, []*cluster.VttabletProcess{targetTab1}, targetKs, "")
catchup(t, targetTab1, workflowName, "Reshard")
catchup(t, targetTab2, workflowName, "Reshard")
vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")
return nil
}

Expand All @@ -84,7 +84,7 @@ func createMoveTablesWorkflow(t *testing.T, tables string) {
confirmTablesHaveSecondaryKeys(t, []*cluster.VttabletProcess{targetTab1}, targetKs, tables)
catchup(t, targetTab1, workflowName, "MoveTables")
catchup(t, targetTab2, workflowName, "MoveTables")
vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")
}

func tstWorkflowAction(t *testing.T, action, tabletTypes, cells string) error {
Expand Down Expand Up @@ -399,10 +399,10 @@ func testReplicatingWithPKEnumCols(t *testing.T) {
insertQuery := "insert into customer(cid, name, typ, sport, meta) values(2, 'Paül','soho','cricket',convert(x'7b7d' using utf8mb4))"
execVtgateQuery(t, vtgateConn, sourceKs, deleteQuery)
waitForNoWorkflowLag(t, vc, targetKs, workflowName)
vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")
execVtgateQuery(t, vtgateConn, sourceKs, insertQuery)
waitForNoWorkflowLag(t, vc, targetKs, workflowName)
vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")
}

func testReshardV2Workflow(t *testing.T) {
Expand Down Expand Up @@ -733,7 +733,7 @@ func moveCustomerTableSwitchFlows(t *testing.T, cells []*Cell, sourceCellOrAlias
moveTablesAction(t, "Create", sourceCellOrAlias, workflow, sourceKs, targetKs, tables)
catchup(t, targetTab1, workflow, workflowType)
catchup(t, targetTab2, workflow, workflowType)
vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")
}

var switchReadsFollowedBySwitchWrites = func() {
Expand Down
8 changes: 4 additions & 4 deletions go/test/endtoend/vreplication/time_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func TestMoveTablesTZ(t *testing.T) {
_, err = vtgateConn.ExecuteFetch("insert into datze(id, dt2) values (12, '2022-04-01 5:06:07')", 1, false) // dst
require.NoError(t, err)

vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")

// update to test date conversions in replication (vplayer) mode (update statements)
_, err = vtgateConn.ExecuteFetch("update datze set dt2 = '2022-04-01 5:06:07' where id = 11", 1, false) // dst
require.NoError(t, err)
_, err = vtgateConn.ExecuteFetch("update datze set dt2 = '2022-01-01 10:20:30' where id = 12", 1, false) // standard time
require.NoError(t, err)

vdiff1(t, ksWorkflow, "")
vdiffSideBySide(t, ksWorkflow, "")

query := "select * from datze"
qrSourceUSPacific, err := productTab.QueryTablet(query, sourceKs, true)
Expand All @@ -154,7 +154,7 @@ func TestMoveTablesTZ(t *testing.T) {
require.NotEqual(t, row.AsString("ts1", ""), qrTargetUTC.Named().Rows[i].AsString("ts1", ""))

dtLayout := "2006-01-02 15:04:05"
// now compare times b/w source and target (actual). VDiff has already compared, but we want to validate that vdiff1 is right too!
// now compare times b/w source and target (actual). VDiff has already compared, but we want to validate that vdiffSideBySide is right too!
dt2a, err := time.Parse(dtLayout, qrTargetUTC.Named().Rows[i].AsString("dt2", ""))
require.NoError(t, err)
targetUTCTUnix := dt2a.Unix()
Expand Down Expand Up @@ -206,5 +206,5 @@ func TestMoveTablesTZ(t *testing.T) {
// inserts to test date conversions in reverse replication
execVtgateQuery(t, vtgateConn, "customer", "insert into datze(id, dt2) values (13, '2022-01-01 18:20:30')")
execVtgateQuery(t, vtgateConn, "customer", "insert into datze(id, dt2) values (14, '2022-04-01 12:06:07')")
vdiff1(t, ksReverseWorkflow, "")
vdiffSideBySide(t, ksReverseWorkflow, "")
}
50 changes: 25 additions & 25 deletions go/test/endtoend/vreplication/vdiff2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ func testWorkflow(t *testing.T, vc *VitessCluster, tc *testCase, cells []*Cell)

// create another VDiff record to confirm it gets deleted when the workflow is completed
ts := time.Now()
uuid, _ := performVDiff2Action(t, ksWorkflow, allCellNames, "create", "", false)
waitForVDiff2ToComplete(t, ksWorkflow, allCellNames, uuid, ts)
uuid, _ := performVDiff2Action(t, false, ksWorkflow, allCellNames, "create", "", false)
waitForVDiff2ToComplete(t, false, ksWorkflow, allCellNames, uuid, ts)

err = vc.VtctlClient.ExecuteCommand(tc.typ, "--", "SwitchTraffic", ksWorkflow)
require.NoError(t, err)
Expand All @@ -219,16 +219,16 @@ func testWorkflow(t *testing.T, vc *VitessCluster, tc *testCase, cells []*Cell)

func testCLIErrors(t *testing.T, ksWorkflow, cells string) {
t.Run("Client error handling", func(t *testing.T) {
_, output := performVDiff2Action(t, ksWorkflow, cells, "badcmd", "", true)
_, output := performVDiff2Action(t, false, ksWorkflow, cells, "badcmd", "", true)
require.Contains(t, output, "Usage:")
_, output = performVDiff2Action(t, ksWorkflow, cells, "create", "invalid_uuid", true)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "create", "invalid_uuid", true)
require.Contains(t, output, "invalid UUID provided")
_, output = performVDiff2Action(t, ksWorkflow, cells, "resume", "invalid_uuid", true)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "resume", "invalid_uuid", true)
require.Contains(t, output, "invalid UUID provided")
_, output = performVDiff2Action(t, ksWorkflow, cells, "delete", "invalid_uuid", true)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "delete", "invalid_uuid", true)
require.Contains(t, output, "invalid UUID provided")
uuid, _ := performVDiff2Action(t, ksWorkflow, cells, "show", "last", false)
_, output = performVDiff2Action(t, ksWorkflow, cells, "create", uuid, true)
uuid, _ := performVDiff2Action(t, false, ksWorkflow, cells, "show", "last", false)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "create", uuid, true)
require.Contains(t, output, "already exists")
})
}
Expand All @@ -246,35 +246,35 @@ func testDelete(t *testing.T, ksWorkflow, cells string) {
}
return int64(len(seen))
}
_, output := performVDiff2Action(t, ksWorkflow, cells, "show", "all", false)
_, output := performVDiff2Action(t, false, ksWorkflow, cells, "show", "all", false)
initialVDiffCount := uuidCount(gjson.Get(output, "#.UUID").Array())
for ; initialVDiffCount < 3; initialVDiffCount++ {
_, _ = performVDiff2Action(t, ksWorkflow, cells, "create", "", false)
_, _ = performVDiff2Action(t, false, ksWorkflow, cells, "create", "", false)
}

// Now let's confirm that we have at least 3 unique VDiffs.
_, output = performVDiff2Action(t, ksWorkflow, cells, "show", "all", false)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "show", "all", false)
require.GreaterOrEqual(t, uuidCount(gjson.Get(output, "#.UUID").Array()), int64(3))
// And that our initial count is what we expect.
require.Equal(t, initialVDiffCount, uuidCount(gjson.Get(output, "#.UUID").Array()))

// Test show last with verbose too as a side effect.
uuid, output := performVDiff2Action(t, ksWorkflow, cells, "show", "last", false, "--verbose")
uuid, output := performVDiff2Action(t, false, ksWorkflow, cells, "show", "last", false, "--verbose")
// The TableSummary is only present with --verbose.
require.Contains(t, output, `"TableSummary":`)

// Now let's delete one of the VDiffs.
_, output = performVDiff2Action(t, ksWorkflow, cells, "delete", uuid, false)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "delete", uuid, false)
require.Equal(t, "completed", gjson.Get(output, "Status").String())
// And confirm that our unique VDiff count has only decreased by one.
_, output = performVDiff2Action(t, ksWorkflow, cells, "show", "all", false)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "show", "all", false)
require.Equal(t, initialVDiffCount-1, uuidCount(gjson.Get(output, "#.UUID").Array()))

// Now let's delete all of them.
_, output = performVDiff2Action(t, ksWorkflow, cells, "delete", "all", false)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "delete", "all", false)
require.Equal(t, "completed", gjson.Get(output, "Status").String())
// And finally confirm that we have no more VDiffs.
_, output = performVDiff2Action(t, ksWorkflow, cells, "show", "all", false)
_, output = performVDiff2Action(t, false, ksWorkflow, cells, "show", "all", false)
require.Equal(t, int64(0), gjson.Get(output, "#").Int())
})
}
Expand All @@ -296,7 +296,7 @@ func testResume(t *testing.T, tc *testCase, cells string) {
ksWorkflow := fmt.Sprintf("%s.%s", tc.targetKs, tc.workflow)

// confirm the last VDiff is in the expected completed state
uuid, output := performVDiff2Action(t, ksWorkflow, cells, "show", "last", false)
uuid, output := performVDiff2Action(t, false, ksWorkflow, cells, "show", "last", false)
jsonOutput := getVDiffInfo(output)
require.Equal(t, "completed", jsonOutput.State)
// save the number of rows compared in previous runs
Expand All @@ -312,8 +312,8 @@ func testResume(t *testing.T, tc *testCase, cells string) {

// confirm that the VDiff was resumed, able to complete, and we compared the
// expected number of rows in total (original run and resume)
_, _ = performVDiff2Action(t, ksWorkflow, cells, "resume", uuid, false)
info := waitForVDiff2ToComplete(t, ksWorkflow, cells, uuid, ogTime)
_, _ = performVDiff2Action(t, false, ksWorkflow, cells, "resume", uuid, false)
info := waitForVDiff2ToComplete(t, false, ksWorkflow, cells, uuid, ogTime)
require.False(t, info.HasMismatch)
require.Equal(t, expectedRows, info.RowsCompared)
})
Expand All @@ -322,10 +322,10 @@ func testResume(t *testing.T, tc *testCase, cells string) {
func testStop(t *testing.T, ksWorkflow, cells string) {
t.Run("Stop", func(t *testing.T) {
// create a new VDiff and immediately stop it
uuid, _ := performVDiff2Action(t, ksWorkflow, cells, "create", "", false)
_, _ = performVDiff2Action(t, ksWorkflow, cells, "stop", uuid, false)
uuid, _ := performVDiff2Action(t, false, ksWorkflow, cells, "create", "", false)
_, _ = performVDiff2Action(t, false, ksWorkflow, cells, "stop", uuid, false)
// confirm the VDiff is in the expected stopped state
_, output := performVDiff2Action(t, ksWorkflow, cells, "show", uuid, false)
_, output := performVDiff2Action(t, false, ksWorkflow, cells, "show", uuid, false)
jsonOutput := getVDiffInfo(output)
require.Equal(t, "stopped", jsonOutput.State)
// confirm that the context cancelled error was also cleared
Expand All @@ -338,7 +338,7 @@ func testAutoRetryError(t *testing.T, tc *testCase, cells string) {
ksWorkflow := fmt.Sprintf("%s.%s", tc.targetKs, tc.workflow)

// confirm the last VDiff is in the expected completed state
uuid, output := performVDiff2Action(t, ksWorkflow, cells, "show", "last", false)
uuid, output := performVDiff2Action(t, false, ksWorkflow, cells, "show", "last", false)
jsonOutput := getVDiffInfo(output)
require.Equal(t, "completed", jsonOutput.State)
// save the number of rows compared in the first run
Expand All @@ -365,7 +365,7 @@ func testAutoRetryError(t *testing.T, tc *testCase, cells string) {

// confirm that the VDiff was retried, able to complete, and we compared the expected
// number of rows in total (original run and retry)
info := waitForVDiff2ToComplete(t, ksWorkflow, cells, uuid, ogTime)
info := waitForVDiff2ToComplete(t, false, ksWorkflow, cells, uuid, ogTime)
require.False(t, info.HasMismatch)
require.Equal(t, expectedRows, info.RowsCompared)
})
Expand All @@ -375,7 +375,7 @@ func testCLICreateWait(t *testing.T, ksWorkflow string, cells string) {
t.Run("vtctl create and wait", func(t *testing.T) {
chCompleted := make(chan bool)
go func() {
_, output := performVDiff2Action(t, ksWorkflow, cells, "create", "", false, "--wait", "--wait-update-interval=1s")
_, output := performVDiff2Action(t, false, ksWorkflow, cells, "create", "", false, "--wait", "--wait-update-interval=1s")
completed := false
// We don't try to parse the JSON output as it may contain a series of outputs
// that together do not form a valid JSON document. We can change this in the
Expand Down
Loading

0 comments on commit 0810146

Please sign in to comment.