diff --git a/pkg/kv/kvpb/errors_test.go b/pkg/kv/kvpb/errors_test.go index 7c64d0623543..aba495a0e268 100644 --- a/pkg/kv/kvpb/errors_test.go +++ b/pkg/kv/kvpb/errors_test.go @@ -380,7 +380,7 @@ func TestNotLeaseholderError(t *testing.T) { err *NotLeaseHolderError }{ { - exp: `[NotLeaseHolderError] r1: replica not lease holder; current lease is repl=(n1,s1):1 seq=2 start=0.000000002,0 epo=1 min-exp=0.000000003,0 pro=0.000000001,0`, + exp: `[NotLeaseHolderError] r1: replica not lease holder; current lease is repl=(n1,s1):1 seq=2 start=0.000000002,0 epo=1 min-exp=0.000000003,0 pro=0.000000001,0 acq=Transfer`, err: &NotLeaseHolderError{ RangeID: 1, Lease: &roachpb.Lease{ diff --git a/pkg/kv/kvserver/batcheval/cmd_lease_test.go b/pkg/kv/kvserver/batcheval/cmd_lease_test.go index 867c6ffc0dba..d022eb745334 100644 --- a/pkg/kv/kvserver/batcheval/cmd_lease_test.go +++ b/pkg/kv/kvserver/batcheval/cmd_lease_test.go @@ -66,13 +66,14 @@ func TestLeaseCommandLearnerReplica(t *testing.T) { cArgs.Args = &kvpb.RequestLeaseRequest{ Lease: roachpb.Lease{ - Replica: replicas[1], + Replica: replicas[1], + AcquisitionType: roachpb.LeaseAcquisitionType_Request, }, } _, err = RequestLease(ctx, nil, cArgs, nil) const expForLearner = `cannot replace lease ` + - `with repl=(n2,s2):2LEARNER seq=0 start=0,0 exp= pro=0,0: ` + + `with repl=(n2,s2):2LEARNER seq=0 start=0,0 exp= pro=0,0 acq=Request: ` + `lease target replica cannot hold lease` require.EqualError(t, err, expForLearner) } diff --git a/pkg/roachpb/data.go b/pkg/roachpb/data.go index 5ad9ad1b19fe..ee3e01373e4b 100644 --- a/pkg/roachpb/data.go +++ b/pkg/roachpb/data.go @@ -1933,7 +1933,7 @@ func (l Lease) SafeFormat(w redact.SafePrinter, _ rune) { default: panic("unexpected lease type") } - w.Printf(" pro=%s", l.ProposedTS) + w.Printf(" pro=%s acq=%s", l.ProposedTS, l.AcquisitionType) } // Empty returns true for the Lease zero-value. diff --git a/pkg/roachpb/data_test.go b/pkg/roachpb/data_test.go index b1e4d79f908b..0e07480f564c 100644 --- a/pkg/roachpb/data_test.go +++ b/pkg/roachpb/data_test.go @@ -1094,12 +1094,13 @@ func TestLeaseStringAndSafeFormat(t *testing.T) { StoreID: 1, ReplicaID: 1, }, - Start: makeClockTS(1, 1), - Expiration: makeTS(2, 1).Clone(), - ProposedTS: makeClockTS(1, 0), - Sequence: 3, + Start: makeClockTS(1, 1), + Expiration: makeTS(2, 1).Clone(), + ProposedTS: makeClockTS(1, 0), + Sequence: 3, + AcquisitionType: LeaseAcquisitionType_Request, }, - exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 exp=0.000000002,1 pro=0.000000001,0", + exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 exp=0.000000002,1 pro=0.000000001,0 acq=Request", }, { name: "epoch", @@ -1109,13 +1110,14 @@ func TestLeaseStringAndSafeFormat(t *testing.T) { StoreID: 1, ReplicaID: 1, }, - Start: makeClockTS(1, 1), - ProposedTS: makeClockTS(1, 0), - Sequence: 3, - Epoch: 4, - MinExpiration: makeTS(2, 1), + Start: makeClockTS(1, 1), + ProposedTS: makeClockTS(1, 0), + Sequence: 3, + Epoch: 4, + MinExpiration: makeTS(2, 1), + AcquisitionType: LeaseAcquisitionType_Transfer, }, - exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 epo=4 min-exp=0.000000002,1 pro=0.000000001,0", + exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 epo=4 min-exp=0.000000002,1 pro=0.000000001,0 acq=Transfer", }, { name: "leader", @@ -1125,13 +1127,31 @@ func TestLeaseStringAndSafeFormat(t *testing.T) { StoreID: 1, ReplicaID: 1, }, - Start: makeClockTS(1, 1), - ProposedTS: makeClockTS(1, 0), - Sequence: 3, - MinExpiration: makeTS(2, 1), - Term: 5, + Start: makeClockTS(1, 1), + ProposedTS: makeClockTS(1, 0), + Sequence: 3, + MinExpiration: makeTS(2, 1), + Term: 5, + AcquisitionType: LeaseAcquisitionType_Transfer, }, - exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 term=5 min-exp=0.000000002,1 pro=0.000000001,0", + exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 term=5 min-exp=0.000000002,1 pro=0.000000001,0 acq=Transfer", + }, + { + name: "leader", + lease: Lease{ + Replica: ReplicaDescriptor{ + NodeID: 1, + StoreID: 1, + ReplicaID: 1, + }, + Start: makeClockTS(1, 1), + ProposedTS: makeClockTS(1, 0), + Sequence: 3, + MinExpiration: makeTS(2, 1), + Term: 5, + AcquisitionType: LeaseAcquisitionType_Request, + }, + exp: "repl=(n1,s1):1 seq=3 start=0.000000001,1 term=5 min-exp=0.000000002,1 pro=0.000000001,0 acq=Request", }, } { t.Run(tc.name, func(t *testing.T) {