Skip to content

Locktable improvements#45040

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
sumeerbhola:locktable
Feb 13, 2020
Merged

Locktable improvements#45040
craig[bot] merged 1 commit intocockroachdb:masterfrom
sumeerbhola:locktable

Conversation

@sumeerbhola
Copy link
Copy Markdown
Collaborator

  • eliminate the doneWaiting slice that is used as a return value for many lockState methods
  • make waitElsewhere state be used only for a replicated lock that is held
  • refactoring to use informActiveWaiters() when lock becomes free

@sumeerbhola sumeerbhola requested a review from nvb February 12, 2020 22:19
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

This has 3 commits. I need to add some tests.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)

Copy link
Copy Markdown
Contributor

@nvb nvb 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 r1, 1 of 1 files at r2, 1 of 1 files at r3.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @sumeerbhola)


pkg/storage/concurrency/lock_table.go, line 306 at r1 (raw file):

func (g *lockTableGuardImpl) doneWaitingAtLock(hasReservation bool, l *lockState) {
	g.mu.Lock()
	if !hasReservation {

Could you give this condition a comment?


pkg/storage/concurrency/lock_table.go, line 1086 at r2 (raw file):

		g := qg.guard
		g.mu.Lock()
		delete(g.mu.locks, l)

nit: move this below the if qg.active { block so that it mirrors the waitingReaders case above.


pkg/storage/concurrency/lock_table.go, line 1320 at r3 (raw file):

	l.queuedWriters.Remove(e)
	if qg.active {
		g.doneWaitingAtLock(true, l)

nit: we're inconsistent about the order that we call doneWaitingAtLock and then conditionally set l.distinguishedWaiter = nil here and above. Let's be consistent so that it's easier to spot bugs.

Copy link
Copy Markdown
Collaborator Author

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

TFTR!
I've added a TODO for a maxLocks test: since none of that functionality is tested (let alone the changes to that in this PR), I plan to do it in a followup PR. The waitingState.held change and other changes are covered by existing tests.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @nvanbenschoten)


pkg/storage/concurrency/lock_table.go, line 306 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Could you give this condition a comment?

Done


pkg/storage/concurrency/lock_table.go, line 1086 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: move this below the if qg.active { block so that it mirrors the waitingReaders case above.

Done


pkg/storage/concurrency/lock_table.go, line 944 at r3 (raw file):

	}
	// TODO: change to always informActiveWaiters since this is a transition from
	// !held to held.

This TODO is fixed in latest commit


pkg/storage/concurrency/lock_table.go, line 1320 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: we're inconsistent about the order that we call doneWaitingAtLock and then conditionally set l.distinguishedWaiter = nil here and above. Let's be consistent so that it's easier to spot bugs.

Done

- fix a TODO to not return slice of doneWaiting *lockTableGuardImpls
  from various lockState methods and instead have those methods do
  the needed work.

- change waitElsewhere to only be used when the lock is held in
  replicated mode. Also, when under memory pressure, narrow the
  exception to clearing the lock to only replicated locks with no
  distinguished waiter.
  The motivation for this change is that when the lockTable is
  clearing its internal state, the only sequencing information
  remaining is for locks held in replicated mode. All others,
  locks held in unreplicated mode, or not held locks with
  reservations, should permit waiters to race. This race will
  only recreate the queue for a lock after the lock is acquired,
  since before then it will appear uncontended.

- refactor to use informActiveWaiters() when lock becomes free.

- update waitingState.held on each waiter when locks are acquired.

Release note: None
@sumeerbhola
Copy link
Copy Markdown
Collaborator Author

bors r+

craig bot pushed a commit that referenced this pull request Feb 13, 2020
45040: Locktable improvements r=sumeerbhola a=sumeerbhola

- eliminate the doneWaiting slice that is used as a return value for many lockState methods
- make waitElsewhere state be used only for a replicated lock that is held
- refactoring to use informActiveWaiters() when lock becomes free


Co-authored-by: sumeerbhola <sumeer@cockroachlabs.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Feb 13, 2020

Build succeeded

@craig craig bot merged commit 0d2fb83 into cockroachdb:master Feb 13, 2020
@sumeerbhola sumeerbhola deleted the locktable branch February 13, 2020 14:03
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