Skip to content

Commit

Permalink
Fix Fakemysqldaemon to store the host and port after `SetReplicatio…
Browse files Browse the repository at this point in the history
…nSource` call (vitessio#13439)

* feat: fix fakemysqldaemon to store the host and port after SetReplicationSource call

Signed-off-by: Manan Gupta <manan@planetscale.com>

* feat: fix tests

Signed-off-by: Manan Gupta <manan@planetscale.com>

---------

Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Jul 6, 2023
1 parent 1518cc1 commit a7903d1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 8 additions & 0 deletions go/vt/mysqlctl/fakemysqldaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
})
Expand Down Expand Up @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions go/vt/wrangler/testlib/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions go/vt/wrangler/testlib/planned_reparent_shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions go/vt/wrangler/testlib/reparent_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -226,14 +225,15 @@ 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",
}
replica.StartActionLoop(t, wr)
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")
Expand Down

0 comments on commit a7903d1

Please sign in to comment.