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: add shed lease target to repl queue #94023

Merged
merged 1 commit into from
Jan 3, 2023
Merged
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
82 changes: 53 additions & 29 deletions pkg/kv/kvserver/replicate_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,34 +736,6 @@ func (rq *replicateQueue) process(
}
}

// After we made a replica change, make sure the lease is still on the
// correct store.
//
// TODO(kvoli): This lease transfer occurs outside of the planning
// ProcessOneChange planning and application logic. It should be moved
// into the planning phase and returned as a follow up change.
if rq.canTransferLeaseFrom(ctx, repl) {
transferStatus, err := rq.shedLease(
ctx,
repl,
repl.Desc(),
repl.SpanConfig(),
allocator.TransferLeaseOptions{
Goal: allocator.FollowTheWorkload,
ExcludeLeaseRepl: false,
CheckCandidateFullness: true,
},
)
if err != nil {
return false, err
}
// If we successfully transferred the lease, we can't requeue, let the new
// leaseholder do it.
if transferStatus == allocator.TransferOK {
requeue = false
}
}

if requeue {
log.KvDistribution.VEventf(ctx, 1, "re-processing")
rq.maybeAdd(ctx, repl, rq.store.Clock().NowAsClockTimestamp())
Expand Down Expand Up @@ -1823,8 +1795,24 @@ func (rq *replicateQueue) considerRebalance(
}
}

// No rebalance target was found, check whether we are able and should
// transfer the lease away to another store.
if !ok {
return nil, nil
if !canTransferLeaseFrom(ctx, repl) {
return nil, nil
}
return rq.shedLeaseTarget(
ctx,
repl,
desc,
conf,
allocator.TransferLeaseOptions{
Goal: allocator.FollowTheWorkload,
ExcludeLeaseRepl: false,
CheckCandidateFullness: true,
},
), nil

}

// If we have a valid rebalance action (ok == true) and we haven't
Expand Down Expand Up @@ -1962,6 +1950,42 @@ func replicationChangesForRebalance(
return chgs, performingSwap, nil
}

// shedLeaseTarget takes in a leaseholder replica, looks for a target for
// transferring the lease and, if a suitable target is found (e.g. alive, not
// draining), returns an allocation op to transfer the lease away.
func (rq *replicateQueue) shedLeaseTarget(
ctx context.Context,
repl *Replica,
desc *roachpb.RangeDescriptor,
conf roachpb.SpanConfig,
opts allocator.TransferLeaseOptions,
) (op AllocationOp) {
usage := RangeUsageInfoForRepl(repl)
// Learner replicas aren't allowed to become the leaseholder or raft leader,
// so only consider the `VoterDescriptors` replicas.
target := rq.allocator.TransferLeaseTarget(
ctx,
rq.storePool,
conf,
desc.Replicas().VoterDescriptors(),
repl,
usage,
false, /* forceDecisionWithoutStats */
opts,
)
if target == (roachpb.ReplicaDescriptor{}) {
return nil
}

op = AllocationTransferLeaseOp{
source: repl.StoreID(),
target: target.StoreID,
usage: usage,
bypassSafetyChecks: false,
}
return op
}

// shedLease takes in a leaseholder replica, looks for a target for transferring
// the lease and, if a suitable target is found (e.g. alive, not draining),
// transfers the lease away.
Expand Down