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 2020/03/02 23:55:25 UTC

[GitHub] [helix] jiajunwang opened a new pull request #845: Async write operation should not throw Exception for serializing error

jiajunwang opened a new pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845
 
 
   ### Issues
   
   - [ ] My PR addresses the following Helix issues and references them in the PR description:
   
   #805 
   
   ### Description
   
   - [ ] Here are some details about my PR, including screenshots of any UI changes:
   
   This change will make the async write operations return error through the async callback instead of throwing exceptions. This change will fix the batch write/create failure due to one single node serializing failure.
   In addition, according to serializer interface definition, change ZK related serializers to throw ZkMarshallingError instead of ZkClientException.
   
   ### Tests
   
   - [ ] The following tests are written for this issue:
   
   testAsyncWriteOperations
   
   - [ ] The following is the result of the "mvn test" command on the appropriate module:
   
   mvn test in progress
   
   ### Commits
   
   - [ ] My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation (Optional)
   
   - [ ] In case of new functionality, my PR adds documentation in the following wiki page:
   
   (Link the GitHub wiki you added)
   
   ### Code Quality
   
   - [ ] My diff has been formatted using helix-style.xml 
   (helix-style-intellij.xml if IntelliJ IDE is used)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386747374
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
+      Random ran = new Random();
+      for (int i = 0; i < 1024; i++) {
+        sb.append(ran.nextInt(26) + 'a');
+      }
+      String buf = sb.toString();
+      for (int i = 0; i < 1024; i++) {
+        oversizeZNRecord.setSimpleField(Integer.toString(i), buf);
+      }
+
+      // ensure /tmp exists for the test
+      if (!zkClient.exists("/tmp")) {
+        zkClient.create("/tmp", null, CreateMode.PERSISTENT);
+      }
+
+      org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler
+          createCallback = new org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler();
+      zkClient.asyncCreate("/tmp/async", null, CreateMode.PERSISTENT, createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), 0);
+
+      // try to create oversize node, should fail
+      zkClient.asyncCreate("/tmp/asyncOversize", oversizeZNRecord, CreateMode.PERSISTENT,
+          createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), KeeperException.Code.MarshallingError);
+
+      ZNRecord normalZNRecord = new ZNRecord("normal");
+      normalZNRecord.setSimpleField("key", buf);
+
+      org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.SetDataCallbackHandler
+          setDataCallbackHandler = new org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.SetDataCallbackHandler();
+      zkClient.asyncSetData("/tmp/async", normalZNRecord, -1, setDataCallbackHandler);
+      setDataCallbackHandler.waitForSuccess();
+      Assert.assertEquals(setDataCallbackHandler.getRc(), 0);
+
+      zkClient.asyncSetData("/tmp/async", oversizeZNRecord, -1, setDataCallbackHandler);
+      setDataCallbackHandler.waitForSuccess();
+      Assert.assertEquals(setDataCallbackHandler.getRc(), KeeperException.Code.MarshallingError);
+    } finally {
+      if (originSizeLimit == null) {
+        System.clearProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+      } else {
+        System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES,
+            originSizeLimit);
+      }
+      zkClient.delete("/tmp/async");
+      zkClient.delete("/tmp/asyncOversize");
 
 Review comment:
   It has been taken care of by after method call. And if the delete fails, there is nothing I can do except to fail the test. But it is not really this test is testing for. So let's don't over test here.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386741186
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
+      Random ran = new Random();
+      for (int i = 0; i < 1024; i++) {
+        sb.append(ran.nextInt(26) + 'a');
+      }
+      String buf = sb.toString();
+      for (int i = 0; i < 1024; i++) {
+        oversizeZNRecord.setSimpleField(Integer.toString(i), buf);
+      }
+
+      // ensure /tmp exists for the test
+      if (!zkClient.exists("/tmp")) {
+        zkClient.create("/tmp", null, CreateMode.PERSISTENT);
+      }
+
+      org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler
+          createCallback = new org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler();
+      zkClient.asyncCreate("/tmp/async", null, CreateMode.PERSISTENT, createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), 0);
+
+      // try to create oversize node, should fail
+      zkClient.asyncCreate("/tmp/asyncOversize", oversizeZNRecord, CreateMode.PERSISTENT,
+          createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), KeeperException.Code.MarshallingError);
+
+      ZNRecord normalZNRecord = new ZNRecord("normal");
+      normalZNRecord.setSimpleField("key", buf);
+
+      org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.SetDataCallbackHandler
+          setDataCallbackHandler = new org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.SetDataCallbackHandler();
+      zkClient.asyncSetData("/tmp/async", normalZNRecord, -1, setDataCallbackHandler);
+      setDataCallbackHandler.waitForSuccess();
+      Assert.assertEquals(setDataCallbackHandler.getRc(), 0);
+
+      zkClient.asyncSetData("/tmp/async", oversizeZNRecord, -1, setDataCallbackHandler);
+      setDataCallbackHandler.waitForSuccess();
+      Assert.assertEquals(setDataCallbackHandler.getRc(), KeeperException.Code.MarshallingError);
+    } finally {
+      if (originSizeLimit == null) {
+        System.clearProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+      } else {
+        System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES,
+            originSizeLimit);
+      }
+      zkClient.delete("/tmp/async");
+      zkClient.delete("/tmp/asyncOversize");
 
 Review comment:
   Nit: maybe it is good to use `verify()` and `Assert` to make sure the path is deleted? Do we also need to consider deleting "/tmp" if it did not exist originally as you would create it?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386744545
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
+      Random ran = new Random();
+      for (int i = 0; i < 1024; i++) {
+        sb.append(ran.nextInt(26) + 'a');
+      }
+      String buf = sb.toString();
+      for (int i = 0; i < 1024; i++) {
+        oversizeZNRecord.setSimpleField(Integer.toString(i), buf);
+      }
+
+      // ensure /tmp exists for the test
+      if (!zkClient.exists("/tmp")) {
+        zkClient.create("/tmp", null, CreateMode.PERSISTENT);
+      }
+
+      org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler
+          createCallback = new org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler();
+      zkClient.asyncCreate("/tmp/async", null, CreateMode.PERSISTENT, createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), 0);
+
+      // try to create oversize node, should fail
+      zkClient.asyncCreate("/tmp/asyncOversize", oversizeZNRecord, CreateMode.PERSISTENT,
+          createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), KeeperException.Code.MarshallingError);
 
 Review comment:
   Nit: Do you also want to check before and after: if the node exists or not to double check the node is not created? 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386800263
 
 

 ##########
 File path: zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
 ##########
 @@ -1720,33 +1721,43 @@ public Stat writeDataGetStat(final String path, Object datat, final int expected
   public void asyncCreate(final String path, Object datat, final CreateMode mode,
       final ZkAsyncCallbacks.CreateCallbackHandler cb) {
     final long startT = System.currentTimeMillis();
-    final byte[] data = (datat == null ? null : serialize(datat, path));
-    retryUntilConnected(new Callable<Object>() {
-      @Override
-      public Object call() throws Exception {
-        ((ZkConnection) getConnection()).getZookeeper()
-            .create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                // Arrays.asList(DEFAULT_ACL),
-                mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
-                    data == null ? 0 : data.length, false));
-        return null;
-      }
+    byte[] data = null;
+    try {
+      data = (datat == null ? null : serialize(datat, path));
+    } catch (ZkMarshallingError e) {
+      cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+          new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
+      return;
+    }
+    final byte[] finalData = data;
+    retryUntilConnected(() -> {
+      ((ZkConnection) getConnection()).getZookeeper()
+          .create(path, finalData, ZooDefs.Ids.OPEN_ACL_UNSAFE,
+              // Arrays.asList(DEFAULT_ACL),
+              mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
+                  finalData == null ? 0 : finalData.length, false));
+      return null;
     });
   }
 
   // Async Data Accessors
   public void asyncSetData(final String path, Object datat, final int version,
       final ZkAsyncCallbacks.SetDataCallbackHandler cb) {
     final long startT = System.currentTimeMillis();
-    final byte[] data = serialize(datat, path);
-    retryUntilConnected(new Callable<Object>() {
-      @Override
-      public Object call() throws Exception {
-        ((ZkConnection) getConnection()).getZookeeper().setData(path, data, version, cb,
-            new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
-                data == null ? 0 : data.length, false));
-        return null;
-      }
+    byte[] data = null;
+    try {
+      data = serialize(datat, path);
+    } catch (ZkMarshallingError e) {
+      cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+          new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
+      return;
+    }
+    final byte[] finalData = data;
 
 Review comment:
   I think it is possible:
   ```
   final byte[] data;
   try {
     data = serialize(datat, path);
   } catch (ZkMarshallingError e) {
     cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
        new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
     return;
   }
   
   retryUntilConnected();
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r387364422
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
+      Random ran = new Random();
+      for (int i = 0; i < 1024; i++) {
+        sb.append(ran.nextInt(26) + 'a');
 
 Review comment:
   @jiajunwang `sb.append(ran.nextInt(26) + 'a');` doesn't add a char to the string builder but an integer. 
   We still have to cast it: `sb.append((char) (ran.nextInt(26) + 'a'));` 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386748889
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
+      Random ran = new Random();
+      for (int i = 0; i < 1024; i++) {
+        sb.append(ran.nextInt(26) + 'a');
+      }
+      String buf = sb.toString();
+      for (int i = 0; i < 1024; i++) {
+        oversizeZNRecord.setSimpleField(Integer.toString(i), buf);
+      }
+
+      // ensure /tmp exists for the test
+      if (!zkClient.exists("/tmp")) {
+        zkClient.create("/tmp", null, CreateMode.PERSISTENT);
+      }
+
+      org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler
+          createCallback = new org.apache.helix.zookeeper.zkclient.callback.ZkAsyncCallbacks.CreateCallbackHandler();
+      zkClient.asyncCreate("/tmp/async", null, CreateMode.PERSISTENT, createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), 0);
+
+      // try to create oversize node, should fail
+      zkClient.asyncCreate("/tmp/asyncOversize", oversizeZNRecord, CreateMode.PERSISTENT,
+          createCallback);
+      createCallback.waitForSuccess();
+      Assert.assertEquals(createCallback.getRc(), KeeperException.Code.MarshallingError);
 
 Review comment:
   Good idea, let me add it.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386746860
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java
 ##########
 @@ -516,7 +514,7 @@ public void testZNRecordStreamingSerializerWriteSizeLimit() throws Exception {
       try {
         zkClient.writeData(path, largeRecord);
         Assert.fail("Data should not written to ZK because data size exceeds writeSizeLimit!");
-      } catch (ZkClientException expected) {
 
 Review comment:
   It is still used by deletePath().

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386747971
 
 

 ##########
 File path: zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
 ##########
 @@ -1720,33 +1721,43 @@ public Stat writeDataGetStat(final String path, Object datat, final int expected
   public void asyncCreate(final String path, Object datat, final CreateMode mode,
       final ZkAsyncCallbacks.CreateCallbackHandler cb) {
     final long startT = System.currentTimeMillis();
-    final byte[] data = (datat == null ? null : serialize(datat, path));
-    retryUntilConnected(new Callable<Object>() {
-      @Override
-      public Object call() throws Exception {
-        ((ZkConnection) getConnection()).getZookeeper()
-            .create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                // Arrays.asList(DEFAULT_ACL),
-                mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
-                    data == null ? 0 : data.length, false));
-        return null;
-      }
+    byte[] data = null;
+    try {
+      data = (datat == null ? null : serialize(datat, path));
+    } catch (ZkMarshallingError e) {
+      cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+          new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
+      return;
+    }
+    final byte[] finalData = data;
+    retryUntilConnected(() -> {
+      ((ZkConnection) getConnection()).getZookeeper()
+          .create(path, finalData, ZooDefs.Ids.OPEN_ACL_UNSAFE,
+              // Arrays.asList(DEFAULT_ACL),
+              mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
+                  finalData == null ? 0 : finalData.length, false));
+      return null;
     });
   }
 
   // Async Data Accessors
   public void asyncSetData(final String path, Object datat, final int version,
       final ZkAsyncCallbacks.SetDataCallbackHandler cb) {
     final long startT = System.currentTimeMillis();
-    final byte[] data = serialize(datat, path);
-    retryUntilConnected(new Callable<Object>() {
-      @Override
-      public Object call() throws Exception {
-        ((ZkConnection) getConnection()).getZookeeper().setData(path, data, version, cb,
-            new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
-                data == null ? 0 : data.length, false));
-        return null;
-      }
+    byte[] data = null;
+    try {
+      data = serialize(datat, path);
+    } catch (ZkMarshallingError e) {
+      cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+          new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
+      return;
+    }
+    final byte[] finalData = data;
 
 Review comment:
   The thing is that I don't want to put the retryUntilConnected() method into the try catch block.
   With the current structure, final data is not possible.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang merged pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang merged pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386737979
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
 
 Review comment:
   You prefer `1204` over `1024`? :)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386743252
 
 

 ##########
 File path: zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java
 ##########
 @@ -1720,33 +1721,43 @@ public Stat writeDataGetStat(final String path, Object datat, final int expected
   public void asyncCreate(final String path, Object datat, final CreateMode mode,
       final ZkAsyncCallbacks.CreateCallbackHandler cb) {
     final long startT = System.currentTimeMillis();
-    final byte[] data = (datat == null ? null : serialize(datat, path));
-    retryUntilConnected(new Callable<Object>() {
-      @Override
-      public Object call() throws Exception {
-        ((ZkConnection) getConnection()).getZookeeper()
-            .create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE,
-                // Arrays.asList(DEFAULT_ACL),
-                mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
-                    data == null ? 0 : data.length, false));
-        return null;
-      }
+    byte[] data = null;
+    try {
+      data = (datat == null ? null : serialize(datat, path));
+    } catch (ZkMarshallingError e) {
+      cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+          new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
+      return;
+    }
+    final byte[] finalData = data;
+    retryUntilConnected(() -> {
+      ((ZkConnection) getConnection()).getZookeeper()
+          .create(path, finalData, ZooDefs.Ids.OPEN_ACL_UNSAFE,
+              // Arrays.asList(DEFAULT_ACL),
+              mode, cb, new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
+                  finalData == null ? 0 : finalData.length, false));
+      return null;
     });
   }
 
   // Async Data Accessors
   public void asyncSetData(final String path, Object datat, final int version,
       final ZkAsyncCallbacks.SetDataCallbackHandler cb) {
     final long startT = System.currentTimeMillis();
-    final byte[] data = serialize(datat, path);
-    retryUntilConnected(new Callable<Object>() {
-      @Override
-      public Object call() throws Exception {
-        ((ZkConnection) getConnection()).getZookeeper().setData(path, data, version, cb,
-            new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT,
-                data == null ? 0 : data.length, false));
-        return null;
-      }
+    byte[] data = null;
+    try {
+      data = serialize(datat, path);
+    } catch (ZkMarshallingError e) {
+      cb.processResult(KeeperException.Code.MARSHALLINGERROR.intValue(), path,
+          new ZkAsyncCallbacks.ZkAsyncCallContext(_monitor, startT, 0, false), null);
+      return;
+    }
+    final byte[] finalData = data;
 
 Review comment:
   Nit: It seems this is redundant? Do you want to make the byte[] array final? If so, you may do declare data as final without initializing it to null.
   ```
   final byte[] data;
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386747120
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
 
 Review comment:
   This is to leave some buffer space. 1024 will fail due to the additional metadata info in the node.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386745197
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
 ##########
 @@ -745,4 +749,65 @@ public void testWaitForEstablishedSession() {
     // Recover zk server for later tests.
     _zkServer.start();
   }
+
+  @Test
+  public void testAsyncWriteOperations() {
+    ZkClient zkClient = new ZkClient(ZK_ADDR);
+    String originSizeLimit =
+        System.getProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES);
+    System.setProperty(ZkSystemPropertyKeys.ZK_SERIALIZER_ZNRECORD_WRITE_SIZE_LIMIT_BYTES, "2000");
+    try {
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+
+      ZNRecord oversizeZNRecord = new ZNRecord("Oversize");
+      StringBuilder sb = new StringBuilder(1204);
+      Random ran = new Random();
+      for (int i = 0; i < 1024; i++) {
+        sb.append(ran.nextInt(26) + 'a');
 
 Review comment:
   Random is good to make sure compressed data is not that small!

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] jiajunwang commented on issue #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
jiajunwang commented on issue #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#issuecomment-593718056
 
 
   This PR is ready to be merged, approved by @pkuwm 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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


[GitHub] [helix] pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error

Posted by GitBox <gi...@apache.org>.
pkuwm commented on a change in pull request #845: Async write operation should not throw Exception for serializing error
URL: https://github.com/apache/helix/pull/845#discussion_r386737281
 
 

 ##########
 File path: helix-core/src/test/java/org/apache/helix/manager/zk/TestZNRecordSizeLimit.java
 ##########
 @@ -516,7 +514,7 @@ public void testZNRecordStreamingSerializerWriteSizeLimit() throws Exception {
       try {
         zkClient.writeData(path, largeRecord);
         Assert.fail("Data should not written to ZK because data size exceeds writeSizeLimit!");
-      } catch (ZkClientException expected) {
 
 Review comment:
   Don't forget to remove unused import for `ZkClientException`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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