Skip to content

Commit

Permalink
kv: improve panic message
Browse files Browse the repository at this point in the history
Over in cockroachdb#111429, we saw a non-locking read request which specified
a key locking durability of lock.Replicated. This is not allowed --
however, the resulting panic message can be improved.

Epic: none

Release note: None
  • Loading branch information
arulajmani committed Sep 28, 2023
1 parent e8f27c3 commit 3fcbf0e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/kv/kvserver/batcheval/declare.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,18 @@ func DefaultDeclareIsolatedKeys(
// Get the correct lock strength to use for {lock,latch} spans if we're
// dealing with locking read requests.
if readOnlyReq, ok := req.(kvpb.LockingReadRequest); ok {
str, _ = readOnlyReq.KeyLocking()
var dur lock.Durability
str, dur = readOnlyReq.KeyLocking()
switch str {
case lock.None:
panic(errors.AssertionFailedf("unexpected non-locking read handling"))
// One reason we can be in this branch is if someone has asked for a
// replicated non-locking read. Detect this nonsensical case to better
// word the error message.
if dur == lock.Replicated {
panic(errors.AssertionFailedf("incompatible key locking strength %s and durability %s", str, dur))
} else {
panic(errors.AssertionFailedf("unexpected non-locking read handling"))
}
case lock.Shared:
access = spanset.SpanReadOnly
// Unlike non-locking reads, shared-locking reads are isolated from
Expand Down

0 comments on commit 3fcbf0e

Please sign in to comment.