Skip to content

Commit

Permalink
Fix unsafe recovery bug in 7.1
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Zhang <[email protected]>
  • Loading branch information
v01dstar authored and ti-chi-bot committed Jul 5, 2023
1 parent 086871d commit 877e455
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions server/cluster/unsafe_recovery_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,48 @@ func TestForceLeaderForCommitMerge(t *testing.T) {
re.Equal(demoteFailedVoter, recoveryController.GetStage())
}

// Failed learner replica/ store should be considered by auto-recover.
func TestAutoDetectModeWithOneLearner(t *testing.T) {

Check failure on line 558 in server/cluster/unsafe_recovery_controller_test.go

View workflow job for this annotation

GitHub Actions / statics

other declaration of TestAutoDetectModeWithOneLearner (typecheck)
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

_, opt, _ := newTestScheduleConfig()
cluster := newTestRaftCluster(ctx, mockid.NewIDAllocator(), opt, storage.NewStorageWithMemoryBackend(), core.NewBasicCluster())
cluster.coordinator = newCoordinator(ctx, cluster, hbstream.NewTestHeartbeatStreams(ctx, cluster.meta.GetId(), cluster, true))
cluster.coordinator.run()
for _, store := range newTestStores(1, "6.0.0") {
re.NoError(cluster.PutStore(store.GetMeta()))
}
recoveryController := newUnsafeRecoveryController(cluster)
re.NoError(recoveryController.RemoveFailedStores(nil, 60, true))

storeReport := pdpb.StoreReport{
PeerReports: []*pdpb.PeerReport{
{
RaftState: &raft_serverpb.RaftLocalState{LastIndex: 10, HardState: &eraftpb.HardState{Term: 1, Commit: 10}},
RegionState: &raft_serverpb.RegionLocalState{
Region: &metapb.Region{
Id: 1001,
RegionEpoch: &metapb.RegionEpoch{ConfVer: 7, Version: 10},
Peers: []*metapb.Peer{
{Id: 11, StoreId: 1}, {Id: 12, StoreId: 2}, {Id: 13, StoreId: 3, Role: metapb.PeerRole_Learner}}}}},
},
}
req := newStoreHeartbeat(1, &storeReport)
req.StoreReport.Step = 1
resp := &pdpb.StoreHeartbeatResponse{}
recoveryController.HandleStoreHeartbeat(req, resp)
hasStore3AsFailedStore := false
for _, failedStore := range resp.RecoveryPlan.ForceLeader.FailedStores {
if failedStore == 3 {
hasStore3AsFailedStore = true
break
}
}
re.True(hasStore3AsFailedStore)
}

func TestAutoDetectMode(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 877e455

Please sign in to comment.