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

storage/concurrency: support idempotent lock acquisition #45277

Merged

Conversation

nvanbenschoten
Copy link
Member

This commit updates lockTableImpl to support idempotent acquisition
of locks at previous sequence numbers. The storage layer expects this
to work, as is tested in TestReplicaTxnIdempotency.

The commit also fixes a bug where we were forgetting to add to the
sequence slice when updating an existing lock in acquireLock.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@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.

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


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

			// the lock acquisition as long as it corresponds to an existing
			// sequence number. The validity of such a lock re-acquisition
			// should have already been determined at the MVCC level.

My understanding (mainly based on reading the comment for TxnMeta.Sequence and Transaction.InFlightWrites) is that requests for multiple sequence numbers can be concurrently issued. Is that correct, and if yes, is there something ensuring that these concurrent requests don't write or lock the same key? What I am trying to understand is whether seeing an older sequence number that is not in seqs should be handled by adding that sequence number, or returning an error (as is done here).


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

		// UUIDs using a counter and makes this output more readable.
		var seqStr string
		if txn.Sequence != 0 {

is this just to avoid changing all the existing tests, or is there something special about sequence 0?

This commit updates lockTableImpl to support idempotent acquisition
of locks at previous sequence numbers. The storage layer expects this
to work, as is tested in TestReplicaTxnIdempotency.

The commit also fixes a bug where we were forgetting to add to the
sequence slice when updating an existing lock in acquireLock.
@nvanbenschoten nvanbenschoten force-pushed the nvanbenschoten/idemptLockTable branch from d7d5602 to ade5011 Compare February 26, 2020 19:33
Copy link
Member Author

@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.

Thanks for the review!

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


pkg/storage/concurrency/lock_table.go, line 904 at r1 (raw file):
Requests for multiple sequence numbers can be concurrently issued, but they can't overlap without either a) being in the same batch, which implies increasing sequence number ordering during evaluation or b) being sequenced in increasing sequence number using QueryIntent requests. This second approach is powered by the txnPipeliner.

What I am trying to understand is whether seeing an older sequence number that is not in seqs should be handled by adding that sequence number, or returning an error (as is done here).

The QueryIntent request attached to the req with the higher sequence number will throw an error in this case, so we shouldn't even make it here. Additionally, if the higher sequence number was written then the lower sequence number would be rejected by MVCC.


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

Previously, sumeerbhola wrote…

is this just to avoid changing all the existing tests, or is there something special about sequence 0?

Yes, this is just to avoid changing tests that don't use sequence numbers. There's nothing special about sequence 0.

Copy link
Collaborator

@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.

:lgtm:

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @sumeerbhola)

@nvanbenschoten
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 26, 2020

Build succeeded

@craig craig bot merged commit 75f4ff3 into cockroachdb:master Feb 26, 2020
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/idemptLockTable branch February 26, 2020 22:31
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