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

extract checking topic availability from BrokerMessageProducer #1832

Merged
merged 8 commits into from
Mar 25, 2024

Conversation

piotrrzysko
Copy link
Member

@piotrrzysko piotrrzysko commented Mar 4, 2024

Addresses

// TODO: maybe implementation this should be moved to KafkaProducer to make it easier for BrokerMessageProducer implementations

List<MetadataLoadingResult> allResults = loadMetadataForTopics(topics, datacenters);
logger.info("Finished loading topic metadata in {}ms", System.currentTimeMillis() - start);
logResultInfo(allResults);
return allResults.stream().anyMatch(MetadataLoadingResult::isFailure);
Copy link
Collaborator

Choose a reason for hiding this comment

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

allResults.stream().anyMatch(MetadataLoadingResult::isFailure) means that we return true if any job fails. Shouldn't we negate the result?

Copy link
Collaborator

Choose a reason for hiding this comment

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

KafkaReadinessCheckTest is probably failing because of this

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. Fixed.

@@ -13,8 +11,6 @@

public class TopicMetadataLoadingJob implements Runnable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

not really related to this PR but I think it would be helpful to at least add a comment what is this the purpose of this class - i.e. to keep producers warm. Without that it is hard to tell, it refreshes topics in the background and discards the result - what for?


when:
hook.refreshMetadata()
hook.refreshMetadataForLocalDatacenter()
Copy link
Collaborator

@moscicky moscicky Mar 5, 2024

Choose a reason for hiding this comment

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

how about checking the result of this method in tests? Right now we are never checking it so we were not able to catch a bug in TopicMetadataLoadingRunner.


import java.util.List;

public class KafkaBrokerTopicMetadataFetcher implements BrokerTopicMetadataFetcher {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering whether it makes sense to separate KafkaBrokerTopicMetadataFetcher from KafkaTopicMetadataFetcher:

  1. they names are really similar which makes it confusing
  2. KafkaTopicMetadataFetcher is only used by KafkaBrokerTopicMetadataFetcher

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Merged.


@Override
public boolean tryFetchFromDatacenter(CachedTopic topic, String datacenter) {
// TODO: To fetch metadata for a selected datacenter https://github.com/allegro/hermes/pull/1823 is required.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the final implementation we have to be extra careful: this class uses Producers and KafkaTopicMetadataFetcher. KafkaTopicMetadataFetcher in turn uses AdminClient. So we are essentially using two different Kafka clients (KafkaProducer and AdminClient) here and we need to make sure in the future that both of them refer to the same datacenter

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps, an option worth considering is to introduce datacenter awareness in this PR since its scope is relatively narrow and it is easier to spot any bugs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me play around with this a bit. Perhaps remodeling this class slightly will address this comment and #1832 (comment).

@moscicky moscicky self-requested a review March 12, 2024 10:09
@piotrrzysko piotrrzysko marked this pull request as ready for review March 14, 2024 10:15
Copy link
Contributor

@szczygiel-m szczygiel-m left a comment

Choose a reason for hiding this comment

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

Great PR!

@piotrrzysko piotrrzysko merged commit d861cf9 into master Mar 25, 2024
27 checks passed
@piotrrzysko piotrrzysko deleted the topic-availability-checker branch March 25, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants