Skip to content

Commit

Permalink
This is an automated cherry-pick of tikv#6691
Browse files Browse the repository at this point in the history
ref tikv#6683, close tikv#6690

Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
v01dstar authored and ti-chi-bot committed Jun 29, 2023
1 parent 8c09be1 commit feafae5
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/cluster/unsafe_recovery_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,14 @@ func (u *unsafeRecoveryController) getFailedPeers(region *metapb.Region) []*meta

var failedPeers []*metapb.Peer
for _, peer := range region.Peers {
<<<<<<< HEAD:server/cluster/unsafe_recovery_controller.go

Check failure on line 690 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected <<, expecting }
if peer.Role == metapb.PeerRole_Learner || peer.Role == metapb.PeerRole_DemotingVoter {

Check failure on line 691 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected if, expecting expression

Check failure on line 691 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

expression in go must be function call
continue
}
if _, ok := u.failedStores[peer.StoreId]; ok {
=======

Check failure on line 695 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected ==, expecting }
if u.isFailed(peer) {
>>>>>>> 610aee7db (unsafe recovery: Fix learner nodes got ignored in auto detect mode error (#6691)):pkg/unsaferecovery/unsafe_recovery_controller.go

Check failure on line 697 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected >>, expecting }

Check failure on line 697 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

invalid character U+0023 '#'
failedPeers = append(failedPeers, peer)

Check failure on line 698 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

expression in go must be function call

Check failure on line 698 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: unexpected = at end of statement
}
}

Check failure on line 700 in server/cluster/unsafe_recovery_controller.go

View workflow job for this annotation

GitHub Actions / statics

syntax error: non-declaration statement outside function body
Expand Down
106 changes: 106 additions & 0 deletions server/cluster/unsafe_recovery_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,117 @@ func (s *testUnsafeRecoverySuite) TestForceLeaderForCommitMerge(c *C) {
c.Assert(recoveryController.GetStage(), Equals, demoteFailedVoter)
}

<<<<<<< HEAD:server/cluster/unsafe_recovery_controller_test.go
func (s *testUnsafeRecoverySuite) TestOneLearner(c *C) {
_, opt, _ := newTestScheduleConfig()
cluster := newTestRaftCluster(s.ctx, mockid.NewIDAllocator(), opt, storage.NewStorageWithMemoryBackend(), core.NewBasicCluster())
cluster.coordinator = newCoordinator(s.ctx, cluster, hbstream.NewTestHeartbeatStreams(s.ctx, cluster.meta.GetId(), cluster, true))
cluster.coordinator.run()
=======
func TestAutoDetectMode(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

opts := mockconfig.NewTestOptions()
cluster := mockcluster.NewCluster(ctx, opts)
coordinator := schedule.NewCoordinator(ctx, cluster, hbstream.NewTestHeartbeatStreams(ctx, cluster.ID, cluster, true))
coordinator.Run()
for _, store := range newTestStores(1, "6.0.0") {
cluster.PutStore(store)
}
recoveryController := NewController(cluster)
re.NoError(recoveryController.RemoveFailedStores(nil, 60, true))

reports := map[uint64]*pdpb.StoreReport{
1: {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}}}}},
}},
}

advanceUntilFinished(re, recoveryController, reports)

expects := map[uint64]*pdpb.StoreReport{
1: {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: 8, Version: 10},
Peers: []*metapb.Peer{
{Id: 11, StoreId: 1}, {Id: 12, StoreId: 2, Role: metapb.PeerRole_Learner}, {Id: 13, StoreId: 3, Role: metapb.PeerRole_Learner}}}}},
}},
}

for storeID, report := range reports {
if result, ok := expects[storeID]; ok {
re.Equal(result.PeerReports, report.PeerReports)
} else {
re.Empty(len(report.PeerReports))
}
}
}

// Failed learner replica store should be considered by auto-detect mode.
func TestAutoDetectWithOneLearner(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

opts := mockconfig.NewTestOptions()
cluster := mockcluster.NewCluster(ctx, opts)
coordinator := schedule.NewCoordinator(ctx, cluster, hbstream.NewTestHeartbeatStreams(ctx, cluster.ID, cluster, true))
coordinator.Run()
for _, store := range newTestStores(1, "6.0.0") {
cluster.PutStore(store)
}
recoveryController := NewController(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 TestOneLearner(t *testing.T) {
re := require.New(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

opts := mockconfig.NewTestOptions()
cluster := mockcluster.NewCluster(ctx, opts)
coordinator := schedule.NewCoordinator(ctx, cluster, hbstream.NewTestHeartbeatStreams(ctx, cluster.ID, cluster, true))
coordinator.Run()
>>>>>>> 610aee7db (unsafe recovery: Fix learner nodes got ignored in auto detect mode error (#6691)):pkg/unsaferecovery/unsafe_recovery_controller_test.go
for _, store := range newTestStores(3, "6.0.0") {
c.Assert(cluster.PutStore(store.GetMeta()), IsNil)
}
Expand Down

0 comments on commit feafae5

Please sign in to comment.