Skip to content

Commit

Permalink
kvserver: improve a comment in TransferLeaseTarget
Browse files Browse the repository at this point in the history
Release justification: adds no-op safeguard

Release note: None
  • Loading branch information
aayushshah15 committed Sep 8, 2021
1 parent b444f85 commit 50b80e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pkg/kv/kvserver/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ func (a *Allocator) TransferLeaseTarget(
leaseholderReplQPS, _ := stats.avgQPS()
currentDelta := getQPSDelta(storeQPSMap, existing)
bestOption := getCandidateWithMinQPS(storeQPSMap, existing)
if bestOption != (roachpb.ReplicaDescriptor{}) &&
if bestOption != (roachpb.ReplicaDescriptor{}) && leaseholderReplQPS > 0 &&
// It is always beneficial to transfer the lease to the coldest candidate
// if the range's own qps is smaller than the difference between the
// leaseholder store and the candidate store. This will always drive down
Expand All @@ -1466,6 +1466,11 @@ func (a *Allocator) TransferLeaseTarget(
// ranges with low QPS. This can add up and prevent us from achieving
// convergence in cases where we're dealing with a ton of very low-QPS
// ranges.
//
// NB: If the `bestOption` ends up being the current leaseholder, then the
// check below will fail since we know that `leaseholderReplQPS` must be
// greater than 0 (the `StoreRebalancer` only bothers rebalancing leases /
// replicas for ranges serving at least some traffic).
(leaseholderStoreQPS-leaseholderReplQPS) > storeQPSMap[bestOption.StoreID] {
storeQPSMap[leaseRepl.StoreID()] -= leaseholderReplQPS
storeQPSMap[bestOption.StoreID] += leaseholderReplQPS
Expand Down
11 changes: 8 additions & 3 deletions pkg/kv/kvserver/replicate_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,10 +1284,15 @@ const (
)

type transferLeaseOptions struct {
goal transferLeaseGoal
goal transferLeaseGoal
// checkTransferLeaseSource, when false, tells `TransferLeaseTarget` to
// exclude the current leaseholder from consideration as a potential target
// (i.e. when the caller explicitly wants to shed its lease away).
checkTransferLeaseSource bool
checkCandidateFullness bool
dryRun bool
// checkCandidateFullness, when false, tells `TransferLeaseTarget`
// to disregard the existing lease counts on candidates.
checkCandidateFullness bool
dryRun bool
}

// leaseTransferOutcome represents the result of shedLease().
Expand Down

0 comments on commit 50b80e3

Please sign in to comment.