Skip to content
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

KAFKA-18401: Transaction version 2 does not support commit transaction without records #18448

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

Conversation

brandboat
Copy link
Member

related to KAFKA-18401,

Fix the issue where producer.commitTransaction under transaction version 2 throws error if no partition or offset is added to transaction. The solution is to avoid sending the endTxnRequest unless producer.send or producer.sendOffsetsToTransaction is triggered.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added core Kafka Broker producer clients small Small PRs labels Jan 8, 2025
@jolshan jolshan self-requested a review January 8, 2025 18:40
@@ -854,7 +856,7 @@ synchronized TxnRequestHandler nextRequest(boolean hasIncompleteBatches) {
return null;
}

if (nextRequestHandler.isEndTxn() && (!isTransactionV2Enabled() && !transactionStarted)) {
if (nextRequestHandler.isEndTxn() && !transactionStarted) {
Copy link
Member

Choose a reason for hiding this comment

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

minor nit here: I wonder if we can change the log here for tv2 so that we say we didn't attempt to add any partitions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pardon me, could you give me some hint? Did you mean we need to modify the log in line 862

                log.debug("Not sending EndTxn for completed transaction since no partitions " +
                        "or offsets were successfully added");

to something else when using TV2?

Copy link
Member

Choose a reason for hiding this comment

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

Right -- the implication of successfully added is a little confusing in the TV2 case because it is not a matter of "successfully" adding but a matter of not attempting to add any at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, I modified the log to Not sending EndTxn for completed transaction since no send or sendOffsetsToTransaction were triggered under TV2. Thank you.

@ClusterTest(brokers = 3, features = {
@ClusterFeature(feature = Feature.TRANSACTION_VERSION, version = 2)})
})
public void testTransactionWithoutSend(ClusterInstance cluster) {
Copy link
Member

Choose a reason for hiding this comment

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

should we include tests for when we do send/add a partition to confirm we do see errors?

Copy link
Member

Choose a reason for hiding this comment

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

And is it possible to add these tests to an existing file?

Copy link
Member Author

Choose a reason for hiding this comment

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

should we include tests for when we do send/add a partition to confirm we do see errors?

Sure, I'm going to write one!

And is it possible to add these tests to an existing file?

Perhaps this one? https://github.com/apache/kafka/blob/trunk/core/src/test/scala/integration/kafka/coordinator/transaction/ProducerIdsIntegrationTest.scala ? We can rename this file to ProducerIntegrationTest.scala and move the test to this file. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

That is an option.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I'll move the test in this PR to the test file I mentioned above. Thanks!

@jolshan jolshan added the transactions Transactions and EOS label Jan 8, 2025
@brandboat brandboat marked this pull request as ready for review January 9, 2025 16:51
@brandboat brandboat changed the title (WIP) KAFKA-18401: Transaction version 2 does not support commit transaction without records KAFKA-18401: Transaction version 2 does not support commit transaction without records Jan 9, 2025
@github-actions github-actions bot removed the small Small PRs label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clients core Kafka Broker producer transactions Transactions and EOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants