/** * Commits the ongoing transaction. This method will flush any unsent records before actually committing the transaction. * * Further, if any of the {@link #send(ProducerRecord)} calls which were part of the transaction hit irrecoverable * errors, this method will throw the last received exception immediately and the transaction will not be committed. * So all {@link #send(ProducerRecord)} calls in a transaction must succeed in order for this method to succeed. * * @throws IllegalStateException if no transactional.id has been configured or no transaction has been started * @throws ProducerFencedException fatal error indicating another producer with the same transactional.id is active * @throws org.apache.kafka.common.errors.UnsupportedVersionException fatal error indicating the broker * does not support transactions (i.e. if its version is lower than 0.11.0.0) * @throws org.apache.kafka.common.errors.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 or abortable error, or for any * other unexpected error */ public void commitTransaction() throws ProducerFencedException { throwIfNoTransactionManager(); TransactionalRequestResult result = transactionManager.beginCommit(); sender.wakeup(); result.await(); }
private void assertAbortableError(Class<? extends RuntimeException> cause) { try { transactionManager.beginCommit(); fail("Should have raised " + cause.getSimpleName()); } catch (KafkaException e) { assertTrue(cause.isAssignableFrom(e.getCause().getClass())); assertTrue(transactionManager.hasError()); } assertTrue(transactionManager.hasError()); transactionManager.beginAbort(); assertFalse(transactionManager.hasError()); }
assertFalse(transactionManager.hasPartitionsToAdd()); transactionManager.beginCommit(); prepareProduceResponse(Errors.NONE, pid, epoch); sender.run(time.milliseconds());
@Test public void testEndTxnNotSentIfIncompleteBatches() { long pid = 13131L; short epoch = 1; doInitTransactions(pid, epoch); transactionManager.beginTransaction(); transactionManager.maybeAddPartitionToTransaction(tp0); prepareAddPartitionsToTxn(tp0, Errors.NONE); sender.run(time.milliseconds()); assertTrue(transactionManager.isPartitionAdded(tp0)); transactionManager.beginCommit(); assertNull(transactionManager.nextRequestHandler(true)); assertTrue(transactionManager.nextRequestHandler(false).isEndTxn()); }
TransactionalRequestResult commitResult = transactionManager.beginCommit();
"value".getBytes(), Record.EMPTY_HEADERS, null, MAX_BLOCK_TIMEOUT).future; TransactionalRequestResult commitResult = transactionManager.beginCommit(); assertFalse(responseFuture.isDone()); prepareAddPartitionsToTxnResponse(Errors.NONE, tp0, epoch, pid);
TransactionalRequestResult commitResult = transactionManager.beginCommit();
assertFalse(transactionManager.hasPartitionsToAdd()); transactionManager.beginCommit(); prepareProduceResponse(Errors.NONE, pid, epoch); sender.run(time.milliseconds());
assertFalse(transactionManager.hasPartitionsToAdd()); transactionManager.beginCommit(); prepareProduceResponse(Errors.NONE, pid, epoch); sender.run(time.milliseconds());
@Test public void testHasOngoingTransactionSuccessfulCommit() { long pid = 13131L; short epoch = 1; TopicPartition partition = new TopicPartition("foo", 0); assertFalse(transactionManager.hasOngoingTransaction()); doInitTransactions(pid, epoch); assertFalse(transactionManager.hasOngoingTransaction()); transactionManager.beginTransaction(); assertTrue(transactionManager.hasOngoingTransaction()); transactionManager.maybeAddPartitionToTransaction(partition); assertTrue(transactionManager.hasOngoingTransaction()); prepareAddPartitionsToTxn(partition, Errors.NONE); sender.run(time.milliseconds()); transactionManager.beginCommit(); assertTrue(transactionManager.hasOngoingTransaction()); prepareEndTxnResponse(Errors.NONE, TransactionResult.COMMIT, pid, epoch); sender.run(time.milliseconds()); assertFalse(transactionManager.hasOngoingTransaction()); }
assertFalse(responseFuture.isDone()); TransactionalRequestResult commitResult = transactionManager.beginCommit();
transactionManager.beginCommit(); prepareEndTxnResponse(Errors.NONE, TransactionResult.COMMIT, pid, epoch);
transactionManager.beginCommit(); sender.run(time.milliseconds()); assertFalse(accumulator.hasUndrained());
transactionManager.beginCommit(); sender.run(time.milliseconds()); assertFalse(accumulator.hasUndrained());