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: tiny update #145

Merged
merged 1 commit into from
Jun 10, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (cb *capacityBalancer) SelectToStore(stores []*StoreInfo, excluded map[uint
return resultStore
}

func (cb *capacityBalancer) SelectBalanceRegion(stores []*StoreInfo, cluster *ClusterInfo) (*metapb.Region, *metapb.Peer) {
func (cb *capacityBalancer) SelectBalanceRegion(cluster *ClusterInfo, stores []*StoreInfo) (*metapb.Region, *metapb.Peer) {
store := cb.SelectFromStore(stores, true)
if store == nil {
return nil, nil
Expand All @@ -115,7 +115,7 @@ func (cb *capacityBalancer) SelectBalanceRegion(stores []*StoreInfo, cluster *Cl
storeID := store.store.GetId()
region := cluster.regions.randRegion(storeID)

// If region peer count is less than max peer count, no need to do balance.
// If region peer count is less than max peer count, no need to do capacity balance.
if len(region.GetPeers()) < int(cluster.getMeta().GetMaxPeerCount()) {
return nil, nil
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func (cb *capacityBalancer) SelectRemovePeer(cluster *ClusterInfo, peers map[uin
func (cb *capacityBalancer) Balance(cluster *ClusterInfo) (*BalanceOperator, error) {
// Firstly, select one balance region from cluster info.
stores := cluster.getStores()
region, oldLeader := cb.SelectBalanceRegion(stores, cluster)
region, oldLeader := cb.SelectBalanceRegion(cluster, stores)
if region == nil || oldLeader == nil {
log.Warn("region cannot be found to do balance")
return nil, nil
Expand Down
5 changes: 5 additions & 0 deletions server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ func (r *RegionsInfo) randRegion(storeID uint64) *metapb.Region {
}

start := time.Now()

// TODO: we should use a better way for region select.
// E.g, if the region is selected a little time before, we can't select
// it again quickly.

idx, randIdx, randRegionID := 0, rand.Intn(len(storeRegions)), uint64(0)
for regionID := range storeRegions {
if idx == randIdx {
Expand Down