Skip to content

Commit

Permalink
ZOOKEEPER-4846: Failure to reload database due to missing ACL
Browse files Browse the repository at this point in the history
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 8532163)
Signed-off-by: Andor Molnar <andor@apache.org>
  • Loading branch information
anmolnar committed Feb 11, 2025
1 parent de7e770 commit 281b5ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 281b5ff

Please sign in to comment.