You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xi...@apache.org on 2022/12/08 06:38:06 UTC
[pulsar] branch branch-2.10 updated: [improve][broker] Support setting `ForceDeleteNamespaceAllowed` dynamically (#18181)
This is an automated email from the ASF dual-hosted git repository.
xiangying pushed a commit to branch branch-2.10
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/branch-2.10 by this push:
new b071daf6f88 [improve][broker] Support setting `ForceDeleteNamespaceAllowed` dynamically (#18181)
b071daf6f88 is described below
commit b071daf6f88ce8b4d0adc7918b0171b15881be47
Author: Jiwei Guo <te...@apache.org>
AuthorDate: Tue Oct 25 22:07:13 2022 +0800
[improve][broker] Support setting `ForceDeleteNamespaceAllowed` dynamically (#18181)
(cherry picked from commit ae0153c4374751e89f9e6222de63068026b93cfd)
---
.../apache/pulsar/broker/ServiceConfiguration.java | 1 +
.../pulsar/broker/service/BrokerServiceTest.java | 36 ++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
index 05a24166c88..a943fba356b 100644
--- a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+++ b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
@@ -574,6 +574,7 @@ public class ServiceConfiguration implements PulsarConfiguration {
@FieldContext(
category = CATEGORY_POLICIES,
+ dynamic = true,
doc = "Allow forced deletion of namespaces. Default is false."
)
private boolean forceDeleteNamespaceAllowed = false;
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
index 193e56ea4a2..0087f4efd8f 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/BrokerServiceTest.java
@@ -86,11 +86,13 @@ import org.apache.pulsar.client.api.ProducerBuilder;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.SubscriptionInitialPosition;
import org.apache.pulsar.client.api.SubscriptionType;
import org.apache.pulsar.client.impl.ConnectionPool;
import org.apache.pulsar.client.impl.PulsarServiceNameResolver;
import org.apache.pulsar.client.impl.auth.AuthenticationTls;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
+import org.apache.pulsar.common.events.EventsTopicNames;
import org.apache.pulsar.common.naming.NamespaceBundle;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.naming.TopicName;
@@ -1348,4 +1350,38 @@ public class BrokerServiceTest extends BrokerTestBase {
assertTrue(brokerService.isSystemTopic("persistent://" + heartbeatNamespaceV1.toString() + "/healthcheck"));
assertTrue(brokerService.isSystemTopic(heartbeatNamespaceV2.toString() + "/healthcheck"));
}
+
+ @Test
+ public void testGetTopic() throws Exception {
+ final String ns = "prop/ns-test";
+ admin.namespaces().createNamespace(ns, 2);
+ final String topicName = ns + "/topic-1";
+ admin.topics().createNonPartitionedTopic(String.format("persistent://%s", topicName));
+ Producer<String> producer1 = pulsarClient.newProducer(Schema.STRING).topic(topicName).create();
+ producer1.close();
+ PersistentTopic persistentTopic = (PersistentTopic) pulsar.getBrokerService().getTopic(topicName.toString(), false).get().get();
+ persistentTopic.close().join();
+ List<String> topics = new ArrayList<>(pulsar.getBrokerService().getTopics().keys());
+ topics.removeIf(item -> item.contains(EventsTopicNames.NAMESPACE_EVENTS_LOCAL_NAME));
+ Assert.assertEquals(topics.size(), 0);
+ @Cleanup
+ Consumer<String> consumer = pulsarClient.newConsumer(Schema.STRING)
+ .topic(topicName)
+ .subscriptionName("sub-1")
+ .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
+ .subscriptionType(SubscriptionType.Shared)
+ .subscribe();
+ }
+
+ @Test
+ public void testDynamicConfigurationsForceDeleteNamespaceAllowed() throws Exception {
+ cleanup();
+ conf.setForceDeleteNamespaceAllowed(false);
+ setup();
+ admin.brokers()
+ .updateDynamicConfiguration("forceDeleteNamespaceAllowed", "true");
+ Awaitility.await().untilAsserted(()->{
+ assertTrue(conf.isForceDeleteNamespaceAllowed());
+ });
+ }
}