From 983664de08a81fc53e39e3a7dad23f1ae9d08eaa Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 5 Jul 2023 14:44:48 +0530 Subject: [PATCH 1/2] feat: fix fakemysqldaemon to store the host and port after SetReplicationSource call Signed-off-by: Manan Gupta --- go/vt/mysqlctl/fakemysqldaemon.go | 8 ++++++++ go/vt/wrangler/testlib/backup_test.go | 12 ++++++------ .../wrangler/testlib/planned_reparent_shard_test.go | 5 ++--- go/vt/wrangler/testlib/reparent_utils_test.go | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/go/vt/mysqlctl/fakemysqldaemon.go b/go/vt/mysqlctl/fakemysqldaemon.go index 10877a4d6d1..c4f92101caf 100644 --- a/go/vt/mysqlctl/fakemysqldaemon.go +++ b/go/vt/mysqlctl/fakemysqldaemon.go @@ -118,6 +118,9 @@ type FakeMysqlDaemon struct { // SetReplicationSourceError is used by SetReplicationSource SetReplicationSourceError error + // StopReplicationError error is used by StopReplication + StopReplicationError error + // WaitPrimaryPositions is checked by WaitSourcePos, if the value is found // in it, then the function returns nil, else the function returns an error WaitPrimaryPositions []mysql.Position @@ -417,6 +420,9 @@ func (fmd *FakeMysqlDaemon) StartReplicationUntilAfter(ctx context.Context, pos // StopReplication is part of the MysqlDaemon interface. func (fmd *FakeMysqlDaemon) StopReplication(hookExtraEnv map[string]string) error { + if fmd.StopReplicationError != nil { + return fmd.StopReplicationError + } return fmd.ExecuteSuperQueryList(context.Background(), []string{ "STOP SLAVE", }) @@ -462,6 +468,8 @@ func (fmd *FakeMysqlDaemon) SetReplicationSource(ctx context.Context, host strin if startReplicationAfter { cmds = append(cmds, "START SLAVE") } + fmd.CurrentSourceHost = host + fmd.CurrentSourcePort = port return fmd.ExecuteSuperQueryList(ctx, cmds) } diff --git a/go/vt/wrangler/testlib/backup_test.go b/go/vt/wrangler/testlib/backup_test.go index f65ba2f6df3..65bd7ab62a1 100644 --- a/go/vt/wrangler/testlib/backup_test.go +++ b/go/vt/wrangler/testlib/backup_test.go @@ -185,9 +185,9 @@ func testBackupRestore(t *testing.T, cDetails *compressionDetails) error { "STOP SLAVE", "START SLAVE", // These commands come from SetReplicationSource RPC called - // to set the correct primary and semi-sync after Backup has concluded + // to set the correct primary and semi-sync after Backup has concluded. + // Since the primary hasn't changed, we only restart replication after fixing semi-sync. "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", } sourceTablet.FakeMysqlDaemon.FetchSuperQueryMap = map[string]*sqltypes.Result{ @@ -422,9 +422,9 @@ func TestBackupRestoreLagged(t *testing.T) { "STOP SLAVE", "START SLAVE", // These commands come from SetReplicationSource RPC called - // to set the correct primary and semi-sync after Backup has concluded + // to set the correct primary and semi-sync after Backup has concluded. + // Since the primary hasn't changed, we only restart replication after fixing semi-sync. "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", } sourceTablet.StartActionLoop(t, wr) @@ -639,9 +639,9 @@ func TestRestoreUnreachablePrimary(t *testing.T) { "STOP SLAVE", "START SLAVE", // These commands come from SetReplicationSource RPC called - // to set the correct primary and semi-sync after Backup has concluded + // to set the correct primary and semi-sync after Backup has concluded. + // Since the primary hasn't changed, we only restart replication after fixing semi-sync. "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", } sourceTablet.StartActionLoop(t, wr) diff --git a/go/vt/wrangler/testlib/planned_reparent_shard_test.go b/go/vt/wrangler/testlib/planned_reparent_shard_test.go index 010c1dc2301..b77dc4b5afe 100644 --- a/go/vt/wrangler/testlib/planned_reparent_shard_test.go +++ b/go/vt/wrangler/testlib/planned_reparent_shard_test.go @@ -625,9 +625,10 @@ func TestPlannedReparentShardRelayLogError(t *testing.T) { "STOP SLAVE", "RESET SLAVE", "START SLAVE", + "START SLAVE", } goodReplica1.StartActionLoop(t, wr) - goodReplica1.FakeMysqlDaemon.SetReplicationSourceError = errors.New("Slave failed to initialize relay log info structure from the repository") + goodReplica1.FakeMysqlDaemon.StopReplicationError = errors.New("Slave failed to initialize relay log info structure from the repository") defer goodReplica1.StopActionLoop(t) // run PlannedReparentShard @@ -850,7 +851,6 @@ func TestPlannedReparentShardPromoteReplicaFail(t *testing.T) { "START SLAVE", // extra commands because of retry "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", "SUBINSERT INTO _vt.reparent_journal (time_created_ns, action_name, primary_alias, replication_position) VALUES", } @@ -921,7 +921,6 @@ func TestPlannedReparentShardSamePrimary(t *testing.T) { "FAKE SET MASTER", "START SLAVE", "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", } goodReplica1.StartActionLoop(t, wr) diff --git a/go/vt/wrangler/testlib/reparent_utils_test.go b/go/vt/wrangler/testlib/reparent_utils_test.go index 6cb67714411..c375e078253 100644 --- a/go/vt/wrangler/testlib/reparent_utils_test.go +++ b/go/vt/wrangler/testlib/reparent_utils_test.go @@ -167,7 +167,6 @@ func TestReparentTablet(t *testing.T) { "FAKE SET MASTER", "START SLAVE", "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", } replica.StartActionLoop(t, wr) @@ -226,6 +225,7 @@ func TestSetReplicationSource(t *testing.T) { "START SLAVE", // We stop and reset the replication parameters because of relay log issues. "STOP SLAVE", + "STOP SLAVE", "RESET SLAVE", "START SLAVE", } @@ -233,7 +233,7 @@ func TestSetReplicationSource(t *testing.T) { defer replica.StopActionLoop(t) // Set the correct error message that indicates we have received a relay log error. - replica.FakeMysqlDaemon.SetReplicationSourceError = errors.New("ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log") + replica.FakeMysqlDaemon.StartReplicationError = errors.New("ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log") // run ReparentTablet err = wr.SetReplicationSource(ctx, replica.Tablet) require.NoError(t, err, "SetReplicationSource failed") From 66a13e9fbf2dfe5e34d0644ceb893827333e7127 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 6 Jul 2023 11:21:41 +0530 Subject: [PATCH 2/2] feat: fix tests Signed-off-by: Manan Gupta --- .../testlib/planned_reparent_shard_test.go | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/go/vt/wrangler/testlib/planned_reparent_shard_test.go b/go/vt/wrangler/testlib/planned_reparent_shard_test.go index 96b9f560ebe..ecdf716a361 100644 --- a/go/vt/wrangler/testlib/planned_reparent_shard_test.go +++ b/go/vt/wrangler/testlib/planned_reparent_shard_test.go @@ -826,7 +826,6 @@ func TestPlannedReparentShardPromoteReplicaFail(t *testing.T) { "START SLAVE", // extra SetReplicationSource call due to retry "STOP SLAVE", - "FAKE SET MASTER", "START SLAVE", } goodReplica1.StartActionLoop(t, wr) @@ -841,8 +840,6 @@ func TestPlannedReparentShardPromoteReplicaFail(t *testing.T) { "FAKE SET MASTER", "START SLAVE", "FAKE SET MASTER", - // extra SetReplicationSource call due to retry - "FAKE SET MASTER", } goodReplica2.StartActionLoop(t, wr) goodReplica2.FakeMysqlDaemon.Replicating = false @@ -861,22 +858,6 @@ func TestPlannedReparentShardPromoteReplicaFail(t *testing.T) { // retrying should work newPrimary.FakeMysqlDaemon.PromoteError = nil newPrimary.FakeMysqlDaemon.CurrentPrimaryPosition = newPrimary.FakeMysqlDaemon.WaitPrimaryPositions[0] - newPrimary.FakeMysqlDaemon.ExpectedExecuteSuperQueryList = []string{ - "STOP SLAVE", - "FAKE SET MASTER", - "START SLAVE", - // extra commands because of retry - "STOP SLAVE", - "START SLAVE", - "SUBINSERT INTO _vt.reparent_journal (time_created_ns, action_name, primary_alias, replication_position) VALUES", - } - oldPrimary.FakeMysqlDaemon.ExpectedExecuteSuperQueryList = []string{ - "FAKE SET MASTER", - "START SLAVE", - // extra commands because of retry - "FAKE SET MASTER", - "START SLAVE", - } // run PlannedReparentShard err = vp.Run([]string{"PlannedReparentShard", "--wait_replicas_timeout", "10s", "--keyspace_shard", newPrimary.Tablet.Keyspace + "/" + newPrimary.Tablet.Shard, "--new_primary", topoproto.TabletAliasString(newPrimary.Tablet.Alias)})