GrantPSpencer commented on code in PR #2607:
URL: https://github.com/apache/helix/pull/2607#discussion_r1312382899


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -115,6 +117,42 @@ public void create(String key, Object data, 
MetaClientInterface.EntryMode mode)
     }
   }
 
+  @Override
+  public void recursiveCreate(String key, T data, EntryMode mode) {
+    recursiveCreateHelper(key, data, mode, -1);
+  }
+
+  @Override
+  public void recursiveCreateWithTTL(String key, T data, long ttl) {
+    recursiveCreateHelper(key, data, EntryMode.TTL, ttl);
+  }
+
+  private void recursiveCreateHelper(String key, T data, EntryMode mode, long 
ttl) {
+    boolean retry;
+    // Ephemeral nodes cannot have children, so we will create PERSISTENT 
nodes as the parents
+    EntryMode parentMode = (EntryMode.EPHEMERAL.equals(mode) ?
+        EntryMode.PERSISTENT : mode);
+
+    do {
+      retry = false;
+      try {
+        if (EntryMode.TTL.equals(mode)) {
+          createWithTTL(key, data, ttl);
+        } else {
+          create(key, data, mode);
+        }
+      // If create fails due to parent node not existing, then call recursion 
on the parent path
+      // and retry create call. We only accept failures due to missing parent 
node, so do not retry
+      // on other errors.
+      } catch (MetaClientNoNodeException e) {
+        String parentPath = getZkParentPath(key);
+        recursiveCreateHelper(parentPath, null, parentMode, ttl);

Review Comment:
   @junkaixue I added two iterative alternatives, let me know which one you 
prefer and I'll delete the other. First maybe faster, but second is more 
readable
   iterativeCreateHelper and iterativeCreateHelperTwo



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to