You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2023/01/06 00:25:57 UTC

[GitHub] [helix] Marcosrico commented on a diff in pull request #2327: Meta client - implement CRUD for zkMetaClient

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


##########
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:
   Given that the `MetaClientException` is caught in the `translateZkExceptionToMetaclientException` method, what is the reason for not using the latter all the time? I assume readability is better if the exception is known to be a general one but perhaps then we would want to remain consistent with the other errors and catch/throw each individual type. Just a thought



-- 
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: reviews-unsubscribe@helix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org