Skip to content

Commit

Permalink
kvserver: allow VOTER_INCOMING to receive the lease
Browse files Browse the repository at this point in the history
Previously, VOTER_INCOMING replicas joining the cluster weren't allowed
to receive the lease, even though there is no actual problem with doing so.
This change removes the restriction, as a step towards #74077

Release note: None
  • Loading branch information
shralex committed Jan 5, 2022
1 parent ecdf51b commit a6e5bde
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
12 changes: 6 additions & 6 deletions pkg/kv/kvserver/replica_learner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,8 @@ func TestLearnerNoAcceptLease(t *testing.T) {
}
}

// TestJointConfigLease verifies that incoming and outgoing voters can't have the
// lease transferred to them.
// TestJointConfigLease verifies that incoming voters can have the
// lease transferred to them, and outgoing voters cannot.
func TestJointConfigLease(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
Expand All @@ -859,14 +859,14 @@ func TestJointConfigLease(t *testing.T) {
require.True(t, desc.Replicas().InAtomicReplicationChange(), desc)

err := tc.TransferRangeLease(desc, tc.Target(1))
exp := `replica cannot hold lease`
require.True(t, testutils.IsError(err, exp), err)
require.NoError(t, err)

// NB: we don't have to transition out of the previous joint config first
// because this is done automatically by ChangeReplicas before it does what
// it's asked to do.
desc = tc.RemoveVotersOrFatal(t, k, tc.Target(1))
err = tc.TransferRangeLease(desc, tc.Target(1))
desc = tc.RemoveVotersOrFatal(t, k, tc.Target(0))
err = tc.TransferRangeLease(desc, tc.Target(0))
exp := `replica cannot hold lease`
require.True(t, testutils.IsError(err, exp), err)
}

Expand Down
15 changes: 7 additions & 8 deletions pkg/roachpb/metadata_replicas.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,13 @@ func CheckCanReceiveLease(wouldbeLeaseholder ReplicaDescriptor, rngDesc *RangeDe
repDesc, ok := rngDesc.GetReplicaDescriptorByID(wouldbeLeaseholder.ReplicaID)
if !ok {
return errReplicaNotFound
} else if t := repDesc.GetType(); t != VOTER_FULL {
// NB: there's no harm in transferring the lease to a VOTER_INCOMING,
// but we disallow it anyway. On the other hand, transferring to
// VOTER_OUTGOING would be a pretty bad idea since those voters are
// dropped when transitioning out of the joint config, which then
// amounts to removing the leaseholder without any safety precautions.
// This would either wedge the range or allow illegal reads to be
// served.
} else if !repDesc.IsVoterNewConfig() {
// NB: there's no harm in transferring the lease to a VOTER_INCOMING.
// On the other hand, transferring to VOTER_OUTGOING would be a pretty bad
// idea since those voters are dropped when transitioning out of the joint
// config, which then amounts to removing the leaseholder without any
// safety precautions. This would either wedge the range or allow illegal
// reads to be served.
//
// Since the leaseholder can't remove itself and is a VOTER_FULL, we
// also know that in any configuration there's at least one VOTER_FULL.
Expand Down

0 comments on commit a6e5bde

Please sign in to comment.