-
Notifications
You must be signed in to change notification settings - Fork 15k
KAFKA-20090: Add recovery logic to handle MaxValue epochFix max epoch #21469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
5bf7788
ddaf85e
87788b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -139,11 +139,12 @@ public TxnTransitMetadata prepareNoTransit() { | |||
|
|
||||
| public TxnTransitMetadata prepareFenceProducerEpoch() { | ||||
| if (producerEpoch == Short.MAX_VALUE) | ||||
| throw new IllegalStateException("Cannot fence producer with epoch equal to Short.MaxValue since this would overflow"); | ||||
| LOGGER.error("Fencing producer {} {} with epoch equal to Short.MaxValue, this must not happen unless there is a bug", transactionalId, producerId); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What action do we expect users to take when they see this message?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message is there so that there is trail that this scenario happened. It would help to RCA weird cases. |
||||
|
|
||||
| // If we've already failed to fence an epoch (because the write to the log failed), we don't increase it again. | ||||
| // This is safe because we never return the epoch to client if we fail to fence the epoch | ||||
| short bumpedEpoch = hasFailedEpochFence ? producerEpoch : (short) (producerEpoch + 1); | ||||
| // Also don't increase if producerEpoch is already at max, to avoid overflow. | ||||
| short bumpedEpoch = hasFailedEpochFence || producerEpoch == Short.MAX_VALUE ? producerEpoch : (short) (producerEpoch + 1); | ||||
|
Comment on lines
+146
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the patch! In my view, this code seems to affect only TV1. Were you intending to make a change specifically for TV1? If not, this may end up being an unintended change. AFAIK, Both TV1 and TV2 call this code line. Even when TV2 is fenced, it actually uses the epoch obtained from Therefore, I believe any change here would affect only TV1...! What do you think?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct -- the bumped epoch is then ignored in TV2 code path. But if we don't make changes here, the TV2 code path wouldn't get through.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your comments!!! 🙇♂️ ###1. ###2. kafka/core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala Line 579 in 9e1f91d
What do you think?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the question 1 there are a couple points: |
||||
|
|
||||
| TransitionData data = new TransitionData(TransactionState.PREPARE_EPOCH_FENCE); | ||||
| data.producerEpoch = bumpedEpoch; | ||||
|
|
@@ -238,8 +239,14 @@ public TxnTransitMetadata prepareAbortOrCommit(TransactionState newState, | |||
| boolean noPartitionAdded) { | ||||
| TransitionData data = new TransitionData(newState); | ||||
| if (clientTransactionVersion.supportsEpochBump()) { | ||||
| // We already ensured that we do not overflow here. MAX_SHORT is the highest possible value. | ||||
| data.producerEpoch = (short) (producerEpoch + 1); | ||||
| if (producerEpoch == Short.MAX_VALUE && newState == TransactionState.PREPARE_ABORT) { | ||||
| // If we're already in a broken state, we let the abort go through without | ||||
| // epoch overflow, so that we can recover and continue. | ||||
| LOGGER.error("Aborting producer {} {} with epoch equal to Short.MaxValue, this must not happen unless there is a bug", transactionalId, producerId); | ||||
| } else { | ||||
| // We already ensured that we do not overflow here. MAX_SHORT is the highest possible value. | ||||
| data.producerEpoch = (short) (producerEpoch + 1); | ||||
| } | ||||
| data.lastProducerEpoch = producerEpoch; | ||||
| } else { | ||||
| data.producerEpoch = producerEpoch; | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make
txnManagerprivate[kafka]instead of adding another getterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example: