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


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -115,6 +117,61 @@ public void create(String key, Object data, 
MetaClientInterface.EntryMode mode)
     }
   }
 
+  @Override
+  public void createFullPath(String key, Object data, 
MetaClientInterface.EntryMode mode) {
+
+    boolean retry;
+    MetaClientInterface.EntryMode parentMode = 
(EntryMode.EPHEMERAL.equals(mode) ?
+        EntryMode.PERSISTENT : mode);
+    do {
+      retry = false;
+      try {
+        create(key, data, mode);
+      } catch (MetaClientNoNodeException e) {
+        retry = true;
+        String parentPath = getZkParentPath(key);
+        try {
+          createFullPath(parentPath, null, parentMode);
+        } catch (MetaClientNodeExistsException e1) {

Review Comment:
   Probably we dont need catch here?
   



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -115,6 +117,61 @@ public void create(String key, Object data, 
MetaClientInterface.EntryMode mode)
     }
   }
 
+  @Override
+  public void createFullPath(String key, Object data, 
MetaClientInterface.EntryMode mode) {
+
+    boolean retry;
+    MetaClientInterface.EntryMode parentMode = 
(EntryMode.EPHEMERAL.equals(mode) ?
+        EntryMode.PERSISTENT : mode);
+    do {
+      retry = false;
+      try {
+        create(key, data, mode);
+      } catch (MetaClientNoNodeException e) {
+        retry = true;
+        String parentPath = getZkParentPath(key);
+        try {
+          createFullPath(parentPath, null, parentMode);
+        } catch (MetaClientNodeExistsException e1) {
+          return;
+        }
+      } catch (MetaClientNodeExistsException e) {
+        LOG.warn("Node already exists. path: " + key);
+        throw e;
+      } catch (MetaClientException e) {
+        LOG.error("Exception while creating path: " + key, e);
+        throw e;
+      }
+    } while (retry);
+  }
+
+  @Override
+  public void createFullPathWithTTL(String key, T data, long ttl) {

Review Comment:
   These 2 logics seems a bit repetitive. We could have a helper function with 
options. 



##########
meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java:
##########
@@ -152,6 +152,15 @@ public Stat (EntryMode mode, int version, long ctime, long 
mtime, long etime) {
    */
   void create(final String key, final T data, final EntryMode mode);
 
+  /**
+   * Create an entry of given EntryMode with given key and data. If any parent 
node in the node
+   * hierarchy does not exist, then the parent node will attempt to be 
created. The entry will not be created if
+   * there is an existing entry with the same full key.
+   */
+  void createFullPath(final String key, final T Data, final EntryMode mode);

Review Comment:
   Since we have `deleteRecursively`, how about `createRecursively` ? 



-- 
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