-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kv: consolidate range lease validation
Closes #123498. Informs #118435. This commit extracts lease request and lease transfer validation into the `kv/kvserver/leases` package which was introduced in #124682. This avoids the scattered leases validity checks which were previously spread between `replica_range_lease.go`, `replica_proposal_buf.go` `cmd_lease_request.go`, `cmd_lease_transfer.go`. This makes the logic easier to understand and easier to test. It will also make the logic easier to adjust when we make the following two changes in service of #118435: - default to rejecting lease requests on unknown leaders - perform lease request validation above raft, like we do for lease transfers This second change also ties in with Leader leases (#123847). Until we make that change, we will occasionally need to propose expiration-based leases (e.g. when we're not the leader) just for them to be rejected by the proposal buffer. Release note: None
- Loading branch information
1 parent
9af051e
commit a1ac434
Showing
16 changed files
with
990 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package leases | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/raftutil" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// ErrMarkLeaseTransferRejectedBecauseTargetMayNeedSnapshot indicates that the | ||
// lease transfer failed because the current leaseholder could not prove that | ||
// the lease transfer target did not need a Raft snapshot. In order to prove | ||
// this, the current leaseholder must also be the Raft leader, which is | ||
// periodically requested in maybeTransferRaftLeadershipToLeaseholderLocked. | ||
var ErrMarkLeaseTransferRejectedBecauseTargetMayNeedSnapshot = errors.New( | ||
"lease transfer rejected because the target may need a snapshot") | ||
|
||
// NewLeaseTransferRejectedBecauseTargetMayNeedSnapshotError return an error | ||
// indicating that a lease transfer failed because the current leaseholder could | ||
// not prove that the lease transfer target did not need a Raft snapshot. | ||
func NewLeaseTransferRejectedBecauseTargetMayNeedSnapshotError( | ||
target roachpb.ReplicaDescriptor, snapStatus raftutil.ReplicaNeedsSnapshotStatus, | ||
) error { | ||
err := errors.Errorf("refusing to transfer lease to %d because target may need a Raft snapshot: %s", | ||
target, snapStatus) | ||
return errors.Mark(err, ErrMarkLeaseTransferRejectedBecauseTargetMayNeedSnapshot) | ||
} |
Oops, something went wrong.