Skip to content

KAFKA-20739: Transaction coordinator accepts InitProducerId v6 keepPreparedTxn recovery#22704

Open
Shekharrajak wants to merge 2 commits into
apache:trunkfrom
Shekharrajak:KAFKA-20739-coordinator-keep-prepared-txn
Open

KAFKA-20739: Transaction coordinator accepts InitProducerId v6 keepPreparedTxn recovery#22704
Shekharrajak wants to merge 2 commits into
apache:trunkfrom
Shekharrajak:KAFKA-20739-coordinator-keep-prepared-txn

Conversation

@Shekharrajak

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added triage PRs from the community core Kafka Broker transactions Transactions and EOS small Small PRs labels 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The epoch fence is skipped on the preserve path —
the prepared txn's epoch must stay valid for completeTransaction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Kafka Broker small Small PRs transactions Transactions and EOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant