[ 
https://issues.apache.org/jira/browse/CURATOR-357?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Kezhu Wang updated CURATOR-357:
-------------------------------
    Issue Type: New Feature  (was: Bug)

> creatingParentsIfNeeded do not create "/"
> -----------------------------------------
>
>                 Key: CURATOR-357
>                 URL: https://issues.apache.org/jira/browse/CURATOR-357
>             Project: Apache Curator
>          Issue Type: New Feature
>          Components: Framework
>            Reporter: Vitalii Tymchyshyn
>            Priority: Major
>
> 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:
> {code}
> public class TestChroot {
>     private TestingServer server = new TestingServer();
>     public TestChroot() throws Exception {
>     }
>     @Test
>     public void testCurator() throws 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
>     public void testZookeeper() throws 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]);
>     }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to