Skip to content

Commit

Permalink
Fix data setup for reparentShardLocked cases, handle Before == ni…
Browse files Browse the repository at this point in the history
…l case

Signed-off-by: Andrew Mason <amason@slack-corp.com>
  • Loading branch information
ajm188 committed Feb 12, 2021
1 parent 53cdbfe commit 1ee9045
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/vt/vtctl/reparentutil/emergency_reparenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func TestEmergencyReparenter_reparentShardLocked(t *testing.T) {
Error: nil,
},
},
SetMasterResults: map[string]error{
"zone1-0000000100": nil,
"zone1-0000000101": nil,
},
StopReplicationAndGetStatusResults: map[string]struct {
Status *replicationdatapb.Status
StopStatus *replicationdatapb.StopReplicationStatus
Expand Down Expand Up @@ -240,6 +244,10 @@ func TestEmergencyReparenter_reparentShardLocked(t *testing.T) {
Error: nil,
},
},
SetMasterResults: map[string]error{
"zone1-0000000100": nil,
"zone1-0000000102": nil,
},
StopReplicationAndGetStatusResults: map[string]struct {
Status *replicationdatapb.Status
StopStatus *replicationdatapb.StopReplicationStatus
Expand Down
4 changes: 4 additions & 0 deletions go/vt/vtctl/reparentutil/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func FindValidEmergencyReparentCandidates(
// ReplicaWasRunning returns true if a StopReplicationStatus indicates that the
// replica had running replication threads before being stopped.
func ReplicaWasRunning(stopStatus *replicationdatapb.StopReplicationStatus) bool {
if stopStatus.Before == nil {
return false
}

return stopStatus.Before.IoThreadRunning || stopStatus.Before.SqlThreadRunning
}

Expand Down
7 changes: 7 additions & 0 deletions go/vt/vtctl/reparentutil/replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,13 @@ func TestReplicaWasRunning(t *testing.T) {
},
expected: false,
},
{
name: "status.Before is nil means we were not running",
in: &replicationdatapb.StopReplicationStatus{
Before: nil,
},
expected: false,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 1ee9045

Please sign in to comment.