From 7f7f0d6f06a5f54f0711308b09c320554c5433c9 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 | 96 +++++++++++++++++++ .../resharding_workflows_v2_test.go | 27 ++++-- 2 files changed, 117 insertions(+), 6 deletions(-) diff --git a/go/test/endtoend/vreplication/migrate_test.go b/go/test/endtoend/vreplication/migrate_test.go index 5d927054000..4a389f3d90e 100644 --- a/go/test/endtoend/vreplication/migrate_test.go +++ b/go/test/endtoend/vreplication/migrate_test.go @@ -20,11 +20,18 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" "github.com/tidwall/gjson" +<<<<<<< HEAD "github.com/stretchr/testify/require" "vitess.io/vitess/go/mysql" +======= + "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/test/endtoend/cluster" + +>>>>>>> 2e47aba034 (CI: Lower resources used for TestVtctldMigrateSharded (#16875)) binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" ) @@ -48,8 +55,15 @@ func insertInitialDataIntoExternalCluster(t *testing.T, conn *mysql.Conn) { func TestVtctlMigrate(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]] @@ -297,3 +311,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 0f3f85a9472..ec7b515fcdc 100644 --- a/go/test/endtoend/vreplication/resharding_workflows_v2_test.go +++ b/go/test/endtoend/vreplication/resharding_workflows_v2_test.go @@ -327,6 +327,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" } @@ -342,11 +345,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) { @@ -752,8 +759,12 @@ func setupCluster(t *testing.T) *VitessCluster { insertInitialData(t) defaultCell := vc.Cells[vc.CellNames[0]] 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 } @@ -767,8 +778,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) {