This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch branch-3.8
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/branch-3.8 by this push:
new 281b5ff13 ZOOKEEPER-4846: Failure to reload database due to missing ACL
281b5ff13 is described below
commit 281b5ff13f000350fe88f186897eb7d4b4e1e0b6
Author: Andor Molnár <[email protected]>
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 <[email protected]>
---
.../main/java/org/apache/zookeeper/server/DataTree.java | 5 +++--
.../java/org/apache/zookeeper/server/DataTreeTest.java | 15 +++++++++++++++
2 files changed, 18 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 3febd7fd5..81789d642 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
@@ -467,8 +467,9 @@ public void createNode(final String path, byte[] data,
List<ACL> acl, long ephem
// we did for the global sessions.
Long longval = aclCache.convertAcls(acl);
- Set<String> children = parent.getChildren();
- if (children.contains(childName)) {
+ DataNode existingChild = nodes.get(path);
+ if (existingChild != null) {
+ existingChild.acl = longval;
throw new KeeperException.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 151e87343..7095aae11 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;
@@ -616,4 +617,18 @@ 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);
+ }
}