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-14365: Extract common logic from Fetcher #13425

Merged
merged 2 commits into from
Mar 24, 2023
Merged

KAFKA-14365: Extract common logic from Fetcher #13425

merged 2 commits into from
Mar 24, 2023

Conversation

kirktrue
Copy link
Contributor

@kirktrue kirktrue commented Mar 20, 2023

The Fetcher class is used internally by the KafkaConsumer to fetch records from the brokers. There is ongoing work to create a new consumer implementation with a significantly refactored threading model. The threading refactor work requires a similarly refactored Fetcher.

This task includes refactoring Fetcher by extracting out some common logic to allow forthcoming implementations to leverage it.

  1. Extract logic from Fetcher into AbstractFetch
  2. Introduce FetchConfig as a concise way to delineate incoming configuration from state
  3. Formalized the defaults in CommonClientConfigs and ConsumerConfig to be accessible elsewhere

Committer Checklist (excluded from commit message)

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

@C0urante
Copy link
Contributor

fetch

Extract logic from Fetcher into AbstractFetcher.

Also introduce FetchConfig as a more concise way to delineate state from
incoming configuration.

Formalized the defaults in CommonClientConfigs and ConsumerConfig to be
accessible elsewhere.
@kirktrue
Copy link
Contributor Author

@guozhangwang @hachikuji @rajinisivaram @philipnee This is ready for a review from whomever has the time.

Copy link
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.

Overall looks good to me. Except the question for synchronizing the super's functions I think we can move forward to merge.

@@ -797,24 +799,15 @@ public KafkaConsumer(Map<String, Object> configs,
config.getBoolean(ConsumerConfig.THROW_ON_FETCH_STABLE_OFFSET_UNSUPPORTED),
config.getString(ConsumerConfig.CLIENT_RACK_CONFIG));
}
FetchConfig<K, V> fetchConfig = new FetchConfig<>(config, keyDeserializer, valueDeserializer, isolationLevel);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice improvement, +1!

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
FetchConfig<K, V> fetchConfig = new FetchConfig<>(config, keyDeserializer, valueDeserializer, isolationLevel);
FetchConfig<K, V> fetchConfig = new FetchConfig<>(config, this.keyDeserializer, this.valueDeserializer, isolationLevel);

Copy link
Contributor

Choose a reason for hiding this comment

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

@kirktrue , these should be this.keyDeserializer and this.valueDeserializer. Otherwise the original values may be null and will cause an NPE on line 300 of CompletedFetch.java

*
* @return true if there are completed fetches, false otherwise
*/
boolean hasCompletedFetches() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I made a quick browse on this class assuming that all the logic are not changed, i.e. mostly copy-paste here except the FetchConfig wrapping. Please LMK otherwise and I will give it a deeper look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally did my best to keep the code I moved from Fetcher into AbstractFetch identical. There was some minor refactoring which could technically introduce bugs.

@guozhangwang
Copy link
Contributor

I've checked the failed tests, which are irrelevant.

@guozhangwang
Copy link
Contributor

LGTM, merged to trunk.

@guozhangwang guozhangwang merged commit a325262 into apache:trunk Mar 24, 2023
@rayokota
Copy link
Contributor

rayokota commented Mar 25, 2023

@guozhangwang , @kirktrue , this PR is causing NPEs downstream. I've added a comment above that indicates the problematic lines. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants