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
Show file tree
Hide file tree
Changes from 2 commits
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
31 changes: 12 additions & 19 deletions server/schedule/replica_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,8 @@ 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
}

func (r *ReplicaChecker) selectBestReplacementStore(region *core.RegionInfo, oldPeer *metapb.Peer, filters ...Filter) (uint64, float64) {
// 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()))
newRegion := region.Clone()
newRegion.RemoveStorePeer(oldPeer.GetStoreId())
Expand Down Expand Up @@ -197,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 All @@ -214,7 +206,7 @@ func (r *ReplicaChecker) checkBestReplacement(region *core.RegionInfo) *Operator
checkerCounter.WithLabelValues("replica_checker", "all_right").Inc()
return nil
}
storeID, newScore := r.selectBestReplacementStore(region, oldPeer)
storeID, newScore := r.SelectBestReplacementStore(region, oldPeer)
if storeID == 0 {
checkerCounter.WithLabelValues("replica_checker", "no_replacement_store").Inc()
return nil
Expand All @@ -227,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
12 changes: 8 additions & 4 deletions server/schedulers/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ func (s *balanceRegionScheduler) transferPeer(cluster schedule.Cluster, region *
scoreGuard := schedule.NewDistinctScoreFilter(cluster.GetLocationLabels(), stores, source)

checker := schedule.NewReplicaChecker(cluster, nil)
newPeer := checker.SelectBestReplacedPeerToAddReplica(region, oldPeer, scoreGuard)
if newPeer == nil {
schedulerCounter.WithLabelValues(s.GetName(), "no_peer").Inc()
storeID, _ := checker.SelectBestReplacementStore(region, oldPeer, scoreGuard)
if storeID == 0 {
schedulerCounter.WithLabelValues(s.GetName(), "no_store").Inc()
return nil
}

target := cluster.GetStore(newPeer.GetStoreId())
target := cluster.GetStore(storeID)
log.Debugf("[region %d] source store id is %v, target store id is %v", region.GetId(), source.GetId(), target.GetId())

sourceSize := source.RegionSize + int64(opInfluence.GetStoreInfluence(source.GetId()).RegionSize)
Expand All @@ -154,6 +154,10 @@ func (s *balanceRegionScheduler) transferPeer(cluster schedule.Cluster, region *
schedulerCounter.WithLabelValues(s.GetName(), "skip").Inc()
return nil
}
newPeer, err := cluster.AllocPeer(storeID)
if err != nil {
schedulerCounter.WithLabelValues(s.GetName(), "no_peer").Inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

return nil?

}

return schedule.CreateMovePeerOperator("balance-region", cluster, region, schedule.OpBalance, oldPeer.GetStoreId(), newPeer.GetStoreId(), newPeer.GetId())
}