Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schedule: remove pending peer before add new peer. #844

Merged
merged 1 commit into from Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions server/coordinator_test.go
Expand Up @@ -213,6 +213,14 @@ func (s *testCoordinatorSuite) TestReplica(c *C) {
checkRemovePeerResp(c, resp, 4)
region.RemoveStorePeer(4)
dispatchHeartbeatNoResp(c, co, region, stream)

// Remove offline peer directly when it's pending.
tc.addLeaderRegion(3, 1, 2, 3)
tc.setStoreOffline(3)
region = tc.GetRegion(3)
region.PendingPeers = []*metapb.Peer{region.GetStorePeer(3)}
resp = dispatchAndRecvHeartbeat(c, co, region, stream)
checkRemovePeerResp(c, resp, 3)
}

func (s *testCoordinatorSuite) TestPeerState(c *C) {
Expand Down
12 changes: 10 additions & 2 deletions server/schedule/replica_checker.go
Expand Up @@ -153,18 +153,26 @@ func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator {
for _, peer := range region.GetPeers() {
store := r.cluster.GetStore(peer.GetStoreId())
if store == nil {
log.Infof("lost the store %d,maybe you are recovering the PD cluster.", peer.GetStoreId())
log.Infof("lost the store %d, maybe you are recovering the PD cluster.", peer.GetStoreId())
return nil
}
if store.IsUp() {
continue
}

// check the number of replicas firstly
// Check the number of replicas first.
if len(region.GetPeers()) > r.opt.GetMaxReplicas() {
return CreateRemovePeerOperator("removeExtraOfflineReplica", region, peer.GetStoreId())
}

// Consider we have 3 peers (A, B, C), we set the store that contains C to
// offline while C is pending. If we generate an operator that adds a replica
// D then removes C, D will not be successfully added util C is normal again.
// So it's better to remove C directly.
if region.GetPendingPeer(peer.GetId()) != nil {
return CreateRemovePeerOperator("removePendingOfflineReplica", region, peer.GetStoreId())
}

newPeer := r.SelectBestPeerToAddReplica(region)
if newPeer == nil {
return nil
Expand Down