tx/rm_stm: fix handling of replay commit requests #21340
Merged
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.
A commit replay can happen in the following cases for example:
Coordinator marked the tx as prepared, dispatched remote commit_tx and
crashed. Recovers notices the transaction as prepared and attempts to
roll forward the transaction (recommit).
Coordinator lost leadership as it was dispatching remote commit_tx,
got frozen, a new leader takes over, commits and bumps the sequence
number to start a new transaction. Meanwhile the original coordinator
recovers from frozen state and starts retrying for a brief period
(rare case).
Prior to this commit, in case of replayed commits, if the partition lost
the transaction state, it was rejecting the request as invalid. The
transaction state can be lost due to producer eviction or with the
sequence number advancing. This can result in a stuck transaction on the
coordinator (particularly in example 1) as it cannot be rolled forward
or back even with a higher producer epoch effectively resulting in a
unusable producer.
With this commit, if there is no local inflight transaction for the
given producer the partition simply assumes the transaction as committed
to make forward progress. This is a valid assumption for the following
reasons
committed or aborted, so either of these must have happened.
guaranteed that the tx is "prepared" on the coordinator, so the only
way it could've been sealed already was with an earlier commit_tx
Fixes: #19954
Fixes: #18184
Backports Required
Release Notes