jiajunwang commented on a change in pull request #1089:
URL: https://github.com/apache/helix/pull/1089#discussion_r439647566



##########
File path: helix-core/src/main/java/org/apache/helix/manager/zk/ZKUtil.java
##########
@@ -632,4 +634,39 @@ private static RealmAwareZkClient getHelixZkClient(String 
zkAddr) {
     return DedicatedZkClientFactory.getInstance()
         .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr), 
clientConfig);
   }
+
+  /**
+   * Convert Stat fields into a Map.
+   *     private long czxid;
+   *     private long mzxid;
+   *     private long ctime;
+   *     private long mtime;
+   *     private int version;
+   *     private int cversion;
+   *     private int aversion;
+   *     private long ephemeralOwner;
+   *     private int dataLength;
+   *     private int numChildren;
+   *     private long pzxid;
+   * @param stat
+   * @return
+   */
+  public static Map<String, String> fromStatToMap(Stat stat) {

Review comment:
       You might want to checkout this method of the Zookeeper Stat class, 
simply implement an OutputArchive to avoid hardcode getting fields here.
   
     public void serialize(OutputArchive a_, String tag) throws 
java.io.IOException {
       a_.startRecord(this,tag);
       a_.writeLong(czxid,"czxid");
       a_.writeLong(mzxid,"mzxid");
       a_.writeLong(ctime,"ctime");
       a_.writeLong(mtime,"mtime");
       a_.writeInt(version,"version");
       a_.writeInt(cversion,"cversion");
       a_.writeInt(aversion,"aversion");
       a_.writeLong(ephemeralOwner,"ephemeralOwner");
       a_.writeInt(dataLength,"dataLength");
       a_.writeInt(numChildren,"numChildren");
       a_.writeLong(pzxid,"pzxid");
       a_.endRecord(this,tag);
     }

##########
File path: 
helix-rest/src/main/java/org/apache/helix/rest/server/resources/zookeeper/ZooKeeperAccessor.java
##########
@@ -165,6 +179,24 @@ private Response getChildren(BaseDataAccessor<byte[]> 
zkBaseDataAccessor, String
     }
   }
 
+  /**
+   * Returns the ZNode Stat object given the path.
+   * @param zkBaseDataAccessor
+   * @param path
+   * @return
+   */
+  private Response getStat(BaseDataAccessor<byte[]> zkBaseDataAccessor, String 
path) {
+    if (zkBaseDataAccessor.exists(path, AccessOption.PERSISTENT)) {
+      Stat stat = zkBaseDataAccessor.getStat(path, AccessOption.PERSISTENT);

Review comment:
       I think getStat return null if the path does not exist. So you don't 
need to call exists before this line.




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

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