KAFKA-20739: Transaction coordinator accepts InitProducerId v6 keepPreparedTxn recovery#22704
Open
Shekharrajak wants to merge 2 commits into
Open
Conversation
Shekharrajak
commented
Jun 29, 2026
| // transaction exists, preserve it and return its producer id/epoch so the client can | ||
| // finalize it. There is no state change, so respond directly without a log append. | ||
| val preservedResult = coordinatorEpochAndMetadata.toOption.flatMap { existingEpochAndMetadata => | ||
| val txnMetadata = existingEpochAndMetadata.transactionMetadata |
Contributor
Author
There was a problem hiding this comment.
The epoch fence is skipped on the preserve path —
the prepared txn's epoch must stay valid for completeTransaction.
This file contains hidden or 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
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.
Ref https://issues.apache.org/jira/browse/KAFKA-20739
The transaction coordinator rejected every InitProducerId keepPreparedTxn=true with UNSUPPORTED_VERSION (a stub), so a 2PC producer could not recover a prepared transaction after a crash/restart.
TransactionCoordinator.handleInitProducerId: replace the stub — reject only keepPreparedTxn && !enable2Pc (INVALID_REQUEST); otherwise proceed.
Add a recovery short-circuit: when an ongoing 2PC transaction exists (ONGOING + isDistributedTwoPhaseCommitTxn), preserve it and return its producerId/epoch as ongoingTxnProducerId/ongoingTxnProducerEpoch
KafkaApis.createResponse: populate the v6 ongoing response fields.
Client side already sends v6 (KAFKA-20738) and consumes these response fields (TransactionManager → PREPARED_TRANSACTION), so the two complete the recovery loop together.
Tests: TransactionCoordinatorTest — keepPreparedTxn without 2PC → INVALID_REQUEST; with 2PC + no ongoing txn → NONE; with an ongoing 2PC txn → returns its pid/epoch and asserts no log append.