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

andor pushed a commit to branch branch-3.9
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/branch-3.9 by this push:
     new 4c889a231 ZOOKEEPER-4846: Failure to reload database due to missing ACL
4c889a231 is described below

commit 4c889a23186dd898f8d54c26f71acc6f977969f9
Author: Andor Molnár <an...@apache.org>
AuthorDate: Tue Feb 11 10:43:20 2025 -0600

    ZOOKEEPER-4846: Failure to reload database due to missing ACL
    
    ZOOKEEPER-4846. Fix ACL reference on existing znode when trying to create
    Reviewers: cnauroth, eolivelli, ztzg
    Author: anmolnar
    Closes #2222 from anmolnar/ZOOKEEPER-4846
    
    (cherry picked from commit 8532163df198466913f26141c0278dc11dbf53ab)
    Signed-off-by: Andor Molnar <an...@apache.org>
---
 .../main/java/org/apache/zookeeper/server/DataTree.java  |  5 +++--
 .../java/org/apache/zookeeper/server/DataTreeTest.java   | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java 
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
index 3b61c80d8..af937f834 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
@@ -462,8 +462,9 @@ public void createNode(final String path, byte[] data, 
List<ACL> acl, long ephem
             // we did for the global sessions.
             Long acls = aclCache.convertAcls(acl);
 
-            Set<String> children = parent.getChildren();
-            if (children.contains(childName)) {
+            DataNode existingChild = nodes.get(path);
+            if (existingChild != null) {
+                existingChild.acl = acls;
                 throw new NodeExistsException();
             }
 
diff --git 
a/zookeeper-server/src/test/java/org/apache/zookeeper/server/DataTreeTest.java 
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/DataTreeTest.java
index 07a69f14f..fc20ed320 100644
--- 
a/zookeeper-server/src/test/java/org/apache/zookeeper/server/DataTreeTest.java
+++ 
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/DataTreeTest.java
@@ -23,6 +23,7 @@
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -631,6 +632,21 @@ public void testDigest() throws Exception {
         }
     }
 
+    @Test
+    public void testCreateNodeFixMissingACL() throws Exception {
+        DataTree dt = new DataTree();
+        ReferenceCountedACLCache aclCache = dt.getReferenceCountedAclCache();
+
+        dt.createNode("/the_parent", new byte[0], ZooDefs.Ids.CREATOR_ALL_ACL, 
-1, 1, 1, 0);
+        Long aclId = dt.getNode("/the_parent").acl;
+        aclCache.removeUsage(aclId);
+        aclCache.purgeUnused();
+        // try to re-create the parent -> throws NodeExistsException, but 
fixes the deleted ACL
+        assertThrows(NodeExistsException.class, () ->
+            dt.createNode("/the_parent", new byte[0], 
ZooDefs.Ids.CREATOR_ALL_ACL, -1, 1, 1, 0));
+        dt.createNode("/the_parent/the_child", new byte[0], 
ZooDefs.Ids.CREATOR_ALL_ACL, -1, 2, 2, 2);
+    }
+
     private DataTree buildDataTreeForTest() {
         final DataTree dt = new DataTree();
         assertEquals(dt.lastProcessedZxid, 0);

Reply via email to