Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
huachaohuang committed Nov 8, 2016
1 parent 235181d commit 68abf69
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions server/balancer_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,19 @@ func collectBalancerGaugeMetrics(ops map[uint64]Operator) {
}

func randomBalance(cluster *clusterInfo) *balanceOperator {
storeCount := cluster.getStoreCount()
if storeCount == 0 {
return nil
}
stores := cluster.getStores()

storeID := uint64(rand.Int() % storeCount)
region := cluster.randLeaderRegion(storeID)
store := stores[rand.Int()%len(stores)]
region := cluster.randLeaderRegion(store.GetId())
if region == nil {
return nil
}

toStoreID := uint64(rand.Int() % storeCount)
for toStoreID == storeID {
toStoreID = uint64(rand.Int() % storeCount)
newStore := stores[rand.Int()%len(stores)]
for newStore == store {
newStore = stores[rand.Int()%len(stores)]
}
newPeer, err := cluster.allocPeer(toStoreID)
newPeer, err := cluster.allocPeer(newStore.GetId())
if err != nil {
return nil
}
Expand Down

0 comments on commit 68abf69

Please sign in to comment.