chickenchickenlove opened a new pull request, #21506: URL: https://github.com/apache/kafka/pull/21506
### Motivation In TV2, there is an edge-case race at the epoch exhaustion boundary (`Short.MaxValue - 1`) that can leave a transaction stuck in `ONGOING`. When a transaction times out at epoch `Short.MaxValue - 1`, the coordinator fences and aborts it. During this flow, the epoch is bumped to `Short.MaxValue` and the transaction proceeds toward abort completion. If a delayed client `EndTxn(ABORT)` arrives with the old epoch, the request may be treated as a retry path. Before this change, `generateTxnTransitMetadataForTxnCompletion` skipped producer ID rotation for epoch-fence aborts due to the `!isEpochFence` guard. That allowed the exhausted epoch path to continue without allocating `nextProducerId`, which could prevent definitive fencing/rotation at the overflow boundary. ### Changes - Removed the `!isEpochFence` guard in the TV2 `endTransaction` completion path when checking `txnMetadata.isProducerEpochExhausted`. This ensures that abort flows passing through epoch fencing (for example, timeout-driven aborts and fencing triggered during `InitProducerId`) can still allocate `nextProducerId` when the epoch is exhausted. Metadata transition behavior: - In `PREPARE_ABORT`, `TxnTransitMetadata` carries `nextProducerId` (with the boundary bump behavior, e.g. epoch reaching `Short.MaxValue`). - In-memory `TransactionMetadata` keeps the original producer ID until marker completion. - On `COMPLETE_ABORT`, `TransactionMetadata` is rotated to the new producer ID with epoch `0`, fully fencing the old producer session. ### Testing Added TV2 boundary tests in `TransactionCoordinatorTest.scala`: - `shouldHandleTimeoutAtEpochOverflowBoundaryCorrectlyAndLateClientAbortRequestTV2` - `shouldRotateProducerIdWhenInitPidFencesOngoingTxnAtEpochOverflowBoundaryTV2` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
