-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
Outdated
Show resolved
Hide resolved
@@ -2580,8 +2582,19 @@ private boolean isSystemTopic(String topic) { | |||
} | |||
} | |||
|
|||
public CompletableFuture<Void> deleteTopicPolicies(TopicName topicName) { | |||
if (!pulsar().getConfig().isTopicLevelPoliciesEnabled()) { | |||
return new CompletableFuture<>(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right.
There was a problem hiding this comment.
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)"
There was a problem hiding this comment.
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. :)
There was a problem hiding this 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
.
fine. |
Hi, the ut have completed, PTAL and give some advice :) |
Awaitility.await().until(() -> pulsar.getTopicPoliciesService().getTopicPolicies(TopicName.get(topic)) != null); | ||
assertNotNull(pulsar.getTopicPoliciesService().getTopicPolicies(TopicName.get(topic))); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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?
TopicName cloneTopicName = topicName; | ||
if (topicName.isPartitioned()) { | ||
cloneTopicName = TopicName.get(topicName.getPartitionedTopicName()); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right.
There was a problem hiding this comment.
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
...ker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
Show resolved
Hide resolved
@eolivelli Can you please review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(cherry picked from commit 00f8e57)
Fixes #11308