From 8be3808bdadc3583ef9e6a0ea18f9bc190d24444 Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:40:28 -0400 Subject: [PATCH] Cherry-pick 2e47aba034e965cb7fddf0f70fd440105650f704 with conflicts --- go/test/endtoend/vreplication/migrate_test.go | 99 +++++++++++++++++++ .../resharding_workflows_v2_test.go | 27 +++-- 2 files changed, 120 insertions(+), 6 deletions(-) diff --git a/go/test/endtoend/vreplication/migrate_test.go b/go/test/endtoend/vreplication/migrate_test.go index 75ab6a3151b..e89f1b5501d 100644 --- a/go/test/endtoend/vreplication/migrate_test.go +++ b/go/test/endtoend/vreplication/migrate_test.go @@ -20,10 +20,14 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" "github.com/tidwall/gjson" +<<<<<<< HEAD "github.com/stretchr/testify/require" +======= +>>>>>>> 2e47aba034 (CI: Lower resources used for TestVtctldMigrateSharded (#16875)) "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/test/endtoend/cluster" @@ -53,10 +57,23 @@ func TestVtctlMigrate(t *testing.T) { allCellNames = "zone1" vc = NewVitessCluster(t, "TestMigrate", cells, mainClusterConfig) +<<<<<<< HEAD require.NotNil(t, vc, "failed to create VitessCluster") defaultReplicas = 0 defaultRdonly = 0 defer vc.TearDown(t) +======= + oldDefaultReplicas := defaultReplicas + oldDefaultRdonly := defaultRdonly + defaultReplicas = 0 + defaultRdonly = 0 + defer func() { + defaultReplicas = oldDefaultReplicas + defaultRdonly = oldDefaultRdonly + }() + + defer vc.TearDown() +>>>>>>> 2e47aba034 (CI: Lower resources used for TestVtctldMigrateSharded (#16875)) defaultCell = vc.Cells[defaultCellName] _, err := vc.AddKeyspace(t, []*Cell{defaultCell}, "product", "0", initialProductVSchema, initialProductSchema, defaultReplicas, defaultRdonly, 100, nil) @@ -314,3 +331,85 @@ func TestVtctldMigrate(t *testing.T) { require.Errorf(t, err, "there is no vitess cluster named ext1") }) } +<<<<<<< HEAD +======= + +// 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 TestVtctldMigrateSharded(t *testing.T) { + setSidecarDBName("_vt") + currentWorkflowType = binlogdatapb.VReplicationWorkflowType_MoveTables + oldDefaultReplicas := defaultReplicas + oldDefaultRdonly := defaultRdonly + defaultReplicas = 0 + defaultRdonly = 0 + defer func() { + defaultReplicas = oldDefaultReplicas + defaultRdonly = oldDefaultRdonly + }() + + vc = setupCluster(t) + defer vc.TearDown() + + vtgateConn := getConnection(t, vc.ClusterConfig.hostname, vc.ClusterConfig.vtgateMySQLPort) + defer vtgateConn.Close() + + setupCustomerKeyspace(t) + createMoveTablesWorkflow(t, "customer,Lead,datze,customer2") + tstWorkflowSwitchReadsAndWrites(t) + tstWorkflowComplete(t) + + var err error + // create external cluster + extCell := "extcell1" + extCells := []string{extCell} + extVc := NewVitessCluster(t, &clusterOptions{ + cells: extCells, + clusterConfig: externalClusterConfig, + }) + defer extVc.TearDown() + + setupExtKeyspace(t, extVc, "rating", extCell) + err = cluster.WaitForHealthyShard(extVc.VtctldClient, "rating", "-80") + require.NoError(t, err) + err = cluster.WaitForHealthyShard(extVc.VtctldClient, "rating", "80-") + require.NoError(t, err) + verifyClusterHealth(t, extVc) + extVtgateConn := getConnection(t, extVc.ClusterConfig.hostname, extVc.ClusterConfig.vtgateMySQLPort) + defer extVtgateConn.Close() + + currentWorkflowType = binlogdatapb.VReplicationWorkflowType_Migrate + 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 { + 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"); err != nil { + 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 + vc = extVc + doVtctldclientVDiff(t, "rating", "e1", "zone1", nil) +} + +func setupExtKeyspace(t *testing.T, vc *VitessCluster, ksName, cellName string) { + numReplicas := 1 + shards := []string{"-80", "80-"} + if _, err := vc.AddKeyspace(t, []*Cell{vc.Cells[cellName]}, ksName, strings.Join(shards, ","), + 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) + require.NoError(t, vtgate.WaitForStatusOfTabletInShard(fmt.Sprintf("%s.%s.replica", ksName, shard), numReplicas, waitTimeout)) + } +} +>>>>>>> 2e47aba034 (CI: Lower resources used for TestVtctldMigrateSharded (#16875)) diff --git a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go index 3135b2c6a33..af51a2e46d1 100644 --- a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go +++ b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go @@ -307,6 +307,9 @@ func tstWorkflowCancel(t *testing.T) error { } func validateReadsRoute(t *testing.T, tabletTypes string, tablet *cluster.VttabletProcess) { + if tablet == nil { + return + } if tabletTypes == "" { tabletTypes = "replica,rdonly" } @@ -319,11 +322,15 @@ func validateReadsRoute(t *testing.T, tabletTypes string, tablet *cluster.Vttabl } func validateReadsRouteToSource(t *testing.T, tabletTypes string) { - validateReadsRoute(t, tabletTypes, sourceReplicaTab) + if sourceReplicaTab != nil { + validateReadsRoute(t, tabletTypes, sourceReplicaTab) + } } func validateReadsRouteToTarget(t *testing.T, tabletTypes string) { - validateReadsRoute(t, tabletTypes, targetReplicaTab1) + if targetReplicaTab1 != nil { + validateReadsRoute(t, tabletTypes, targetReplicaTab1) + } } func validateWritesRouteToSource(t *testing.T) { @@ -732,8 +739,12 @@ func setupCluster(t *testing.T) *VitessCluster { insertInitialData(t) sourceTab = vc.Cells[defaultCell.Name].Keyspaces["product"].Shards["0"].Tablets["zone1-100"].Vttablet - sourceReplicaTab = vc.Cells[defaultCell.Name].Keyspaces["product"].Shards["0"].Tablets["zone1-101"].Vttablet - sourceRdonlyTab = vc.Cells[defaultCell.Name].Keyspaces["product"].Shards["0"].Tablets["zone1-102"].Vttablet + if defaultReplicas > 0 { + sourceReplicaTab = vc.Cells[defaultCell.Name].Keyspaces["product"].Shards["0"].Tablets["zone1-101"].Vttablet + } + if defaultRdonly > 0 { + sourceRdonlyTab = vc.Cells[defaultCell.Name].Keyspaces["product"].Shards["0"].Tablets["zone1-102"].Vttablet + } return vc } @@ -752,8 +763,12 @@ func setupCustomerKeyspace(t *testing.T) { custKs := vc.Cells[defaultCell.Name].Keyspaces["customer"] targetTab1 = custKs.Shards["-80"].Tablets["zone1-200"].Vttablet targetTab2 = custKs.Shards["80-"].Tablets["zone1-300"].Vttablet - targetReplicaTab1 = custKs.Shards["-80"].Tablets["zone1-201"].Vttablet - targetRdonlyTab1 = custKs.Shards["-80"].Tablets["zone1-202"].Vttablet + if defaultReplicas > 0 { + targetReplicaTab1 = custKs.Shards["-80"].Tablets["zone1-201"].Vttablet + } + if defaultRdonly > 0 { + targetRdonlyTab1 = custKs.Shards["-80"].Tablets["zone1-202"].Vttablet + } } func setupCustomer2Keyspace(t *testing.T) {