I have a type of locking mechanism using ephemerals via Curator framework, they are created with with creatingParentsIfNeeded. The whole tree disappears when the last ephemeral leaf node is removed. Parent nodes have an IP address as value.
Code snip from our class: CreateModable<ACLBackgroundPathAndBytesable<String>> localCreateMethod = createMethod.get(); if (localCreateMethod == null) { CreateBuilderMain createBuilder = cfClient.create(); CreateModable<ACLBackgroundPathAndBytesable<String>> tempCreateMethod = createBuilder.creatingParentContainersIfNeeded(); createMethod.compareAndSet(null, tempCreateMethod); localCreateMethod = createMethod.get(); } try { localCreateMethod.withMode(CreateMode.EPHEMERAL).inBackground(backgroundCallback).forPath(basePath, getEncryptedBytes(commandNode.getNodeBytes())); } catch (Exception e) { log.error("Exception: ", e); } [zk: localhost:2181(CONNECTED) 1] get /GROUP_V7POC03/ephemerals/inquirylock 10.194.54.93 [zk: localhost:2181(CONNECTED) 2] stat /GROUP_V7POC03/ephemerals/inquirylock cZxid = 0xf20001914e ctime = Tue Feb 04 11:11:45 CET 2020 mZxid = 0xf200019169 mtime = Tue Feb 04 11:11:48 CET 2020 pZxid = 0xf20001918b cversion = 2 dataVersion = 3 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 12 numChildren = 2 [zk: localhost:2181(CONNECTED) 3] get /GROUP_V7POC03/ephemerals/inquirylock 10.194.54.93 [zk: localhost:2181(CONNECTED) 4] get /GROUP_V7POC03/ephemerals [zk: localhost:2181(CONNECTED) 5] stat /GROUP_V7POC03/ephemerals/inquirylock/lrv1705f.europe.intranet:v7poc03 cZxid = 0xf200019189 ctime = Tue Feb 04 11:11:51 CET 2020 mZxid = 0xf200019189 mtime = Tue Feb 04 11:11:51 CET 2020 pZxid = 0xf200019189 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x10022c4e19c000b dataLength = 83 numChildren = 0 On 4 February 2020 15:58:39 Jordan Zimmerman <jor...@jordanzimmerman.com> wrote: >> can I implement a lock recipe which just >> tries to create ephemeral node without any persistent nodes. > > Ephemeral nodes cannot have any children. Unless you create your lock at > the root ("/") you'd need some parent persistent node. Is this a big > problem for you? Unless you have 1000s of unique lock paths there shouldn't > be any problem with persistent parent node. > > -Jordan