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 80a067f221a..ecdf716a361 100644 --- a/go/vt/wrangler/testlib/planned_reparent_shard_test.go +++ b/go/vt/wrangler/testlib/planned_reparent_shard_test.go @@ -631,9 +631,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 @@ -825,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) @@ -840,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 @@ -920,7 +918,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")