release-20.2: kvserver: improve intent cleanup for disconnected clients #65384
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-20.2
./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