-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
kvserver: read lease under mutex when switching lease type #124223
kvserver: read lease under mutex when switching lease type #124223
Conversation
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
cab4b67
to
d08fe81
Compare
This passes 10/10 tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @kvoli)
pkg/kv/kvserver/replica_range_lease.go
line 1621 at r1 (raw file):
defer r.mu.Unlock() st := r.leaseStatusAtRLocked(ctx, r.store.Clock().NowAsClockTimestamp())
We should pull the r.store.Clock().NowAsClockTimestamp()
outside of the replica mutex.
pkg/kv/kvserver/replica_range_lease.go
line 1627 at r1 (raw file):
if !r.hasCorrectLeaseTypeRLocked(st.Lease) { return r.requestLeaseLocked(ctx, st, nil /* limiter */)
ignorable nit: consider structuring this to separate the no-op cases from the switch lease case:
if !st.OwnedBy(r.store.StoreID()) {
return nil
}
if r.hasCorrectLeaseTypeRLocked(st.Lease) {
return nil
}
return r.requestLeaseLocked(ctx, st, nil /* limiter */)
A race could occur when a replica queue and post lease application both attempted to switch the lease type. This race would cause the queue to not process the replica because the lease type had already changed. As a result, lease preference violations might not have been quickly resolved by the lease queue. Read the lease under the same mutex used for requesting the lease, when possibly switching the lease type. Resolves: cockroachdb#123998 Release note: None
d08fe81
to
574f667
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TYFTR!
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)
pkg/kv/kvserver/replica_range_lease.go
line 1621 at r1 (raw file):
Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
We should pull the
r.store.Clock().NowAsClockTimestamp()
outside of the replica mutex.
Done.
pkg/kv/kvserver/replica_range_lease.go
line 1627 at r1 (raw file):
Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
ignorable nit: consider structuring this to separate the no-op cases from the switch lease case:
if !st.OwnedBy(r.store.StoreID()) { return nil } if r.hasCorrectLeaseTypeRLocked(st.Lease) { return nil } return r.requestLeaseLocked(ctx, st, nil /* limiter */)
This is easier to follow, updated.
bors r=nvanbenschoten |
A race could occur when a replica queue and post lease application both attempted to switch the lease type. This race would cause the queue to not process the replica because the lease type had already changed. As a result, lease preference violations might not have been quickly resolved by the lease queue.
Read the lease under the same mutex used for requesting the lease, when possibly switching the lease type.
Resolves: #123998
Release note: None