Skip to content

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

Merged
junrao merged 13 commits intoapache:trunkfrom
philipnee:consumer-refactor-assignment
Jul 21, 2023
Merged

KAFKA-14950: implement assign() and assignment()#13797
junrao merged 13 commits intoapache:trunkfrom
philipnee:consumer-refactor-assignment

Conversation

@philipnee
Copy link
Contributor

@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...
@philipnee philipnee added KIP-848 The Next Generation of the Consumer Rebalance Protocol ctr Consumer Threading Refactor (KIP-848) labels Jun 1, 2023
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?

@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.

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
Contributor 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
Contributor 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
Contributor 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
Contributor 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
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

Labels

ctr Consumer Threading Refactor (KIP-848) KIP-848 The Next Generation of the Consumer Rebalance Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants