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

MINOR: add helper function for clusterInstance #16852

Merged
merged 10 commits into from
Aug 31, 2024
Merged

Conversation

TaiJuWu
Copy link
Contributor

@TaiJuWu TaiJuWu commented Aug 11, 2024

*More detailed description of your change,
Add two helper function: clusterInstance#createTopic

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

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

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@TaiJuWu thanks for this nice helper.

core/src/test/java/kafka/test/ClusterInstance.java Outdated Show resolved Hide resolved
@@ -187,6 +188,21 @@ default void waitTopicDeletion(String topic) throws InterruptedException {
waitForTopic(topic, 0);
}

default long waitForMeatdataSync() throws InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is totally unused. Why we need this helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is not used now.
This comes from TestUtils.ensureConsistentKRaftMetadata and I think it can help new infra user easy to sync metadata.
WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test at least

@chia7712
Copy link
Contributor

@TaiJuWu any updates?

@TaiJuWu
Copy link
Contributor Author

TaiJuWu commented Aug 24, 2024

@TaiJuWu any updates?

@chia7712 Thanks for review. Update.

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@TaiJuWu thanks for your patch

@@ -187,6 +188,14 @@ default void waitTopicDeletion(String topic) throws InterruptedException {
waitForTopic(topic, 0);
}

long waitForMeatdataSync() throws InterruptedException;
Copy link
Contributor

Choose a reason for hiding this comment

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

waitForMetadataSync

Also, what is the purpose of the return value?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the typo

clusterInstance.createTopic(topicName, partitions, replicas);
clusterInstance.waitForTopic(topicName, partitions);

long offset = clusterInstance.waitForMeatdataSync();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please write test to make sure "it works well" rather than checking the return value. For example, the method is used to "wait" the metadata. Hence, we should make some metadata changes and then call waitForMetadataSync. Finally, we call the APIs using the metadata to check the metadata is synced.

@TaiJuWu TaiJuWu marked this pull request as draft August 27, 2024 10:52
@@ -187,6 +188,14 @@ default void waitTopicDeletion(String topic) throws InterruptedException {
waitForTopic(topic, 0);
}

void waitForMeatdataSync(String topic, int partition, int isrSize) throws InterruptedException;
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 almost equal to waitForTopic, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I find KRaft can trace cluster log by controller but there is no way to check cluster log for ZK.
ZK only support partition level log so I am so hesitate to add this method.
We can discuss offline tonight!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is almost equal to waitForTopic, right?

Hi @chia7712 , I removed waitForMetadataSync, PTAL.

@TaiJuWu TaiJuWu marked this pull request as ready for review August 28, 2024 23:10

default void createTopic(String topicName, int partitions, short replicas) {
try (Admin admin = createAdminClient()) {
admin.createTopics(Collections.singletonList(new NewTopic(topicName, partitions, replicas)));
Copy link
Contributor

Choose a reason for hiding this comment

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

why not calling the wait?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no specific reason.
Personally, I prefer user to waitTopic explicitly.
I am also fine to sync topic implicitly, just rename to CreateTopicWithSync.
WDYT?

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 "helper" method, so I feel a little sugar is good to users. We can add comments to this helper to remind users that this method is blocked until metadata get synced.

Copy link
Contributor Author

@TaiJuWu TaiJuWu Aug 29, 2024

Choose a reason for hiding this comment

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

Thanks for your explanation and review, updated.

clusterInstance.createTopic(topicName, partitions, replicas);

try (Admin admin = clusterInstance.createAdminClient()) {
Assertions.assertTrue(admin.listTopics().listings().get().stream().anyMatch(s -> s.name().equals(topicName)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the partition and replica also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks for review.

@chia7712 chia7712 merged commit 8f4d856 into apache:trunk Aug 31, 2024
1 check failed
@TaiJuWu TaiJuWu deleted the clusterTool branch August 31, 2024 15:27
bboyleonp666 pushed a commit to bboyleonp666/kafka that referenced this pull request Sep 4, 2024
…6852)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
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.

2 participants