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

server: fix frequent alloc id #1013

Merged
merged 4 commits into from
Apr 10, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions server/schedule/replica_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,6 @@ func (r *ReplicaChecker) Check(region *core.RegionInfo) *Operator {
return r.checkBestReplacement(region)
}

// SelectBestReplacedPeerToAddReplica returns a new peer that to be used to replace the old peer and distinct score.
func (r *ReplicaChecker) SelectBestReplacedPeerToAddReplica(region *core.RegionInfo, oldPeer *metapb.Peer, filters ...Filter) *metapb.Peer {
storeID, _ := r.SelectBestReplacementStore(region, oldPeer, filters...)
if storeID == 0 {
log.Debugf("[region %d] no best store to add replica", region.GetId())
return nil
}
newPeer, err := r.cluster.AllocPeer(storeID)
if err != nil {
return nil
}
return newPeer
}

// SelectBestReplacementStore returns a store id that to be used to replace the old peer and distinct score.
func (r *ReplicaChecker) SelectBestReplacementStore(region *core.RegionInfo, oldPeer *metapb.Peer, filters ...Filter) (uint64, float64) {
filters = append(filters, NewExcludedFilter(nil, region.GetStoreIds()))
Expand Down Expand Up @@ -198,9 +184,14 @@ func (r *ReplicaChecker) checkOfflinePeer(region *core.RegionInfo) *Operator {
return CreateRemovePeerOperator("removePendingOfflineReplica", r.cluster, OpReplica, region, peer.GetStoreId())
}

newPeer := r.SelectBestReplacedPeerToAddReplica(region, peer)
if newPeer == nil {
log.Debugf("[region %d] no best peer to add replica", region.GetId())
storeID, _ := r.SelectBestReplacementStore(region, peer)
if storeID == 0 {
log.Debugf("[region %d] no best store to add replica", region.GetId())
return nil
}
newPeer, err := r.cluster.AllocPeer(storeID)
if err != nil {
log.Info("alloc peer meet error:", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use log.Error.

return nil
}
return CreateMovePeerOperator("makeUpOfflineReplica", r.cluster, region, OpReplica, peer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId())
Expand Down Expand Up @@ -228,6 +219,7 @@ func (r *ReplicaChecker) checkBestReplacement(region *core.RegionInfo) *Operator
}
newPeer, err := r.cluster.AllocPeer(storeID)
if err != nil {
log.Info("alloc peer meet error:", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

return nil
}
checkerCounter.WithLabelValues("replica_checker", "new_operator").Inc()
Expand Down