Skip to content

Commit

Permalink
Merge pull request #135199 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.3-135127

release-24.3: kvserver: include lease acquisition type when printing a lease
  • Loading branch information
arulajmani authored Nov 15, 2024
2 parents b4ca2c7 + fc62fbb commit 6f7b3e0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/kv/kvpb/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions pkg/kv/kvserver/batcheval/cmd_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <empty> ` +
`with repl=(n2,s2):2LEARNER seq=0 start=0,0 exp=<nil> pro=0,0: ` +
`with repl=(n2,s2):2LEARNER seq=0 start=0,0 exp=<nil> pro=0,0 acq=Request: ` +
`lease target replica cannot hold lease`
require.EqualError(t, err, expForLearner)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/roachpb/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
54 changes: 37 additions & 17 deletions pkg/roachpb/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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) {
Expand Down

0 comments on commit 6f7b3e0

Please sign in to comment.