Skip to content

KAFKA-14402: Update AddPartitionsToTxn protocol to batch and handle verifyOnly requests#13231

Merged
jolshan merged 18 commits intoapache:trunkfrom
jolshan:kafka-14402
Mar 7, 2023
Merged

KAFKA-14402: Update AddPartitionsToTxn protocol to batch and handle verifyOnly requests#13231
jolshan merged 18 commits intoapache:trunkfrom
jolshan:kafka-14402

Conversation

@jolshan
Copy link
Copy Markdown
Member

@jolshan jolshan commented Feb 10, 2023

Part 1 of KIP-890

I've updated the API spec and related classes.

Clients should only be able to send up to version 3 requests and that is enforced by using a client builder.

Requests > 4 only require cluster permissions as they are initiated from other brokers.

I've added tests for the batched requests and for the verifyOnly mode.

Also -- minor change to the KafkaApis method to properly match the request name.

Committer Checklist (excluded from commit message)

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

Copy link
Copy Markdown
Contributor

@jeffkbkim jeffkbkim left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! left some comments

Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala Outdated
Comment thread core/src/main/scala/kafka/server/KafkaApis.scala Outdated
Comment thread clients/src/main/resources/common/message/AddPartitionsToTxnResponse.json Outdated
Comment thread core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala Outdated
Comment thread clients/src/main/resources/common/message/AddPartitionsToTxnResponse.json Outdated
Comment thread clients/src/main/resources/common/message/AddPartitionsToTxnResponse.json Outdated
Comment thread core/src/main/scala/kafka/coordinator/transaction/TransactionCoordinator.scala Outdated
Comment thread clients/src/main/resources/common/message/AddPartitionsToTxnRequest.json Outdated
@jolshan
Copy link
Copy Markdown
Member Author

jolshan commented Feb 23, 2023

I've added the changes to the API spec
-- verify only is now a transaction level config
-- top level error is added to the response

I've added builders to the request and tried to simplify some of the methods.
I've also addressed the verifyOnly case where some partitions are in the txn and others are not.

I will update the KIP to reflect some of these changes (especially with respect to the API spec)

I still need to address the unstable API change, but that will require a pull from master.

@jolshan
Copy link
Copy Markdown
Member Author

jolshan commented Feb 23, 2023

Took a quick look at the unstable api change. Looks like some integration tests built specifically for v4 fail with org.apache.kafka.common.errors.InvalidRequestException: Received request api key ADD_PARTITIONS_TO_TXN with version 4 which is not enabled

I will need to look into this.

@dajac
Copy link
Copy Markdown
Member

dajac commented Feb 23, 2023

Took a quick look at the unstable api change. Looks like some integration tests built specifically for v4 fail with org.apache.kafka.common.errors.InvalidRequestException: Received request api key ADD_PARTITIONS_TO_TXN with version 4 which is not enabled

I will need to look into this.

@jolshan I suppose that you have to enable unstable apis in your new integration tests.

Copy link
Copy Markdown
Contributor

@guozhangwang guozhangwang left a comment

Choose a reason for hiding this comment

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

Made a new pass according to the newly updated KIP, do not have further comments.

@guozhangwang
Copy link
Copy Markdown
Contributor

@dajac @hachikuji if you do not have further comments, we can proceed and merge it then?

Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

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

@jolshan Thanks for the PR. I made a first pass and left some comments.

public void handleResponse(AbstractResponse response) {
AddPartitionsToTxnResponse addPartitionsToTxnResponse = (AddPartitionsToTxnResponse) response;
Map<TopicPartition, Errors> errors = addPartitionsToTxnResponse.errors();
Map<TopicPartition, Errors> errors = addPartitionsToTxnResponse.errors().get(AddPartitionsToTxnResponse.V3_AND_BELOW_TXN_ID);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I suppose that errors should never be null here. I wonder if we should still check it. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What should we do if the check fails? Just have a better error message thrown?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, the check is probably not necessary. By the way, I find the idea of having V3_AND_BELOW_TXN_ID for old version a bit confusing. I was wondering if using addPartitionsToTxnResponse.data().resultsByTopicV3AndBelow() would be a better alternative here. We only iterate over the Map so the Map is not strictly required here. Have you considered something like this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was told not to have v3 and below specific methods from Jason because the v3 case should generalize to a single version of the v4 case and that should make it easy to use methods for both.

However, if we really think this is an issue. I guess we can change the approach again. I'm just not sure the experience of errors only applying to v4+. Any ideas there besides changing the method name to express it should only be used in v4+?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Understood. Let's keep it as it is then.

I agree that v3 case should generalized to a single item of the v4 case. It is just unfortunate that we don't have the transaction id in v3 response so we have to use an empty string for it. I suppose that it is the way it is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah. It really is unfortunate. 😞

Comment thread core/src/test/scala/unit/kafka/server/AddPartitionsToTxnRequestServerTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/server/AddPartitionsToTxnRequestServerTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/server/AddPartitionsToTxnRequestServerTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/server/KafkaApisTest.scala Outdated
Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

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

@jolshan Thanks for the update. I left some nits. We should be good to go once they are addressed.

Comment thread core/src/test/scala/unit/kafka/server/AddPartitionsToTxnRequestServerTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/server/KafkaApisTest.scala Outdated
Comment thread core/src/test/scala/unit/kafka/server/KafkaApisTest.scala Outdated
Copy link
Copy Markdown
Member

@dajac dajac left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the patch. I left two suggestions for follow-ups. We can do those in separate PRs. This one is large enough.

ApiKeys.INIT_PRODUCER_ID -> ((resp: InitProducerIdResponse) => resp.error),
ApiKeys.WRITE_TXN_MARKERS -> ((resp: WriteTxnMarkersResponse) => resp.errorsByProducerId.get(producerId).get(tp)),
ApiKeys.ADD_PARTITIONS_TO_TXN -> ((resp: AddPartitionsToTxnResponse) => resp.errors.get(tp)),
ApiKeys.ADD_PARTITIONS_TO_TXN -> ((resp: AddPartitionsToTxnResponse) => resp.errors.get(AddPartitionsToTxnResponse.V3_AND_BELOW_TXN_ID).get(tp)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a follow-up: We should cover the new version here as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The new version doesn't really use authorizer, so I wasn't sure if it was needed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess it uses authHelper.authorizeClusterOperation(request, CLUSTER_ACTION)

}

@Test
def testBatchedAddPartitionsToTxnRequest(): Unit = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As a follow-up: It seems that the test coverage is pretty low for this API here. It would be great if we could extend it. e.g. authorization failures, validation failures, etc.

@jolshan jolshan merged commit 29a1a16 into apache:trunk Mar 7, 2023
@jolshan
Copy link
Copy Markdown
Member Author

jolshan commented Mar 7, 2023

Demogorgon314 pushed a commit to Demogorgon314/kop that referenced this pull request Apr 15, 2026
…mnative#942)

Main changes:
- Adapt to the new `AddPartitionsToTxnRequest` from
apache/kafka#13231 (KIP-890)
- Support the new `DescribeTopicPartitions` request from
apache/kafka#14612 (KIP-966), which is required
by some admin APIs

Other changes:
- apache/kafka#13760 will retry when
`deleteRecords` returns a retriable error, change the error code to
`INVALID_REQUEST`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants