Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv: acquire clock reading for lease request under lock #135042

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/kv/kvserver/leases/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func (i BuildInput) validate() error {
if i.Now.IsEmpty() {
return errors.AssertionFailedf("no clock timestamp provided")
}
if i.Now.Less(i.MinLeaseProposedTS) {
return errors.AssertionFailedf("clock timestamp earlier than minimum lease proposed timestamp")
}
if i.RaftStatus == nil {
return errors.AssertionFailedf("no raft status provided")
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/kv/kvserver/leases/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ func TestInputValidation(t *testing.T) {
input: BuildInput{},
expErr: "no lease target provided",
},
{
name: "no timestamp",
input: BuildInput{
NextLeaseHolder: repl2,
},
expErr: "no clock timestamp provided",
},
{
name: "invalid minimum lease proposed timestamp",
input: BuildInput{
NextLeaseHolder: repl2,
Now: cts20,
MinLeaseProposedTS: cts30,
},
expErr: "clock timestamp earlier than minimum lease proposed timestamp",
},
{
name: "remote transfer",
input: BuildInput{
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/replica_range_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,6 @@ func (r *Replica) redirectOnOrAcquireLeaseForRequest(
// Loop until the lease is held or the replica ascertains the actual lease
// holder. Returns also on context.Done() (timeout or cancellation).
for attempt := 1; ; attempt++ {
now = r.store.Clock().NowAsClockTimestamp()
llHandle, status, transfer, pErr := func() (*leaseRequestHandle, kvserverpb.LeaseStatus, bool, *kvpb.Error) {
nvanbenschoten marked this conversation as resolved.
Show resolved Hide resolved
r.mu.Lock()
defer r.mu.Unlock()
Expand All @@ -1259,6 +1258,7 @@ func (r *Replica) redirectOnOrAcquireLeaseForRequest(
return r.mu.pendingLeaseRequest.JoinRequest(), kvserverpb.LeaseStatus{}, true /* transfer */, nil
}

now := r.store.Clock().NowAsClockTimestamp()
status := r.leaseStatusForRequestRLocked(ctx, now, reqTS)
switch status.State {
case kvserverpb.LeaseState_ERROR:
Expand Down
Loading