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/18 23:29:45 UTC

[GitHub] [helix] desaikomal commented on a diff in pull request #2343: ZkMetaclient - implementation of TransactionOp

desaikomal commented on code in PR #2343:
URL: https://github.com/apache/helix/pull/2343#discussion_r1080665623


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -414,4 +414,130 @@ private static EntryMode convertZkEntryMode(long ephemeralOwner) {
         throw new IllegalArgumentException(zkEphemeralType + " is not supported.");
     }
   }
+
+
+  @Override
+  public List<OpResult> transactionOP(Iterable<Op> iterable) throws KeeperException {
+    // Convert list of MetaClient Ops to Zk Ops
+    List<org.apache.zookeeper.Op> zkOps = metaClientOpToZk(iterable);
+    // Execute Zk transactional support
+    List<org.apache.zookeeper.OpResult> zkResult = _zkClient.multi(zkOps);
+    // Convert list of Zk OpResults to MetaClient OpResults
+    return zkOpResultToMetaClient(zkResult);
+  }
+
+  /**
+   * Helper function for transactionOp. Converts MetaClient Op's into Zk Ops to execute
+   * zk transactional support.
+   * @param ops
+   * @return
+   */
+  public List<org.apache.zookeeper.Op> metaClientOpToZk(Iterable<Op> ops) throws KeeperException {
+    List<org.apache.zookeeper.Op> zkOps = new ArrayList<>();
+    org.apache.zookeeper.Op temp;
+    for (Op op : ops) {
+      switch (op.getType()) {
+        case CREATE:
+          int zkFlag = zkFlagFromEntryMode(((Op.Create) op).getEntryMode());

Review Comment:
   this seems like double time evaluation. You want to pass CreateMode type. Can you not have a simple enum which you can pass directly? You are anyway, hardcoding to Op.Create, so why not pass that enum directly. We don't want to create code complexity if passing something directly saves CPU cycles. 



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -414,4 +414,130 @@ private static EntryMode convertZkEntryMode(long ephemeralOwner) {
         throw new IllegalArgumentException(zkEphemeralType + " is not supported.");
     }
   }
+
+
+  @Override
+  public List<OpResult> transactionOP(Iterable<Op> iterable) throws KeeperException {
+    // Convert list of MetaClient Ops to Zk Ops
+    List<org.apache.zookeeper.Op> zkOps = metaClientOpToZk(iterable);
+    // Execute Zk transactional support
+    List<org.apache.zookeeper.OpResult> zkResult = _zkClient.multi(zkOps);
+    // Convert list of Zk OpResults to MetaClient OpResults
+    return zkOpResultToMetaClient(zkResult);
+  }
+
+  /**
+   * Helper function for transactionOp. Converts MetaClient Op's into Zk Ops to execute
+   * zk transactional support.
+   * @param ops
+   * @return
+   */
+  public List<org.apache.zookeeper.Op> metaClientOpToZk(Iterable<Op> ops) throws KeeperException {
+    List<org.apache.zookeeper.Op> zkOps = new ArrayList<>();
+    org.apache.zookeeper.Op temp;
+    for (Op op : ops) {
+      switch (op.getType()) {
+        case CREATE:
+          int zkFlag = zkFlagFromEntryMode(((Op.Create) op).getEntryMode());
+          temp = org.apache.zookeeper.Op.create(
+              op.getPath(), ((Op.Create) op).getData(), DEFAULT_ACL, CreateMode.fromFlag(zkFlag));
+          break;
+        case DELETE:
+          temp = org.apache.zookeeper.Op.delete(
+              op.getPath(), ((Op.Delete) op).getVersion());
+          break;
+        case SET:
+          temp = org.apache.zookeeper.Op.setData(
+              op.getPath(), ((Op.Set) op).getData(), ((Op.Set) op).getVersion());
+          break;
+        case CHECK:
+          temp = org.apache.zookeeper.Op.check(
+              op.getPath(), ((Op.Check) op).getVersion());
+          break;
+        default:
+          throw new IllegalArgumentException(op.getType() + " is not supported.");
+      }
+      zkOps.add(temp);
+    }
+    return zkOps;
+  }
+
+  /**
+   * Helper function for transactionOP. Converts the result from calling zk transactional support into
+   * metaclient OpResults.
+   * @param zkResult
+   * @return
+   */
+  public List<OpResult> zkOpResultToMetaClient(List<org.apache.zookeeper.OpResult> zkResult) throws KeeperException.BadArgumentsException {

Review Comment:
   ditto.



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -414,4 +414,130 @@ private static EntryMode convertZkEntryMode(long ephemeralOwner) {
         throw new IllegalArgumentException(zkEphemeralType + " is not supported.");
     }
   }
+
+
+  @Override
+  public List<OpResult> transactionOP(Iterable<Op> iterable) throws KeeperException {
+    // Convert list of MetaClient Ops to Zk Ops
+    List<org.apache.zookeeper.Op> zkOps = metaClientOpToZk(iterable);
+    // Execute Zk transactional support
+    List<org.apache.zookeeper.OpResult> zkResult = _zkClient.multi(zkOps);
+    // Convert list of Zk OpResults to MetaClient OpResults
+    return zkOpResultToMetaClient(zkResult);
+  }
+
+  /**
+   * Helper function for transactionOp. Converts MetaClient Op's into Zk Ops to execute
+   * zk transactional support.
+   * @param ops
+   * @return
+   */
+  public List<org.apache.zookeeper.Op> metaClientOpToZk(Iterable<Op> ops) throws KeeperException {

Review Comment:
   you changed exception from KeeperException to IllegalArgument.
   
   so is this still required?



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