From 3fcbf0eda9a5e760ab070995fa5619e19b575c94 Mon Sep 17 00:00:00 2001 From: Arul Ajmani Date: Thu, 28 Sep 2023 12:32:26 -0500 Subject: [PATCH] kv: improve panic message Over in #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 --- pkg/kv/kvserver/batcheval/declare.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/kv/kvserver/batcheval/declare.go b/pkg/kv/kvserver/batcheval/declare.go index 74951f4d2016..64e21b40fd33 100644 --- a/pkg/kv/kvserver/batcheval/declare.go +++ b/pkg/kv/kvserver/batcheval/declare.go @@ -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