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. #826

Merged
merged 2 commits into from Oct 31, 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
15 changes: 15 additions & 0 deletions server/coordinator_test.go
Expand Up @@ -90,6 +90,13 @@ func (c *testClusterInfo) setStoreDown(storeID uint64) {
store.LastHeartbeatTS = time.Time{}
c.putStore(store)
}

func (c *testClusterInfo) setStoreOffline(storeID uint64) {
store := c.GetStore(storeID)
store.State = metapb.StoreState_Offline
c.putStore(store)
}

func (c *testClusterInfo) LoadRegion(regionID uint64, followerIds ...uint64) {
// regions load from etcd will have no leader
region := &metapb.Region{Id: regionID}
Expand Down Expand Up @@ -285,6 +292,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