From a5787e8599e2fadd2869ccaee24a864d6331723a Mon Sep 17 00:00:00 2001 From: Yevgeniy Miretskiy Date: Thu, 6 Jan 2022 17:09:15 -0500 Subject: [PATCH] kv: Allow nil when checking for empty lease. Treat nil lease as empty when checking for empty lease. Recent changes in https://github.com/cockroachdb/cockroach/pull/66374 as well as in https://github.com/cockroachdb/cockroach/pull/74315 changed how lease is stored as well as modified receiver type. As a result, attempts to print empty `EvictionToken{}` will result in a nil panic. Release Notes: None --- pkg/roachpb/data.go | 2 +- pkg/roachpb/string_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/roachpb/data.go b/pkg/roachpb/data.go index 05805865aa8b..36e1fbc1877b 100644 --- a/pkg/roachpb/data.go +++ b/pkg/roachpb/data.go @@ -1887,7 +1887,7 @@ func (l *Lease) SafeFormat(w redact.SafePrinter, _ rune) { // Empty returns true for the Lease zero-value. func (l *Lease) Empty() bool { - return *l == (Lease{}) + return l == nil || *l == (Lease{}) } // OwnedBy returns whether the given store is the lease owner. diff --git a/pkg/roachpb/string_test.go b/pkg/roachpb/string_test.go index 74279eb2489b..a6114a472162 100644 --- a/pkg/roachpb/string_test.go +++ b/pkg/roachpb/string_test.go @@ -154,7 +154,7 @@ func TestLeaseString(t *testing.T) { }, { lease: nil, - expected: "", + expected: "", }, { lease: &roachpb.Lease{