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: fail gracefully in TestLeaseTransferRejectedIfTargetNeedsSnapshot #107526

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
16 changes: 13 additions & 3 deletions pkg/kv/kvserver/client_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,9 @@ func TestLeaseTransferRejectedIfTargetNeedsSnapshot(t *testing.T) {
ServerArgs: base.TestServerArgs{
Knobs: base.TestingKnobs{
Store: &kvserver.StoreTestingKnobs{
// If we're testing the below-raft check, disable the above-raft check.
// See: https://github.com/cockroachdb/cockroach/pull/107526
DisableAboveRaftLeaseTransferSafetyChecks: rejectAfterRevoke,
TestingRequestFilter: func(ctx context.Context, ba *kvpb.BatchRequest) *kvpb.Error {
if rejectAfterRevoke && ba.IsSingleTransferLeaseRequest() {
transferLeaseReqBlockOnce.Do(func() {
Expand Down Expand Up @@ -3003,10 +3006,17 @@ func TestLeaseTransferRejectedIfTargetNeedsSnapshot(t *testing.T) {
// Replica.AdminTransferLease.
transferErrC := make(chan error, 1)
if rejectAfterRevoke {
_ = tc.Stopper().RunAsyncTask(ctx, "transfer lease", func(ctx context.Context) {
require.NoError(t, tc.Stopper().RunAsyncTask(ctx, "transfer lease", func(ctx context.Context) {
transferErrC <- tc.TransferRangeLease(*repl0.Desc(), tc.Target(2))
})
<-transferLeaseReqBlockedC
}))
select {
case <-transferLeaseReqBlockedC:
// Expected case: lease transfer triggered our interceptor and is now
// waiting there for transferLeaseReqUnblockedCh.
case err := <-transferErrC:
// Unexpected case: lease transfer errored out before making it into the filter.
t.Fatalf("transferErrC unexpectedly signaled: %v", err)
}
}

// Truncate the log at index+1 (log entries < N are removed, so this
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_range_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ func (r *Replica) AdminTransferLease(
raftStatus := r.raftStatusRLocked()
raftFirstIndex := r.raftFirstIndexRLocked()
snapStatus := raftutil.ReplicaMayNeedSnapshot(raftStatus, raftFirstIndex, nextLeaseHolder.ReplicaID)
if snapStatus != raftutil.NoSnapshotNeeded && !bypassSafetyChecks {
if snapStatus != raftutil.NoSnapshotNeeded && !bypassSafetyChecks && !r.store.cfg.TestingKnobs.DisableAboveRaftLeaseTransferSafetyChecks {
r.store.metrics.LeaseTransferErrorCount.Inc(1)
log.VEventf(ctx, 2, "not initiating lease transfer because the target %s may "+
"need a snapshot: %s", nextLeaseHolder, snapStatus)
Expand Down
4 changes: 4 additions & 0 deletions pkg/kv/kvserver/testing_knobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ type StoreTestingKnobs struct {
// leadership when it diverges from the range's leaseholder. This can
// also be set via COCKROACH_DISABLE_LEADER_FOLLOWS_LEASEHOLDER.
DisableLeaderFollowsLeaseholder bool
// If set, the above-raft lease transfer safety checks (that verify that
// we don't transfer leases to followers that need a snapshot, etc) are
// disabled. The proposal-time checks are not affected by this knob.
DisableAboveRaftLeaseTransferSafetyChecks bool
// DisableRefreshReasonNewLeader disables refreshing pending commands when a new
// leader is discovered.
DisableRefreshReasonNewLeader bool
Expand Down