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

concurrency: refactors in preparation for lock promotion #118448

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

arulajmani
Copy link
Collaborator

See individual commits for details.

References #110435

@arulajmani arulajmani requested a review from a team as a code owner January 30, 2024 00:00
Copy link

blathers-crl bot commented Jan 30, 2024

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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@nvanbenschoten nvanbenschoten left a 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: :shipit: 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
Copy link
Collaborator Author

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFAL!

Reviewable status: :shipit: 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 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?

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 the queuedGuard.

Discussed offline. SGTM. Done!

Copy link
Member

@nvanbenschoten nvanbenschoten left a 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: :shipit: 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
Copy link
Collaborator Author

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: 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.

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @arulajmani)

@arulajmani
Copy link
Collaborator Author

Thanks!

bors r=nvanbenschoten

@craig
Copy link
Contributor

craig bot commented Feb 8, 2024

Build succeeded:

@craig craig bot merged commit 414670b into cockroachdb:master Feb 8, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants