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

kvserver: alter balanceScore result to classify stores into 3 buckets #73614

Merged
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
25 changes: 9 additions & 16 deletions pkg/kv/kvserver/allocator_scorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ type scorerOptions interface {
ctx context.Context, store roachpb.StoreDescriptor, sl StoreList,
) bool
// balanceScore returns a discrete score (`balanceStatus`) based on whether
// the store represented by `sc` classifies as underfull, lessThanEqualToMean,
// moreThanMean or overfull relative to all the stores in `sl`.
// the store represented by `sc` classifies as underfull, aroundTheMean, or
// overfull relative to all the stores in `sl`.
balanceScore(sl StoreList, sc roachpb.StoreCapacity) balanceStatus
// rebalanceFromConvergenceScore assigns a convergence score to the store
// referred to by `sc` based on whether moving a replica away from this store
Expand Down Expand Up @@ -172,13 +172,10 @@ func (o rangeCountScorerOptions) balanceScore(
curRangeCount := float64(sc.RangeCount)
if curRangeCount < minRangeCount {
return underfull
} else if curRangeCount <= sl.candidateRanges.mean {
return lessThanEqualToMean
} else if curRangeCount < maxRangeCount {
return moreThanMean
} else {
} else if curRangeCount >= maxRangeCount {
return overfull
}
return aroundTheMean
}

// rebalanceFromConvergesScore returns 1 iff rebalancing a replica away from
Expand Down Expand Up @@ -271,13 +268,10 @@ func (o qpsScorerOptions) balanceScore(sl StoreList, sc roachpb.StoreCapacity) b
curQPS := sc.QueriesPerSecond
if curQPS < minQPS {
return underfull
} else if curQPS <= sl.candidateQueriesPerSecond.mean {
return lessThanEqualToMean
} else if curQPS < maxQPS {
return moreThanMean
} else {
} else if curQPS >= maxQPS {
return overfull
}
return aroundTheMean
}

func (o qpsScorerOptions) rebalanceFromConvergesScore(_ StoreList, _ roachpb.StoreCapacity) int {
Expand Down Expand Up @@ -1523,10 +1517,9 @@ func diversityRebalanceFromScore(
type balanceStatus int

const (
overfull balanceStatus = -2
moreThanMean balanceStatus = -1
lessThanEqualToMean balanceStatus = 0
underfull balanceStatus = 1
overfull balanceStatus = -1
aroundTheMean balanceStatus = 0
underfull balanceStatus = 1
)

func overfullRangeThreshold(options rangeCountScorerOptions, mean float64) float64 {
Expand Down
57 changes: 20 additions & 37 deletions pkg/kv/kvserver/allocator_scorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,40 +1473,23 @@ func TestBalanceScoreByRangeCount(t *testing.T) {
candidateRanges: stat{mean: 1000},
}

sEmpty := roachpb.StoreCapacity{
Capacity: 1024 * 1024 * 1024,
Available: 1024 * 1024 * 1024,
LogicalBytes: 0,
}
sMean := roachpb.StoreCapacity{
Capacity: 1024 * 1024 * 1024,
Available: 512 * 1024 * 1024,
LogicalBytes: 512 * 1024 * 1024,
RangeCount: 1000,
}
sRangesOverfull := sMean
sRangesOverfull.RangeCount = 1500
sRangesUnderfull := sMean
sRangesUnderfull.RangeCount = 500
sRangesLessThanMean := sMean
sRangesLessThanMean.RangeCount = 900
sRangesMoreThanMean := sMean
sRangesMoreThanMean.RangeCount = 1099

testCases := []struct {
sc roachpb.StoreCapacity
expected balanceStatus
RangeCount int32
expected balanceStatus
}{
{sEmpty, underfull},
{sRangesLessThanMean, lessThanEqualToMean},
{sMean, lessThanEqualToMean},
{sRangesMoreThanMean, moreThanMean},
{sRangesOverfull, overfull},
{sRangesUnderfull, underfull},
{0, underfull},
{900, aroundTheMean},
{1000, aroundTheMean},
{1099, aroundTheMean},
{1100, overfull},
{2000, overfull},
}
for i, tc := range testCases {
if a, e := options.balanceScore(storeList, tc.sc), tc.expected; a != e {
t.Errorf("%d: balanceScore(storeList, %+v) got %d; want %d", i, tc.sc, a, e)
sc := roachpb.StoreCapacity{
RangeCount: tc.RangeCount,
}
if a, e := options.balanceScore(storeList, sc), tc.expected; a != e {
t.Errorf("%d: balanceScore(storeList, %+v) got %d; want %d", i, sc, a, e)
}
}
}
Expand All @@ -1518,26 +1501,26 @@ func TestRebalanceBalanceScoreOnQPS(t *testing.T) {
storeList := StoreList{
candidateQueriesPerSecond: stat{mean: 1000},
}
options := qpsScorerOptions{
qpsRebalanceThreshold: 0.1,
}

testCases := []struct {
QPS float64
expBalanceScore balanceStatus
}{
{0, underfull},
{900, lessThanEqualToMean},
{999, lessThanEqualToMean},
{1000, lessThanEqualToMean},
{1001, moreThanMean},
{899, underfull},
{900, aroundTheMean},
{1099, aroundTheMean},
{1100, overfull},
{2000, overfull},
}

for i, tc := range testCases {
sc := roachpb.StoreCapacity{
QueriesPerSecond: tc.QPS,
}
options := qpsScorerOptions{
qpsRebalanceThreshold: 0.1,
}
if a, e := options.balanceScore(storeList, sc), tc.expBalanceScore; a != e {
t.Errorf("%d: rebalanceToConvergesScore(storeList, %+v) got %d; want %d", i, sc, a, e)
}
Expand Down
Loading