Skip to content

[CURATOR-357] creatingParentsIfNeeded do not create "/" #877

@jira-importer

Description

@jira-importer

In Zookeeper there is no guaranty that "/" would exist. In a case when chroot feature is used, "/" path may not exists.
Currently Curator incorrectly assumes that "/" always exists. It leads to NoNodeException when there is no "/" available.
E.g. see CURATOR-280 for example.
A solution would be to create "/" in ZKPaths#mkdirs.
Primary concern is that it would slow down general case when entity name do not have path separator. Currently it does not require any additional calls, now "/" check would be needed.
A solution can be to change logic to create parents only if NoNode received for node creation call. This would also speed up all the cases where entity name has separator, including when namespaces are used.

Test:

public class TestChroot {
    private TestingServer server = new TestingServer();
<span class="code-keyword">public</span> TestChroot() <span class="code-keyword">throws</span> Exception {
}

@Test
<span class="code-keyword">public</span> void testCurator() <span class="code-keyword">throws</span> Exception {

CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString() + "/chrootCurator", new RetryOneTime(1000));
client.start();
client.create().creatingParentsIfNeeded().forPath("/test", new byte[]{1});
Assert.assertEquals(1, client.getData().forPath("/test")[0]);
}

@Test
<span class="code-keyword">public</span> void testZookeeper() <span class="code-keyword">throws</span> Exception {

CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString() + "/chrootZoo", new RetryOneTime(1000));
client.start();
ZooKeeper zooKeeper = client.getZookeeperClient().getZooKeeper();
zooKeeper.create("/", new byte[]{}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zooKeeper.create("/test", new byte[]{1}, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Assert.assertEquals(1, client.getData().forPath("/test")[0]);
}
}


Originally reported by tivv, imported from: creatingParentsIfNeeded do not create "/"
  • status: Closed
  • priority: Major
  • resolution: Won't Fix
  • resolved: 2023-05-10T11:56:20+01:00
  • imported: 2025-01-21

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions