rreddy-22 commented on code in PR #19539:
URL: https://github.com/apache/kafka/pull/19539#discussion_r2082575771
##########
clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java:
##########
@@ -760,6 +765,48 @@ public void sendOffsetsToTransaction(Map<TopicPartition,
OffsetAndMetadata> offs
}
}
+ /**
+ * Prepares the current transaction for a two-phase commit. This method
will flush all pending messages
+ * and transition the producer into a mode where only {@link
#commitTransaction()}, {@link #abortTransaction()},
+ * or completeTransaction(PreparedTxnState) may be called.
+ * <p>
+ * This method is used as part of a two-phase commit protocol:
+ * <ol>
+ * <li>Prepare the transaction by calling this method. This returns a
{@link PreparedTxnState} if successful.</li>
+ * <li>Make any external system changes that need to be atomic with this
transaction.</li>
+ * <li>Complete the transaction by calling {@link #commitTransaction()},
{@link #abortTransaction()} or
+ * completeTransaction(PreparedTxnState).</li>
+ * </ol>
+ *
+ * @return the prepared transaction state to use when completing the
transaction
+ *
+ * @throws IllegalStateException if no transactional.id has been
configured or no transaction has been started yet.
+ * @throws InvalidTxnStateException if the producer is not in a state
where preparing
+ * a transaction is possible or 2PC is not enabled.
+ * @throws ProducerFencedException fatal error indicating another producer
with the same transactional.id is active
+ * @throws UnsupportedVersionException fatal error indicating the broker
+ * does not support transactions (i.e. if its version is lower
than 0.11.0.0)
+ * @throws AuthorizationException fatal error indicating that the
configured
+ * transactional.id is not authorized. See the exception for more
details
+ * @throws KafkaException if the producer has encountered a previous fatal
error or for any other unexpected error
+ * @throws TimeoutException if the time taken for preparing the
transaction has surpassed <code>max.block.ms</code>
+ * @throws InterruptException if the thread is interrupted while blocked
+ */
+ @Override
+ public PreparedTxnState prepareTransaction() throws
ProducerFencedException {
+ throwIfNoTransactionManager();
+ throwIfProducerClosed();
Review Comment:
yeahhhh I wasnt sure if we wanted to throw an error in this case
--
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]