This is an automated email from the ASF dual-hosted git repository.

xyz 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 3c6f31f  Cleanup znode data when namespace deleted (#11791)
3c6f31f is described below

commit 3c6f31ff068ef3dc266b1a81b0919fb1f5515607
Author: gaozhangmin <[email protected]>
AuthorDate: Sat Aug 28 01:20:08 2021 +0800

    Cleanup znode data when namespace deleted (#11791)
    
    Fixes #11734
    
    ### Motivation
    
    Now, forcely delete namespace  would  delete 
`/managed-ledger/tenant/namespace` `/admin/partitioned-topic/tenant/namespace`  
znode, but  `/namespace/tenant/namespace` still is uncleaned
    
    For non-force delete, these all znode would not be cleaned, I think we 
should also clean up these znode.
    
    ### Modifications
    
    delete these znode  after namespace delete
    
    Co-authored-by: gavingaozhangmin <[email protected]>
---
 .../pulsar/broker/admin/impl/NamespacesBase.java   | 36 ++++++++++++++++++++++
 .../broker/cache/LocalZooKeeperCacheService.java   |  2 +-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
index eb27521..e70e230 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
@@ -23,6 +23,8 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
 import static 
org.apache.pulsar.broker.cache.ConfigurationCacheService.POLICIES;
 import static 
org.apache.pulsar.broker.cache.ConfigurationCacheService.RESOURCEGROUPS;
 import static 
org.apache.pulsar.broker.cache.LocalZooKeeperCacheService.LOCAL_POLICIES_ROOT;
+import static 
org.apache.pulsar.broker.cache.LocalZooKeeperCacheService.MANAGED_LEDGER_ROOT;
+import static 
org.apache.pulsar.broker.cache.LocalZooKeeperCacheService.OWNER_INFO_ROOT;
 import static 
org.apache.pulsar.common.policies.data.PoliciesUtil.defaultBundle;
 import static org.apache.pulsar.common.policies.data.PoliciesUtil.getBundles;
 import com.google.common.collect.Lists;
@@ -306,11 +308,38 @@ public abstract class NamespacesBase extends 
AdminResource {
             }
 
             try {
+                final String globalPartitionedPath = 
path(PARTITIONED_TOPIC_PATH_ZNODE, namespaceName.toString());
+                final String managedLedgerPath = joinPath(MANAGED_LEDGER_ROOT, 
namespaceName.toString());
+                // check whether partitioned topics znode exist
+                if (namespaceResources().exists(globalPartitionedPath)) {
+                    deleteRecursive(namespaceResources(), 
globalPartitionedPath);
+                }
+
+                try {
+                    if (namespaceResources().exists(managedLedgerPath)) {
+                        pulsar().getPulsarResources().getTopicResources()
+                                .clearDomainPersistence(namespaceName).get();
+                        pulsar().getPulsarResources().getTopicResources()
+                                
.clearNamespacePersistence(namespaceName).get();
+                    }
+                } catch (ExecutionException | InterruptedException e) {
+                    // warn level log here since this failure has no side 
effect besides left a un-used metadata
+                    // and also will not affect the re-creation of namespace
+                    log.warn("[{}] Failed to remove managed-ledger for {}", 
clientAppId(), namespaceName, e);
+                }
                 // we have successfully removed all the ownership for the 
namespace, the policies znode can be deleted
                 // now
                 final String globalZkPolicyPath = path(POLICIES, 
namespaceName.toString());
                 final String localZkPolicyPath = joinPath(LOCAL_POLICIES_ROOT, 
namespaceName.toString());
+                final String namespacePath = joinPath(OWNER_INFO_ROOT, 
namespaceName.toString());
                 namespaceResources().delete(globalZkPolicyPath);
+
+                try {
+                    namespaceResources().delete(namespacePath);
+                } catch (NotFoundException e) {
+                    // If the z-node with the modified information is not 
there anymore, we're already good
+                }
+
                 try {
                     getLocalPolicies().delete(localZkPolicyPath);
                 } catch (NotFoundException nne) {
@@ -501,9 +530,16 @@ public abstract class NamespacesBase extends AdminResource 
{
                 // now
                 final String globalZkPolicyPath = path(POLICIES, 
namespaceName.toString());
                 final String localZkPolicyPath = joinPath(LOCAL_POLICIES_ROOT, 
namespaceName.toString());
+                final String namespacePath = joinPath(OWNER_INFO_ROOT, 
namespaceName.toString());
                 namespaceResources().delete(globalZkPolicyPath);
 
                 try {
+                    namespaceResources().delete(namespacePath);
+                } catch (NotFoundException e) {
+                    // If the z-node with the modified information is not 
there anymore, we're already good
+                }
+
+                try {
                     getLocalPolicies().delete(localZkPolicyPath);
                 } catch (NotFoundException nne) {
                     // If the z-node with the modified information is not 
there anymore, we're already good
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/cache/LocalZooKeeperCacheService.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/cache/LocalZooKeeperCacheService.java
index a48c3f0..01cdb70 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/cache/LocalZooKeeperCacheService.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/cache/LocalZooKeeperCacheService.java
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
 public class LocalZooKeeperCacheService {
     private static final Logger LOG = 
LoggerFactory.getLogger(LocalZooKeeperCacheService.class);
 
-    private static final String MANAGED_LEDGER_ROOT = "/managed-ledgers";
+    public static final String MANAGED_LEDGER_ROOT = "/managed-ledgers";
     public static final String OWNER_INFO_ROOT = "/namespace";
     public static final String LOCAL_POLICIES_ROOT = "/admin/local-policies";
     public static final String AVAILABLE_BOOKIES_ROOT = "/ledgers/available";

Reply via email to