forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvserver: simplify checkExecutionCanProceed
I found myself having to make a change to this method in cockroachdb#72972 and was really unsure about when this returned a nonzero lease status and whether that even mattered. Also, the code was hard to grok due to the large number of "fallthrough" if-else statements. Now it follows a standard pattern of checking and immediately returning errors as early as possible, and prefers early returns for the success cases as well. The method now clearly states what its contract (now) is: it will either return a valid lease status and no error (leaseholder read), or a zero lease status and no error (follower read or lease check skipped), or a zero lease status and an error (can't serve request, for example invalid lease, out of bounds, or pending merge, etc). Leases previously returned a half-populated lease status up for the purpose of communicating the sequence to use during proposal. However, it was cleaner to return a zero status and to repurpose the existing special casing for leases in `evalAndPropose` path to pull the sequence from the lease request. I checked the callers to make sure that none of the now absent lease statuses introduce a behavior change. The TL;DR is that callers always ignored all but the valid lease status. ---- The simplest caller is `executeAdminBatch` which doesn't even assign the returned lease status: https://github.com/cockroachdb/cockroach/blob/55720d0a4c0dd8030cd19645461226d173eefc2e/pkg/kv/kvserver/replica_send.go#L759-L775 The second caller is `executeReadOnlyBatch`: https://github.com/cockroachdb/cockroach/blob/86e2edece61091944d8575336b5de74fafc28b35/pkg/kv/kvserver/replica_read.go#L42-L46 `st` is used only if `err == nil`, in two places: https://github.com/cockroachdb/cockroach/blob/64aadfec4b3877371b6f71bf5f9aa83bd97aa515/pkg/kv/kvserver/observedts/limit.go#L42-L50 This will return early in case of a zero lease status, i.e. is a no-op in this case. The second use is storing `st` into the `endCmds`: https://github.com/cockroachdb/cockroach/blob/86e2edece61091944d8575336b5de74fafc28b35/pkg/kv/kvserver/replica_read.go#L152 which is accessed only under a similar lease validity check: https://github.com/cockroachdb/cockroach/blob/55720d0a4c0dd8030cd19645461226d173eefc2e/pkg/kv/kvserver/replica_send.go#L1019-L1021 The third caller is `executeWriteBatch`: https://github.com/cockroachdb/cockroach/blob/455cdddc6d75c03645f486b22970e5c6198a8d56/pkg/kv/kvserver/replica_write.go#L81-L89 We handled `ComputeLocalUncertaintyLimit` already. Other than that, `st` is passed to `evalAndPropose`. In that method, since it is the write path, we shouldn't see follower reads and so the remaining case are leases, where the status will be zero and the special-casing in that method takes over. ---- This commit also simplifies leaseGoodToGoRLocked. It was repeatedly reassigning `status` which I found hard to follow. Release note: None
- Loading branch information
Showing
4 changed files
with
140 additions
and
74 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