-
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
Changes from 7 commits
0874a4f
4ee5f5d
9a05aee
2a4c941
92c9762
2e55ffc
2e5f284
2e74398
cc45b0d
f74bed9
ee0ceb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
import io.netty.channel.EventLoopGroup; | ||
import io.netty.channel.socket.SocketChannel; | ||
import io.netty.handler.ssl.SslContext; | ||
import io.netty.util.concurrent.CompleteFuture; | ||
import io.netty.util.concurrent.DefaultThreadFactory; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
|
@@ -2580,6 +2581,17 @@ public Optional<TopicPolicies> getTopicPolicies(TopicName topicName) { | |
} | ||
} | ||
|
||
public CompletableFuture<Void> deleteTopicPolicies(TopicName topicName) { | ||
if (!pulsar().getConfig().isTopicLevelPoliciesEnabled()) { | ||
return new CompletableFuture<>(); | ||
} | ||
TopicName cloneTopicName = topicName; | ||
if (topicName.isPartitioned()) { | ||
cloneTopicName = TopicName.get(topicName.getPartitionedTopicName()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
return pulsar.getTopicPoliciesService().deleteTopicPoliciesAsync(cloneTopicName); | ||
} | ||
|
||
private <T> boolean checkMaxTopicsPerNamespace(TopicName topicName, int numPartitions, | ||
CompletableFuture<T> topicFuture) { | ||
Integer maxTopicsPerNamespace; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
final String topic = testTopic + UUID.randomUUID(); | ||
pulsarClient.newProducer().topic(topic).create().close(); | ||
|
||
Awaitility.await() | ||
.until(() -> pulsar.getTopicPoliciesService().cacheIsInitialized(TopicName.get(topic))); | ||
assertNull(pulsar.getTopicPoliciesService().getTopicPolicies(TopicName.get(topic))); | ||
|
||
int maxConsumersPerSubscription = 10; | ||
admin.topics().setMaxConsumersPerSubscription(topic, maxConsumersPerSubscription); | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
|
||
Awaitility.await().until(() -> pulsar.getBrokerService().getTopic(topic, false).get().isPresent()); | ||
assertTrue(pulsar.getBrokerService().getTopic(topic, false).get().isPresent()); | ||
|
||
admin.topics().delete(topic); | ||
|
||
Awaitility.await().until(() -> !pulsar.getBrokerService().getTopic(topic, false).get().isPresent()); | ||
assertFalse(pulsar.getBrokerService().getTopic(topic, false).get().isPresent()); | ||
|
||
Awaitility.await().until(() -> pulsar.getTopicPoliciesService().getTopicPolicies(TopicName.get(topic)) == null); | ||
assertNull(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.
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 asCompletableFuture.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.
My fault, I misunderstand it. :)