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

GH-3328: Enhance AbstractConsumerSeekAware with Extended callback for Multi-Group Listeners #3341

Closed
wants to merge 15 commits into from

Conversation

bky373
Copy link
Contributor

@bky373 bky373 commented Jul 3, 2024

Background

Resolves #3328

  • When using AbstractConsumerSeekAware in a multi-group listeners scenario, there are cases where the number of registered callbacks differs from the number of discovered callbacks.
  • This is due to the value type of callbacks Map in AbstractConsumerSeekAware class being simply ConsumerSeekCallback. This causes some callbacks looking at the same partition to be missing.

Changes

  • Change the value type of callbacks Map in AbstractConsumerSeekAware class from ConsumerSeekCallback to List<ConsumerSeekCallback>. Also modify some methods, test codes and docs that are affected by this change.
  • Add test codes to verify that the callbacks registered via registeredSeekCallback() and the ones you can get via getSeekCallbacks() match completely.

Comment on lines +85 to +86
assertThat(registeredCallbacks).containsExactlyInAnyOrderElementsOf(getCallbacks).isNotEmpty();
assertThat(registeredTopicPartitions).containsExactlyInAnyOrderElementsOf(getTopicPartitions).hasSize(3);
Copy link
Contributor Author

@bky373 bky373 Jul 3, 2024

Choose a reason for hiding this comment

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

When concurrency = 2, if the partitions are all assigned to only one consumer in each group,
callbacks will be two, and four if the partitions are assigned split within the group.
This varies every time you run the test, so I used isNotEmpty() instead of specific value.

assertThat(registeredCallbacks).containsExactlyInAnyOrderElementsOf(getCallbacks).isNotEmpty();

@bky373 bky373 changed the title GH-3328: Add missing seek callbacks on each topic partition GH-3328: Enhance AbstractConsumerSeekAware with Extended callback for Multi-Group Listeners Jul 3, 2024
@bky373 bky373 marked this pull request as ready for review July 3, 2024 13:43
@bky373 bky373 force-pushed the GH-3328 branch 2 times, most recently from 77c22a4 to 6e22643 Compare July 5, 2024 14:02
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Looks good so far!
Just some minor suggestions to perfect it.
Thanks

@@ -184,6 +184,9 @@ public class SeekToLastOnIdleListener extends AbstractConsumerSeekAware {

/**
* Rewind all partitions one record.
* As of version 3.3, for multi-group listeners, it's recommended to use `getTopicsAndCallbacks()`
Copy link
Member

Choose a reason for hiding this comment

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

There is no reason to mention this in the docs since the version of the doc is exact match to the code.
So, better to just adjust these samples in the doc to whatever is expected from the code.

@bky373
Copy link
Contributor Author

bky373 commented Jul 9, 2024

Looks good so far! Just some minor suggestions to perfect it. Thanks

@artembilan
Thanks for your review!

Also one minor suggestion: I'd like to rename the callbacksToTopic Map in AbstractConsumerSeekAware to callbackToTopics, so that it's consistent with the newly added topicToCallbacks Map. (Or should I rename the one I'm adding?) But I'm not sure if it's a good idea to change it, and if so, if I should do it here in PR.

private final Map<TopicPartition, List<ConsumerSeekCallback>> topicToCallbacks = new ConcurrentHashMap<>();

private final Map<ConsumerSeekCallback, List<TopicPartition>> callbacksToTopic = new ConcurrentHashMap<>();

Please take a look at my work and let me know what you think.
a1b0044

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

The callbackToTopics sounds reasonable.

Looks like that's the last concern we have in this PR.

Thanks

@bky373
Copy link
Contributor Author

bky373 commented Jul 9, 2024

The callbackToTopics sounds reasonable.

Looks like that's the last concern we have in this PR.

Thanks

Thanks! I still have some work like whats-new documentation, but It's getting very late where I am, so I'll try to finish it tomorrow, thanks as always.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Pulling locally for final review and merge.

@artembilan
Copy link
Member

Merged as 0fcdf92 with minor code and docs clean up.

@bky373 ,

Thank you for contribution; looking forward for more!

@artembilan artembilan closed this Jul 11, 2024
@bky373
Copy link
Contributor Author

bky373 commented Jul 11, 2024

Pulling locally for final review and merge.

@artembilan
Great, I wanted to change the order of items too, so thanks for doing it for me!
Thanks again for the great help so far! cc. @sobychacko

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.

Mismatch Between Registered and Found Callbacks in Multi-group Listener Cases
3 participants