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

When delete a topic, delete the topic policy together. #11316

Merged
merged 11 commits into from
Jul 20, 2021

Conversation

horizonzy
Copy link
Member

Fixes #11308

@@ -2580,8 +2582,19 @@ private boolean isSystemTopic(String topic) {
}
}

public CompletableFuture<Void> deleteTopicPolicies(TopicName topicName) {
if (!pulsar().getConfig().isTopicLevelPoliciesEnabled()) {
return new CompletableFuture<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to return a completed future?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure return completed future is the best way, so followed the origin code style, return completed fusture. I will modify it.

Copy link
Member Author

@horizonzy horizonzy Jul 15, 2021

Choose a reason for hiding this comment

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

Finally, I maintain the complete fusture way. I think use complete future is more suitable for this method. Cound you give some advice.

Copy link
Contributor

Choose a reason for hiding this comment

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

@horizonzy I think you need a completed CompletableFuture right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the new CompletableFuture should be completed. Such as CompletableFuture.completedFuture(null);

Copy link
Member Author

Choose a reason for hiding this comment

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

right.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I wasn't clear.
I was suggesting to return "CompletableFuture.completedFuture(null)"

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, I wasn't clear.
I was suggesting to return "CompletableFuture.completedFuture(null)"

My fault, I misunderstand it. :)

Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

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

@horizonzy Could you please help add some unit tests for the change? You can refer to TopicPoliciesTest.

@horizonzy
Copy link
Member Author

@horizonzy Could you please help add some unit tests for the change? You can refer to TopicPoliciesTest.

fine.

@horizonzy
Copy link
Member Author

@horizonzy Could you please help add some unit tests for the change? You can refer to TopicPoliciesTest.

Hi, the ut have completed, PTAL and give some advice :)

Comment on lines 2410 to 2411
Awaitility.await().until(() -> pulsar.getTopicPoliciesService().getTopicPolicies(TopicName.get(topic)) != null);
assertNotNull(pulsar.getTopicPoliciesService().getTopicPolicies(TopicName.get(topic)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be simplified to Awaitility.await().untilAssert()

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -2395,4 +2395,31 @@ public void testTopicRetentionPolicySetInManagedLedgerConfig() throws Exception
});
}

@Test
public void testPolicyIsDeleteTogether() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a test for covering the topic auto-deletion case.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -2580,8 +2582,19 @@ private boolean isSystemTopic(String topic) {
}
}

public CompletableFuture<Void> deleteTopicPolicies(TopicName topicName) {
if (!pulsar().getConfig().isTopicLevelPoliciesEnabled()) {
return new CompletableFuture<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

@horizonzy I think you need a completed CompletableFuture right?

Comment on lines 2588 to 2591
TopicName cloneTopicName = topicName;
if (topicName.isPartitioned()) {
cloneTopicName = TopicName.get(topicName.getPartitionedTopicName());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The method topicName.getPartitionedTopicName() already handled is the topic is a partition or not. so we don't need to check here.

Copy link
Member Author

Choose a reason for hiding this comment

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

right.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

…ait().until

2. add ut for delete policy on topic auto-delete

3.code clean.
# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
@sijie
Copy link
Member

sijie commented Jul 20, 2021

@eolivelli Can you please review this PR?

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@eolivelli eolivelli merged commit 00f8e57 into apache:master Jul 20, 2021
Technoboy- pushed a commit to Technoboy-/pulsar that referenced this pull request Jul 22, 2021
codelipenghui pushed a commit that referenced this pull request Jul 23, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Jul 23, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life release/2.8.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Topic Policy] Delete the topic policy for the topic when the topic been deleted.
6 participants