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


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -49,55 +61,97 @@ public ZkMetaClient(ZkMetaClientConfig config) {
   }
 
   @Override
-  public void create(String key, Object data) {
-
+  public void create(String key, T data) {
+    // TODO: This function is implemented only for test. It does not have 
proper error handling
+    _zkClient.create(key, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, 
CreateMode.PERSISTENT);
   }
 
   @Override
-  public void create(String key, Object data, EntryMode mode) {
+  public void create(String key, T data, EntryMode mode) {
 
   }
 
   @Override
-  public void set(String key, Object data, int version) {
-
+  public void set(String key, T data, int version) {
+    try {
+      _zkClient.writeData(key, data, version);
+    } catch (ZkException e) {
+      throw translateZkExceptionToMetaclientException(e);
+    }
   }
 
   @Override
-  public Object update(String key, DataUpdater updater) {
-    return null;
+  public T update( String key, DataUpdater<T> updater) {
+    org.apache.zookeeper.data.Stat stat = new org.apache.zookeeper.data.Stat();
+    // TODO: add retry logic for ZkBadVersionException.
+    try {
+      T oldData = _zkClient.readData(key, stat);
+      T newData = updater.update(oldData);
+      set(key, newData, stat.getVersion());
+      return newData;
+    } catch (ZkException e) {
+      throw translateZkExceptionToMetaclientException(e);
+    }
   }
 
   @Override
   public Stat exists(String key) {
-    return null;
+    org.apache.zookeeper.data.Stat zkStats;
+    try {
+      zkStats = _zkClient.getStat(key);
+      if (zkStats == null) {
+        return null;
+      }
+      return new Stat(EphemeralType.get(zkStats.getEphemeralOwner()) == 
EphemeralType.VOID
+          ? EntryMode.PERSISTENT : EntryMode.EPHEMERAL, zkStats.getVersion());
+    } catch (ZkException e) {
+      throw translateZkExceptionToMetaclientException(e);
+    }
   }
 
   @Override
-  public Object get(String key) {
-    return null;
+  public T get(String key) {
+    return _zkClient.readData(key, true);
   }
 
   @Override
-  public List<String> getDirestChildrenKeys(String key) {
+  public List<OpResult> transactionOP(Iterable<Op> ops) {
     return null;
   }
 
   @Override
-  public int countDirestChildren(String key) {
-    return 0;
+  public List<String> getDirectChildrenKeys(String key) {
+    try {
+      return _zkClient.getChildren(key);
+    } catch (ZkException e) {
+      throw new MetaClientException(e);
+    }
+  }
+
+  @Override
+  public int countDirectChildren(String key) {
+    return _zkClient.countChildren(key);
   }
 
   @Override
   public boolean delete(String key) {
-    return false;
+    try {
+      return _zkClient.delete(key);
+    } catch (ZkException e) {
+      throw new MetaClientException(e);

Review Comment:
   Good catch. I was planning to use 
`translateZkExceptionToMetaclientException` and it is a typo. :D



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