-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
concurrency: refactors in preparation for lock promotion #118448
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. |
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 1 of 1 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani)
pkg/kv/kvserver/concurrency/lock_table.go
line 2725 at r1 (raw file):
// insertLockingRequest inserts the locking request, trying to access the lock // with the supplied strength, at the correct position into the lock's wait
s/into/in/
pkg/kv/kvserver/concurrency/lock_table.go
line 2794 at r2 (raw file):
// arrival time -- requests that arrive later sort after requests that arrive // earlier, and vice-versa. func (kl *keyLocks) sortsAfter(g1, g2 *lockTableGuardImpl) bool {
A sortsBefore
and sortsAfter
method which don't reference each other and which don't use some shared logic feels like a recipe for bugs. Do we need both?
pkg/kv/kvserver/concurrency/lock_table.go
line 2794 at r2 (raw file):
// arrival time -- requests that arrive later sort after requests that arrive // earlier, and vice-versa. func (kl *keyLocks) sortsAfter(g1, g2 *lockTableGuardImpl) bool {
Does this need to be a method on keyLocks
? Are we going to scan through the held locks to detect promotions on each call?
An alternative approach here would be something like the following:
type queueOrder struct {
reqSeqNum uint64
lockPromotion bool
}
func (o1 queueOrder) before(o2 queueOrder) bool { ... }
We'd then compute and store an immutable queueOrder
on the queuedGuard
.
This logic was duplicate in a couple of places. Epic: none Release note: None
97b813b
to
da2ae83
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.
RFAL!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)
pkg/kv/kvserver/concurrency/lock_table.go
line 2794 at r2 (raw file):
Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
A
sortsBefore
andsortsAfter
method which don't reference each other and which don't use some shared logic feels like a recipe for bugs. Do we need both?
Yeah, I call one from the other in #118484.
I ended up removing the before
-- the only place that was previously using it was verify
, which I rewrote to (what I think to) be a bit clearer.
pkg/kv/kvserver/concurrency/lock_table.go
line 2794 at r2 (raw file):
Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Does this need to be a method on
keyLocks
? Are we going to scan through the held locks to detect promotions on each call?An alternative approach here would be something like the following:
type queueOrder struct { reqSeqNum uint64 lockPromotion bool } func (o1 queueOrder) before(o2 queueOrder) bool { ... }We'd then compute and store an immutable
queueOrder
on thequeuedGuard
.
Discussed offline. SGTM. Done!
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 1 of 1 files at r3, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani)
pkg/kv/kvserver/concurrency/lock_table.go
line 2794 at r2 (raw file):
Previously, arulajmani (Arul Ajmani) wrote…
Discussed offline. SGTM. Done!
Are these still needed now that we have queueOrder
?
The lock table uses sequence numbers (which are a function of request arrival order) to determine the sort order for requests in a lock's wait queue. We'll expand this criteria soon to enable lock promotion. In preparation, we pull raw sequence number comparisons behind methods on a newly introduced `queueOrder` struct. Epic: none Release note: None
da2ae83
to
df82b0e
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)
pkg/kv/kvserver/concurrency/lock_table.go
line 2794 at r2 (raw file):
Previously, nvanbenschoten (Nathan VanBenschoten) wrote…
Are these still needed now that we have
queueOrder
?
Ugh accidentally pressed u
one too many times and didn't realize :)
My bad; removed.
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 1 of 1 files at r5, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @arulajmani)
Thanks! bors r=nvanbenschoten |
Build succeeded: |
See individual commits for details.
References #110435