rreddy-22 opened a new pull request, #23831:
URL: https://github.com/apache/kafka/pull/23831

   Follow-up to #23630, addressing
   https://github.com/apache/kafka/pull/23630#discussion_r4151983373. #23630
   returns NOT_COORDINATOR once the broker has applied the leadership change;
   this covers a coordinator whose metadata is still behind.
   
   With transaction V2, an EndTxn(COMMIT) at the current epoch on a transaction
   in Empty, CompleteCommit or CompleteAbort state returned INVALID_TXN_STATE,
   which is fatal to the client. A coordinator that has lost leadership but not
   yet applied the metadata change sees the transaction in exactly this state,
   since its partitions were added on the new coordinator, and answered from its
   stale cache.
   
   Commit an empty transaction instead, the same way an empty abort is handled:
   bump the epoch, write PrepareCommit with no partitions and complete it 
without
   markers.
   
   - A stale coordinator cannot get that write replicated. The transaction log
     is written with acks=-1, and the new leader is in the old leader's ISR but
     stopped fetching from it before the partitions were added. The client gets
     a retriable error (NOT_COORDINATOR or COORDINATOR_NOT_AVAILABLE), looks up
     the coordinator again and commits on the new one.
   - A coordinator that is up to date only sees an empty transaction when the
     client wrote nothing, since a TV2 produce always adds its partition to the
     transaction before it succeeds. Committing it is a no-op epoch bump.
   
   Retries are unchanged: CompleteCommit + Commit + Retry still returns NONE and
   CompleteAbort + Commit + Retry still returns PRODUCER_FENCED. Transaction V1
   is unchanged. A PrepareCommit with no partitions is loaded and completed the
   same way as the empty PrepareAbort that TV2 already writes.
   
   Tests cover the updated state table, completing without markers, the
   retriable error when the write fails, producer ID rotation on an exhausted
   epoch, and loading an empty PrepareCommit from the log.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to