Skip to content

KAFKA-19272: Add initPid Response handling when keepPrepared is set to true (KIP-939) #20039

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

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

rreddy-22
Copy link
Contributor

When initPid(keepPrepared = true) is called after a client crashes, several situations should be considered.

When there's an ongoing transaction, we can transition it to the newly added PREPARED_TRANSACTION state. However, what if there's no ongoing transaction?

Another scenario could be:

  • Issued a commit, to commit prepared
  • The commit succeeded on the TC, but the client crashed
  • Client restarted with keepPreparedTxn=true (because it doesn't know if the commit succeeded or not and needs to keep retrying the commit until it's successful)
  • Issued a commit, but the transaction is not ongoing, because it's committed

Solution:
This is a perfectly valid scenario as the external transaction coordinator for the 2PC transaction will keep committing participants, and the participants need to eventually return success (that's a guarantee for a prepared transaction).
Rejected Alt 1 -> Return an InvalidTxnStateException : Returning an error would break the above scenario.
Rejected Alt 2 -> Then the next thought is that we should somehow validate if the state is expected, but we don't have data to validate the result against.

Final Solution: Just returning the success and transitioning to READY is the proper handling of this condition.

@github-actions github-actions bot added triage PRs from the community producer clients small Small PRs labels Jun 25, 2025
@rreddy-22 rreddy-22 marked this pull request as draft June 25, 2025 17:04
@rreddy-22 rreddy-22 changed the title Add initPid Response handling when keepPrepared is set to true KAFKA-19272: Add initPid Response handling when keepPrepared is set to true (KIP-939) Jun 25, 2025
@github-actions github-actions bot removed the small Small PRs label Jun 25, 2025
@rreddy-22 rreddy-22 marked this pull request as ready for review June 25, 2025 18:59
@jolshan jolshan added ci-approved and removed triage PRs from the community labels Jun 25, 2025
@@ -29,6 +29,7 @@
import org.apache.kafka.clients.producer.internals.BufferPool;
import org.apache.kafka.clients.producer.internals.BuiltInPartitioner;
import org.apache.kafka.clients.producer.internals.KafkaProducerMetrics;
import org.apache.kafka.clients.producer.internals.PreparedTxnState;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is public class, it shouldn't be in internals.

@@ -349,7 +348,7 @@ public synchronized void prepareTransaction() {
maybeFailWithError();
transitionTo(State.PREPARED_TRANSACTION);
this.preparedTxnState = new PreparedTxnState(
this.producerIdAndEpoch.producerId + ":" +
this.producerIdAndEpoch.producerId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just change the type of preparedTxnState member to be private volatile ProducerIdAndEpoch preparedTxnState then we can just assign numbers to it (it even has a convenient NONE constant). Then the KafkaProducer would create the corresponding PreparedTxnState object.

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

Successfully merging this pull request may close these issues.

3 participants