-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
release-21.1: kvserver: improve intent cleanup for disconnected clients #65383
Merged
erikgrinaker
merged 4 commits into
cockroachdb:release-21.1
from
erikgrinaker:backport21.1-64869
May 26, 2021
Merged
release-21.1: kvserver: improve intent cleanup for disconnected clients #65383
erikgrinaker
merged 4 commits into
cockroachdb:release-21.1
from
erikgrinaker:backport21.1-64869
May 26, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transaction records and intents are normally cleaned up asynchronously via `IntentResolver.CleanupTxnIntentsAsync()`, separately from the client's context. When the async task limit is exceeded, cleanup instead becomes synchronous and attached to the client context. However, the final `gcTxnRecord()` call to remove the transaction record is asynchronous even when intent cleanup is synchronous, to avoid holding onto the intent resolver task slot. This call will typically return to the caller before `gcTxnRecord()` completes, which may cause the caller to cancel the context (either via `defer cancel()` or a client disconnection) and in turn cancel the `gcTxnRecord()` call. This patch gives the async `gcTxnRecord()` call a separate background context that's independent of the client's context even in the synchronous case, with a 20 second timeout to avoid goroutine leaks. Release note (bug fix): Fixed a race condition during transaction cleanup that could leave old transaction records behind until MVCC garbage collection.
Whenever a client disconnects during an open transaction or in-flight DML statement, the server-side session will asynchronously clean up the transaction record and intents by rolling back the transaction. However, this had a very short timeout of 3 seconds, and even though the actual `IntentResolver.CleanupTxnIntentsAsync()` cleanup task runs asynchronously and independently of the client's context in the typical case, the short timeout could cause transaction cleanup to be cancelled if the `EndTxn` request took more than 3 seconds to get all the way through Raft execution or if the async task limit was exceeded such that the cleanup task kept using the client's context. This in turn could lead to intents building up over time. This patch increases the timeout when rolling back transactions for disconnected clients to 1 minute, and also tries to perform transaction cleanup when a client disconnects while waiting for an `EndTxn` command to go through Raft. Release note (bug fix): improved transaction cleanup for disconnected clients, to reduce intent buildup.
Release note: None
This test is flaky because it does not retry transaction failures. However, the retries uncovered additional bugs, so skipping the test for now to avoid CI flake. Release note: None
erikgrinaker
force-pushed
the
backport21.1-64869
branch
from
May 23, 2021 20:01
a718ddb
to
ada742a
Compare
nvanbenschoten
approved these changes
May 26, 2021
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, 4 of 4 files at r2, 1 of 1 files at r3, 1 of 1 files at r4.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @aliher1911)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 2/2 commits from #64869.
Backport 1/1 commits from #65385.
Backport 1/1 commits from #65461.
TestReliableIntentCleanup
turned out to be flaky, and the flake uncovered additional bugs. Therefore, the test has to be skipped here (to avoid introducing flake), and will be enabled again when #65592 is backported. The test has been verified to pass most of the time onrelease-21.1
./cc @cockroachdb/release
kvserver: improve intent cleanup for disconnected clients
Whenever a client disconnects during an open transaction or in-flight
DML statement, the server-side session will asynchronously clean up the
transaction record and intents by rolling back the transaction.
However, this had a very short timeout of 3 seconds, and even though the
actual
IntentResolver.CleanupTxnIntentsAsync()
cleanup task runsasynchronously and independently of the client's context in the typical
case, the short timeout could cause transaction cleanup to be cancelled
if the
EndTxn
request took more than 3 seconds to get all the waythrough Raft execution or if the async task limit was exceeded such that
the cleanup task kept using the client's context. This in turn could
lead to intents building up over time.
This patch increases the timeout when rolling back transactions for
disconnected clients to 1 minute, and also tries to perform transaction
cleanup when a client disconnects while waiting for an
EndTxn
commandto go through Raft.
Resolves #64770, touches #60585.
Release note (bug fix): improved transaction cleanup for disconnected
clients, to reduce intent buildup.
kvserver: fix race condition during synchronous txn record cleanup
Transaction records and intents are normally cleaned up asynchronously
via
IntentResolver.CleanupTxnIntentsAsync()
, separately from theclient's context. When the async task limit is exceeded, cleanup instead
becomes synchronous and attached to the client context. However, the
final
gcTxnRecord()
call to remove the transaction record isasynchronous even when intent cleanup is synchronous, to avoid holding
onto the intent resolver task slot. This call will typically return to
the caller before
gcTxnRecord()
completes, which may cause the caller tocancel the context (either via
defer cancel()
or a clientdisconnection) and in turn cancel the
gcTxnRecord()
call.This patch gives the async
gcTxnRecord()
call a separate backgroundcontext that's independent of the client's context even in the
synchronous case, with a 20 second timeout to avoid goroutine leaks.
Resolves #64868, touches #60585.
Release note (bug fix): Fixed a race condition during transaction
cleanup that could leave old transaction records behind until MVCC
garbage collection.
/cc @cockroachdb/kv