Skip to content

Commit

Permalink
server/balancer: don't care score if not enough replicas (#501)
Browse files Browse the repository at this point in the history
If a region has not enough replicas, we just add replicas to
any available stores.
  • Loading branch information
huachaohuang committed Feb 13, 2017
1 parent 7c90c0b commit bf2e914
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (r *replicaChecker) Check(region *regionInfo) Operator {
}

if len(region.GetPeers()) < r.rep.GetMaxReplicas() {
newPeer, _ := r.selectBestPeer(region)
newPeer, _ := r.selectBestPeer(region, r.filters...)
if newPeer == nil {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions server/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,22 @@ func (s *testReplicaCheckerSuite) TestBasic(c *C) {
checkAddPeer(c, rc.Check(region), 4)

// Test healthFilter.
// If store 4 is down, we wait.
// If store 4 is down, we add to store 3.
tc.setStoreDown(4)
c.Assert(rc.Check(region), IsNil)
checkAddPeer(c, rc.Check(region), 3)
tc.setStoreUp(4)
checkAddPeer(c, rc.Check(region), 4)

// Test snapshotCountFilter.
// If snapshotCount > MaxSnapshotCount, we can not add peer.
// If snapshotCount > MaxSnapshotCount, we add to store 3.
tc.updateSnapshotCount(4, 3)
c.Assert(rc.Check(region), IsNil)
checkAddPeer(c, rc.Check(region), 3)
// If snapshotCount < MaxSnapshotCount, we can add peer again.
tc.updateSnapshotCount(4, 1)
checkAddPeer(c, rc.Check(region), 4)

// Test storageThresholdFilter.
// If storage ratio > storageRatioThreshold, we can not add peer.
// If storage ratio > storageRatioThreshold, we add to store 3.
tc.addRegionStore(4, 1, 0.9)
checkAddPeer(c, rc.Check(region), 3)
// If storage ratio < storageRatioThreshold, we can add peer again.
Expand Down

0 comments on commit bf2e914

Please sign in to comment.