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-14950: implement assign() and assignment() #13797

Merged
merged 13 commits into from Jul 21, 2023

Conversation

philipnee
Copy link
Collaborator

@philipnee philipnee commented Jun 1, 2023

In this PR: I implemented assign() and assignment(). Ported the original tests from the KafkaConsumerTest.java

Different from the original Implementation:

We will explicitly send an assignment change event to the background thread to invoke auto-commit if the group.id is configured. After updating the subscription state, a NewTopicsMetadataUpdateRequestEvent will also be sent to the background thread to update the metadata.

unsubscribe

add tests

Update DefaultBackgroundThreadTest.java

Bad test...
Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@philipnee : Thanks for the PR. Left a few comments.

/*
this.coordinator.onLeavePrepare();
this.coordinator.maybeLeaveGroup("the consumer unsubscribed from all topics");
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we uncomment the code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed those lines as it's for unsubscribe which isn't baked enough for this PR.


log.info("Assigned to partition(s): {}", Utils.join(partitions, ", "));
if (this.subscriptions.assignFromUser(new HashSet<>(partitions)))
updateMetadata(time.milliseconds());
Copy link
Contributor

Choose a reason for hiding this comment

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

The existing consumer seems to only update the metadata for new topics. updateMetadata doesn't make it clear that it's for new topics. Could we make it clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does the latest rename and refactor address your concerns?

@@ -537,7 +568,9 @@ public void subscribe(Pattern pattern) {

@Override
public void unsubscribe() {
throw new KafkaException("method not implemented");
// fetcher.clearBufferedDataForUnassignedPartitions(Collections.emptySet());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Backed out the unsubscribe logic as it wasn't implemented in any meaningful way.

@@ -166,7 +208,7 @@ private DefaultBackgroundThread mockBackgroundThread() {
applicationEventsQueue,
backgroundEventsQueue,
this.errorEventHandler,
processor,
applicationEventProcessor,
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed.

@philipnee
Copy link
Collaborator Author

@kirktrue thanks for taking over this. @junrao - would you be up for another round of review?

@junrao
Copy link
Contributor

junrao commented Jul 7, 2023

@philipnee Was the following comment addressed? Kirk mentioned to take a closer look.

#13797 (comment)

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@philipnee : Thanks for the updated PR. A couple of more comments.

@philipnee
Copy link
Collaborator Author

@junrao - thanks for the review. I've addressed the two issues you pointed out. Would you be able to take another look at it?

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@philipnee : Thanks for the updated PR. The PR LGTM. Are the 23 test failures related?

@philipnee
Copy link
Collaborator Author

Thanks, @junrao -The failing tests should be fixed in the latest commit: The integration test failed because of missing subscription state dependency, which was added in one of the subsequent PR.

The failing tests are irrelevant, and these are:

Build / JDK 8 and Scala 2.12 / testOffsetTranslationBehindReplicationFlow() – org.apache.kafka.connect.mirror.integration.MirrorConnectorsWithCustomForwardingAdminIntegrationTest
44s
Build / JDK 11 and Scala 2.13 / testBalancePartitionLeaders() – org.apache.kafka.controller.QuorumControllerTest
12s
Build / JDK 20 and Scala 2.13 / [1] tlsProtocol=TLSv1.2, useInlinePem=false – org.apache.kafka.common.network.SslTransportLayerTest
14s
Build / JDK 20 and Scala 2.13 / testSyncTopicConfigs() – org.apache.kafka.connect.mirror.integration.MirrorConnectorsWithCustomForwardingAdminIntegrationTest
1m 56s

Copy link
Contributor

@junrao junrao left a comment

Choose a reason for hiding this comment

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

@philipnee : Thanks for the updated PR. LGTM

@junrao
Copy link
Contributor

junrao commented Jul 21, 2023

@philipnee : Could you update the description of the PR (to be included in the commit message) before I merge it? The description still has the following and I am not sure if it's still relevant.

Missing:

Fetcher to clear the buffer

@philipnee
Copy link
Collaborator Author

philipnee commented Jul 21, 2023

Hey @junrao - Thanks again. I updated the description to reflect the updated code more accurately. Here I just quoted the paragraph I made the change to:

We will explicitly send an assignment change event to the background thread to invoke auto-commit if the group.id is configured. After updating the subscription state, a NewTopicsMetadataUpdateRequestEvent will also be sent to the background thread to update the metadata.

@junrao junrao merged commit 1656591 into apache:trunk Jul 21, 2023
1 check was pending
Cerchie pushed a commit to Cerchie/kafka that referenced this pull request Jul 25, 2023
We will explicitly send an assignment change event to the background thread to invoke auto-commit if the group.id is configured. After updating the subscription state, a NewTopicsMetadataUpdateRequestEvent will also be sent to the background thread to update the metadata.

Co-authored-by: Kirk True <kirk@kirktrue.pro>
Reviewers: Jun Rao <junrao@gmail.com>
philipnee added a commit to philipnee/kafka that referenced this pull request Jul 25, 2023
We will explicitly send an assignment change event to the background thread to invoke auto-commit if the group.id is configured. After updating the subscription state, a NewTopicsMetadataUpdateRequestEvent will also be sent to the background thread to update the metadata.

Co-authored-by: Kirk True <kirk@kirktrue.pro>
Reviewers: Jun Rao <junrao@gmail.com>
philipnee added a commit to philipnee/kafka that referenced this pull request Jul 28, 2023
…resolve some conflicts (#32)

* cherry-pick

* KAFKA-14950: implement assign() and assignment() (apache#13797)

We will explicitly send an assignment change event to the background thread to invoke auto-commit if the group.id is configured. After updating the subscription state, a NewTopicsMetadataUpdateRequestEvent will also be sent to the background thread to update the metadata.

Co-authored-by: Kirk True <kirk@kirktrue.pro>
Reviewers: Jun Rao <junrao@gmail.com>

* cherry-pick conflict

* Update CommitRequestManager.java

Update ApplicationEventProcessor.java

---------

Co-authored-by: Kirk True <kirk@kirktrue.pro>
jeqo pushed a commit to aiven/kafka that referenced this pull request Aug 15, 2023
We will explicitly send an assignment change event to the background thread to invoke auto-commit if the group.id is configured. After updating the subscription state, a NewTopicsMetadataUpdateRequestEvent will also be sent to the background thread to update the metadata.

Co-authored-by: Kirk True <kirk@kirktrue.pro>
Reviewers: Jun Rao <junrao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants