This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 60c570b Fix system topic can not auto created (#9272)
60c570b is described below
commit 60c570b87f7b12f91b65e759636d5a710c5dd36d
Author: feynmanlin <[email protected]>
AuthorDate: Tue Jan 26 12:06:03 2021 +0800
Fix system topic can not auto created (#9272)
Fixes #9265
### Motivation
If disabled the topic auto-creation, the system topic under the namespace
also not able to be created automatically, this will result in the topic level
policy not able to use.
### Modifications
Make the system topic be automatically created at any time
---
.../org/apache/pulsar/broker/service/BrokerService.java | 6 ++++++
.../org/apache/pulsar/broker/admin/TopicPoliciesTest.java | 14 ++++++++++++++
2 files changed, 20 insertions(+)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
index 053ee69..9cc2bcc 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
@@ -127,6 +127,7 @@ import org.apache.pulsar.client.impl.PulsarClientImpl;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
import org.apache.pulsar.common.allocator.PulsarByteBufAllocator;
import org.apache.pulsar.common.configuration.FieldContext;
+import org.apache.pulsar.common.events.EventsTopicNames;
import org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor;
import org.apache.pulsar.common.intercept.BrokerEntryMetadataInterceptor;
import org.apache.pulsar.common.intercept.BrokerEntryMetadataUtils;
@@ -2420,6 +2421,11 @@ public class BrokerService implements Closeable,
ZooKeeperCacheListener<Policies
}
public boolean isAllowAutoTopicCreation(final TopicName topicName) {
+ //System topic can always be created automatically
+ if
(EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME.equals(topicName.getLocalName())
+ && pulsar.getConfiguration().isSystemTopicEnabled()) {
+ return true;
+ }
AutoTopicCreationOverride autoTopicCreationOverride =
getAutoTopicCreationOverride(topicName);
if (autoTopicCreationOverride != null) {
return autoTopicCreationOverride.allowAutoTopicCreation;
diff --git
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
index 2b452e5..7cb65f2 100644
---
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
+++
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
@@ -1433,4 +1433,18 @@ public class TopicPoliciesTest extends
MockedPulsarServiceBaseTest {
->
assertNull(admin.topics().getReplicatorDispatchRate(topic)));
}
+ @Test(timeOut = 30000)
+ public void testAutoCreationDisabled() throws Exception {
+ cleanup();
+ conf.setAllowAutoTopicCreation(false);
+ setup();
+ final String topic = testTopic + UUID.randomUUID();
+ admin.topics().createPartitionedTopic(topic, 3);
+ pulsarClient.newProducer().topic(topic).create().close();
+ Awaitility.await().atMost(5, TimeUnit.SECONDS)
+ .until(() ->
pulsar.getTopicPoliciesService().cacheIsInitialized(TopicName.get(topic)));
+ //should not fail
+ assertNull(admin.topics().getMessageTTL(topic));
+ }
+
}