jolshan commented on code in PR #17402:
URL: https://github.com/apache/kafka/pull/17402#discussion_r1819479426
##########
core/src/test/scala/integration/kafka/api/TransactionsTest.scala:
##########
@@ -759,8 +762,107 @@ class TransactionsTest extends IntegrationTestHarness {
}
@ParameterizedTest
- @ValueSource(strings = Array("zk", "kraft"))
- def testFailureToFenceEpoch(quorum: String): Unit = {
+ @CsvSource(Array("kraft, true"))
+ def testBumpTransactionalEpochWithTV2Enabled(quorum: String, isTV2Enabled:
Boolean): Unit = {
+ val producer = createTransactionalProducer("transactionalProducer",
+ deliveryTimeoutMs = 5000, requestTimeoutMs = 5000)
+ val consumer = transactionalConsumers.head
+
+ try {
+ // Create a topic with RF=1 so that a single broker failure will render
it unavailable
+ val testTopic = "test-topic"
+ createTopic(testTopic, numPartitions, 1, new Properties)
+ val partitionLeader = TestUtils.waitUntilLeaderIsKnown(brokers, new
TopicPartition(testTopic, 0))
+
+ producer.initTransactions()
+
+ // First transaction: commit
+ producer.beginTransaction()
+
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(testTopic,
0, "4", "4", willBeCommitted = true))
+ producer.commitTransaction()
+
+ // Get producerId and epoch after first commit
+ val log = brokers(partitionLeader).logManager.getLog(new
TopicPartition(testTopic, 0)).get
+ val producerStateManager = log.producerStateManager
+ val activeProducersIter =
producerStateManager.activeProducers.entrySet().iterator()
+ assertTrue(activeProducersIter.hasNext)
+ var producerStateEntry = activeProducersIter.next().getValue
+ val producerId = producerStateEntry.producerId
+ var previousProducerEpoch = producerStateEntry.producerEpoch
+
+ // Second transaction: abort
+ producer.beginTransaction()
+
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(topic1,
null, "2", "2", willBeCommitted = false))
+
+ killBroker(partitionLeader)
+ val failedFuture =
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(testTopic,
0, "3", "3", willBeCommitted = false))
+ Thread.sleep(6000)
+ restartDeadBrokers()
+
+ org.apache.kafka.test.TestUtils.assertFutureThrows(failedFuture,
classOf[TimeoutException])
+ producer.abortTransaction()
+
+ // Get producer epoch after abortTransaction and verify it has increased.
+ producerStateEntry =
+ brokers(partitionLeader).logManager.getLog(new
TopicPartition(testTopic,
0)).get.producerStateManager.activeProducers.get(producerId)
+ if (producerStateEntry != null) {
+ val currentProducerEpoch = producerStateEntry.producerEpoch
+ assertTrue(currentProducerEpoch > previousProducerEpoch,
+ s"Producer epoch after abortTransaction ($currentProducerEpoch)
should be greater than after first commit ($previousProducerEpoch)")
+ // Update previousProducerEpoch
+ previousProducerEpoch = currentProducerEpoch
+ } else {
+ fail("Producer state entry should not be null after abortTransaction")
+ }
+
+ // Third transaction: commit
+ producer.beginTransaction()
+
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(topic2,
null, "2", "2", willBeCommitted = true))
+
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(topic1,
null, "4", "4", willBeCommitted = true))
+
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(testTopic,
0, "1", "1", willBeCommitted = true))
+
producer.send(TestUtils.producerRecordWithExpectedTransactionStatus(testTopic,
0, "3", "3", willBeCommitted = true))
+ producer.commitTransaction()
+
+ // Wait until the producer epoch has been updated on the broker
+ TestUtils.waitUntilTrue(() => {
+ val logOption = brokers(partitionLeader).logManager.getLog(new
TopicPartition(testTopic, 0))
+ logOption.exists { log =>
+ val producerStateEntry =
log.producerStateManager.activeProducers.get(producerId)
+ producerStateEntry != null && producerStateEntry.producerEpoch >
previousProducerEpoch
+ }
+ }, "Timed out waiting for producer epoch to be incremented after second
commit", 10000)
+
+ // Get producer epoch after second commit and verify it has increased
+ val logAfterCommit = brokers(partitionLeader).logManager.getLog(new
TopicPartition(testTopic, 0)).get
Review Comment:
What is the difference between the check above and this?
--
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]