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

kv: bump timestamp cache when releasing replicated locks synchronously #111670

Merged

Conversation

nvanbenschoten
Copy link
Member

@nvanbenschoten nvanbenschoten commented Oct 3, 2023

Fixes #111536.

This commit is the second half of #111546. Whereas that commit taught intent/lock resolution to bump the timestamp cache when releasing replicated locks for committed transactions asynchronously through ResolveIntent and ResolveIntentRange requests, this commit teaches intent/lock resolution to bump the timestamp cache when releasing replicated locks for committed transactions synchronously through EndTxn requests.

The interface changes here look slightly different than the ones in that commit. Instead of attaching the commit timestamp to the response proto, we attach the spans over which replicated locks were released. This is because the commit timestamp was already present on the response, but the request may have resolved multiple lock spans.

Release note: None

@nvanbenschoten nvanbenschoten requested a review from a team as a code owner October 3, 2023 18:23
@nvanbenschoten nvanbenschoten requested a review from a team October 3, 2023 18:23
@nvanbenschoten nvanbenschoten requested a review from a team as a code owner October 3, 2023 18:23
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nvanbenschoten nvanbenschoten force-pushed the nvanbenschoten/endTxnBumpTsCache branch 2 times, most recently from 2e75555 to baa1990 Compare October 5, 2023 04:44
Copy link
Contributor

@miraradeva miraradeva left a comment

Choose a reason for hiding this comment

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

:lgtm: Just a few nits and one question.

Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @itsbilal and @nvanbenschoten)


pkg/kv/kvpb/api.proto line 985 at r1 (raw file):

  // spans when committing this transaction. Notably, this field is left unset
  // if only write intents were resolved. The field is also left unset for
  // transactions who aborted.

nit: "transactions that aborted."


pkg/kv/kvserver/replica_tscache.go line 146 at r1 (raw file):

			// the released locks continue to provide protection against writes
			// underneath the transaction's commit timestamp.
			for _, sp := range resp.(*kvpb.EndTxnResponse).ReplicatedLocksReleasedOnCommit {

If a txn committed successfully, is it guaranteed to have released/resolved all locks in its LockSpans? If so, what would happen if here we iterated over req.(*kvpb.EndTxnRequest).LockSpans instead of the actually-released replicated locks?

I guess one difference from the current logic is that we'll also bump the ts cache for spans that include only write intents. What would that do (other than being unnecessary)?

Is it possible that different (e.g. more) locks were released than were included in LockSpans?


pkg/kv/kvserver/batcheval/cmd_end_transaction.go line 634 at r1 (raw file):

			}
			if replLocksReleased {
				releasedReplLocks = append(releasedReplLocks, update.Span)

nit: replLocksReleased and releasedReplLocks is a bit confusing. I think releasedReplLocks is a good name for the slice; for the boolean, maybe wereReplLocksReleased or something shorter along those lines?


pkg/kv/kvserver/replica_test.go line 14618 at r1 (raw file):

		et, _ := endTxnArgs(txn, isCommit)
		// Assign lock spans to the EndTxn request. Assign one point lock span
		// and one range lock spans.

nit: "and one range lock span."

Fixes cockroachdb#111536.

This commit is the second half of cockroachdb#111546. Whereas that commit taught
intent/lock resolution to bump the timestamp cache when releasing
replicated locks for committed transactions asynchronously through
ResolveIntent and ResolveIntentRange requests, this commit teaches
intent/lock resolution to bump the timestamp cache when releasing
replicated locks for committed transactions synchronously through EndTxn
requests.

The interface changes here look slightly different than the ones in that
commit. Instead of attaching the commit timestamp to the response proto,
we attach the spans over which replicated locks were released. This is
because the commit timestamp was already present on the response, but
the request may have resolved multiple lock spans.

Release note: None
@nvanbenschoten nvanbenschoten force-pushed the nvanbenschoten/endTxnBumpTsCache branch from baa1990 to 0e6de2b Compare October 6, 2023 03:02
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.

TFTR!

bors r=miraradeva

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


pkg/kv/kvpb/api.proto line 985 at r1 (raw file):

Previously, miraradeva (Mira Radeva) wrote…

nit: "transactions that aborted."

Done.


pkg/kv/kvserver/replica_tscache.go line 146 at r1 (raw file):

If a txn committed successfully, is it guaranteed to have released/resolved all locks in its LockSpans?

No, not all of the LockSpans that were included in the request must have been resolved/released by this point. Those that were not resolved are written into the transaction record for asynchronous resolution. The relevant logic is in cmd_end_transaction.go, with the handling of the externalLocks variable.

There are two reasons why a span in the EndTxn request may not be resolved by this point:

  1. it references keys on a different range than that in which the transaction record is stored.
  2. synchronous resolution (resolveLocalLocks) hit a key or byte limit and left the remaining locks on the transaction record's range for asynchronous resolution.

I guess one difference from the current logic is that we'll also bump the ts cache for spans that include only write intents. What would that do (other than being unnecessary)?

It wouldn't be incorrect, but it would be unnecessary and put undue pressure on the timestamp cache's memory limit, which may lead to the timestamp cache losing fidelity faster than it otherwise would.

Is it possible that different (e.g. more) locks were released than were included in LockSpans?

It's not possible that more locks were released than were included in LockSpans, only that fewer were.


pkg/kv/kvserver/batcheval/cmd_end_transaction.go line 634 at r1 (raw file):

Previously, miraradeva (Mira Radeva) wrote…

nit: replLocksReleased and releasedReplLocks is a bit confusing. I think releasedReplLocks is a good name for the slice; for the boolean, maybe wereReplLocksReleased or something shorter along those lines?

Done.


pkg/kv/kvserver/replica_test.go line 14618 at r1 (raw file):

Previously, miraradeva (Mira Radeva) wrote…

nit: "and one range lock span."

Done.

@craig
Copy link
Contributor

craig bot commented Oct 6, 2023

Build succeeded:

@craig craig bot merged commit d926f1e into cockroachdb:master Oct 6, 2023
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/endTxnBumpTsCache branch October 6, 2023 16:23
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.

kv: bump timestamp cache during replicated {shared,exclusive} lock resolution
3 participants