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
  • Loading branch information
anmolnar authored Feb 11, 2025
1 parent a8eb7fa commit 8532163
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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 @@ -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);
Expand Down

0 comments on commit 8532163

Please sign in to comment.