Skip to content

Commit

Permalink
Address Review Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps committed Sep 20, 2024
1 parent 04684af commit e6a3989
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions go/test/endtoend/vreplication/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ func TestVtctlMigrate(t *testing.T) {
func TestVtctldMigrateUnsharded(t *testing.T) {
vc = NewVitessCluster(t, nil)

oldDefaultReplicas := defaultReplicas
oldDefaultRdonly := defaultRdonly
defaultReplicas = 0
defaultRdonly = 0
defer func() {
defaultReplicas = oldDefaultReplicas
defaultRdonly = oldDefaultRdonly
}()

defer vc.TearDown()

defaultCell := vc.Cells[vc.CellNames[0]]
Expand Down Expand Up @@ -303,12 +310,20 @@ func TestVtctldMigrateUnsharded(t *testing.T) {
})
}

// TestShardedMigrate adds a test for a sharded cluster to validate a fix for a bug where the target keyspace name
// TestVtctldMigrate adds a test for a sharded cluster to validate a fix for a bug where the target keyspace name
// doesn't match that of the source cluster. The test migrates from a cluster with keyspace customer to an "external"
// cluster with keyspace rating.
func TestMigrateSharded(t *testing.T) {
setSidecarDBName("_vt")
func TestVtctldMigrateSharded(t *testing.T) {
oldDefaultReplicas := defaultReplicas
oldDefaultRdonly := defaultRdonly
defaultReplicas = 1
defaultRdonly = 1
defer func() {
defaultReplicas = oldDefaultReplicas
defaultRdonly = oldDefaultRdonly
}()

setSidecarDBName("_vt")
currentWorkflowType = binlogdatapb.VReplicationWorkflowType_MoveTables
vc = setupCluster(t)
vtgateConn := getConnection(t, vc.ClusterConfig.hostname, vc.ClusterConfig.vtgateMySQLPort)
Expand Down Expand Up @@ -342,14 +357,14 @@ func TestMigrateSharded(t *testing.T) {
var output string
if output, err = extVc.VtctldClient.ExecuteCommandWithOutput("Mount", "register", "--name=external", "--topo-type=etcd2",
fmt.Sprintf("--topo-server=localhost:%d", vc.ClusterConfig.topoPort), "--topo-root=/vitess/global"); err != nil {
t.Fatalf("Mount command failed with %+v : %s\n", err, output)
require.FailNow(t, "Mount command failed with %+v : %s\n", err, output)
}
ksWorkflow := "rating.e1"
if output, err = extVc.VtctldClient.ExecuteCommandWithOutput("Migrate",
"--target-keyspace", "rating", "--workflow", "e1",
"create", "--source-keyspace", "customer", "--mount-name", "external", "--all-tables", "--cells=zone1",
"--tablet-types=primary,replica"); err != nil {
t.Fatalf("Migrate command failed with %+v : %s\n", err, output)
require.FailNow(t, "Migrate command failed with %+v : %s\n", err, output)
}
waitForWorkflowState(t, extVc, ksWorkflow, binlogdatapb.VReplicationWorkflowState_Running.String())
// this is because currently doVtctldclientVDiff is using the global vc :-( and we want to run a diff on the extVc cluster
Expand All @@ -358,21 +373,16 @@ func TestMigrateSharded(t *testing.T) {
}

func setupExtKeyspace(t *testing.T, vc *VitessCluster, ksName, cellName string) {
rdonly := 0
numReplicas := 1
shards := []string{"-80", "80-"}
if _, err := vc.AddKeyspace(t, []*Cell{vc.Cells[cellName]}, ksName, strings.Join(shards, ","),
customerVSchema, customerSchema, defaultReplicas, rdonly, 1200, nil); err != nil {
customerVSchema, customerSchema, numReplicas, 0, 1200, nil); err != nil {
t.Fatal(err)
}
vtgate := vc.Cells[cellName].Vtgates[0]
for _, shard := range shards {
err := cluster.WaitForHealthyShard(vc.VtctldClient, ksName, shard)
require.NoError(t, err)
if defaultReplicas > 0 {
require.NoError(t, vtgate.WaitForStatusOfTabletInShard(fmt.Sprintf("%s.%s.replica", ksName, shard), defaultReplicas, waitTimeout))
}
if rdonly > 0 {
require.NoError(t, vtgate.WaitForStatusOfTabletInShard(fmt.Sprintf("%s.%s.rdonly", ksName, shard), defaultRdonly, waitTimeout))
}
require.NoError(t, vtgate.WaitForStatusOfTabletInShard(fmt.Sprintf("%s.%s.replica", ksName, shard), numReplicas, waitTimeout))
}
}

0 comments on commit e6a3989

Please sign in to comment.