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: check L0 sub-levels on allocation #78608

Merged
merged 1 commit into from
Apr 11, 2022
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
35 changes: 30 additions & 5 deletions pkg/kv/kvserver/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"
"time"

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/constraint"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings"
Expand Down Expand Up @@ -899,7 +900,7 @@ func (a *Allocator) allocateTarget(
conf,
existingVoters,
existingNonVoters,
a.scorerOptions(),
a.scorerOptions(ctx),
// When allocating a *new* replica, we explicitly disregard nodes with any
// existing replicas. This is important for multi-store scenarios as
// otherwise, stores on the nodes that have existing replicas are simply
Expand Down Expand Up @@ -1122,6 +1123,7 @@ func (a Allocator) removeTarget(

replicaSetForDiversityCalc := getReplicasForDiversityCalc(targetType, existingVoters, existingReplicas)
rankedCandidates := candidateListForRemoval(
ctx,
candidateStoreList,
constraintsChecker,
a.storePool.getLocalitiesByStore(replicaSetForDiversityCalc),
Expand Down Expand Up @@ -1451,16 +1453,18 @@ func (a Allocator) RebalanceNonVoter(
)
}

func (a *Allocator) scorerOptions() *rangeCountScorerOptions {
func (a *Allocator) scorerOptions(ctx context.Context) *rangeCountScorerOptions {
return &rangeCountScorerOptions{
storeHealthOptions: a.storeHealthOptions(ctx),
deterministic: a.storePool.deterministic,
rangeRebalanceThreshold: rangeRebalanceThreshold.Get(&a.storePool.st.SV),
}
}

func (a *Allocator) scorerOptionsForScatter() *scatterScorerOptions {
func (a *Allocator) scorerOptionsForScatter(ctx context.Context) *scatterScorerOptions {
return &scatterScorerOptions{
rangeCountScorerOptions: rangeCountScorerOptions{
storeHealthOptions: a.storeHealthOptions(ctx),
deterministic: a.storePool.deterministic,
rangeRebalanceThreshold: 0,
},
Expand Down Expand Up @@ -1588,6 +1592,24 @@ func (a *Allocator) leaseholderShouldMoveDueToPreferences(
return true
}

// storeHealthOptions returns the store health options, currently only
// considering the threshold for L0 sub-levels. This threshold is not
// considered in allocation or rebalancing decisions (excluding candidate
// stores as targets) when enforcementLevel is set to storeHealthNoAction or
// storeHealthLogOnly. By default storeHealthLogOnly is the action taken. When
// there is a mixed version cluster, storeHealthNoAction is set instead.
func (a *Allocator) storeHealthOptions(ctx context.Context) storeHealthOptions {
enforcementLevel := storeHealthNoAction
if a.storePool.st.Version.IsActive(ctx, clusterversion.AutoStatsTableSettings) {
enforcementLevel = storeHealthEnforcement(l0SublevelsThresholdEnforce.Get(&a.storePool.st.SV))
}

return storeHealthOptions{
enforcementLevel: enforcementLevel,
l0SublevelThreshold: l0SublevelsThreshold.Get(&a.storePool.st.SV),
}
}

// TransferLeaseTarget returns a suitable replica to transfer the range lease
// to from the provided list. It includes the current lease holder replica
// unless asked to do otherwise by the excludeLeaseRepl parameter.
Expand Down Expand Up @@ -1735,11 +1757,14 @@ func (a *Allocator) TransferLeaseTarget(
// https://github.com/cockroachdb/cockroach/issues/75630.
bestStore, noRebalanceReason := bestStoreToMinimizeQPSDelta(
leaseReplQPS,
qpsRebalanceThreshold.Get(&a.storePool.st.SV),
minQPSDifferenceForTransfers.Get(&a.storePool.st.SV),
leaseRepl.StoreID(),
candidates,
storeDescMap,
&qpsScorerOptions{
storeHealthOptions: a.storeHealthOptions(ctx),
qpsRebalanceThreshold: qpsRebalanceThreshold.Get(&a.storePool.st.SV),
minRequiredQPSDiff: minQPSDifferenceForTransfers.Get(&a.storePool.st.SV),
},
)

switch noRebalanceReason {
Expand Down
Loading