You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by "xyuanlu (via GitHub)" <gi...@apache.org> on 2023/04/29 04:09:24 UTC

[GitHub] [helix] xyuanlu opened a new pull request, #2465: Persist watcher

xyuanlu opened a new pull request, #2465:
URL: https://github.com/apache/helix/pull/2465

   ### Issues
   
   - [ ] My PR addresses the following Helix issues and references them in the PR description:
   
   (#200 - Link your issue number here: You can write "Fixes #XXX". Please use the proper keyword so that the issue gets closed automatically. See https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue
   Any of the following keywords can be used: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved)
   
   ### Description
   
   - [ ] Here are some details about my PR, including screenshots of any UI changes:
   
   (Write a concise description including what, why, how)
   
   ### Tests
   
   - [ ] The following tests are written for this issue:
   
   (List the names of added unit/integration tests)
   
   - The following is the result of the "mvn test" command on the appropriate module:
   
   (If CI test fails due to known issue, please specify the issue and test PR locally. Then copy & paste the result of "mvn test" to here.)
   
   ### Changes that Break Backward Compatibility (Optional)
   
   - My PR contains changes that break backward compatibility or previous assumptions for certain methods or API. They include:
   
   (Consider including all behavior changes for public methods or API. Also include these changes in merge description so that other developers are aware of these changes. This allows them to make relevant code changes in feature branches accounting for the new method/API behavior.)
   
   ### Documentation (Optional)
   
   - In case of new functionality, my PR adds documentation in the following wiki page:
   
   (Link the GitHub wiki you added)
   
   ### 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"
   
   ### 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.

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


[GitHub] [helix] junkaixue commented on a diff in pull request #2465: Add exception for register ZK one time watcher when _usePersistWatcher flag is on

Posted by "junkaixue (via GitHub)" <gi...@apache.org>.
junkaixue commented on code in PR #2465:
URL: https://github.com/apache/helix/pull/2465#discussion_r1187926512


##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -2152,6 +2173,13 @@ public <T extends Object> T readData(String path, Stat stat) {
 
   @SuppressWarnings("unchecked")
   public <T extends Object> T readData(final String path, final Stat stat, final boolean watch) {
+    // Throws exception when try to subscribe watch when using _usePersistWatcher. When ZkClient
+    // is subscribed as persist watcher, resubscribing the same object as onw time watcher will
+    // over write the persist watcher causing missing following event.
+    if (_usePersistWatcher && watch) {
+      throw new IllegalArgumentException(
+          "Can not subscribe one time watcher when ZkClient is using PersistWatcher");
+    }

Review Comment:
   Can we just wrap it with a private function for validation?



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


[GitHub] [helix] desaikomal commented on a diff in pull request #2465: Add exception for register ZK one time watcher when _usePersistWatcher flag is on

Posted by "desaikomal (via GitHub)" <gi...@apache.org>.
desaikomal commented on code in PR #2465:
URL: https://github.com/apache/helix/pull/2465#discussion_r1181662867


##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -1360,6 +1360,13 @@ public List<String> getChildren(String path) {
   }
 
   protected List<String> getChildren(final String path, final boolean watch) {
+    // Throws exception when try to subscribe watch when using _usePersistWatcher. When ZkClient
+    // is subscribed as persist watcher, resubscribing the same object as onw time watcher will
+    // over write the persist watcher causing missing following event.
+    if (_usePersistWatcher && watch) {

Review Comment:
   is this change in API contract? If not, we should be good.



##########
zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/TestZooKeeperConnection.java:
##########
@@ -0,0 +1,69 @@
+package org.apache.helix.zookeeper.impl;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.helix.zookeeper.zkclient.IZkConnection;
+import org.apache.helix.zookeeper.zkclient.ZkClient;
+import org.apache.zookeeper.AddWatchMode;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestZooKeeperConnection extends ZkTestBase {
+  final int count = 100;
+  final int[] get_count = {0};
+  CountDownLatch countDownLatch = new CountDownLatch(count*2);
+
+
+  /*
+  This function tests persist watchers' behavior in {@link org.apache.helix.zookeeper.zkclient.ZkConnection}
+  1. Register a persist watcher on a path and create 100 children Znode, edit the ZNode for 100 times.
+  Expecting 200 events.
+  2. register a one time listener on the path. Make the same change and count the total number of event.

Review Comment:
   shouldn't the one-time listener throw exception?



##########
zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/TestZooKeeperConnection.java:
##########
@@ -0,0 +1,69 @@
+package org.apache.helix.zookeeper.impl;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.helix.zookeeper.zkclient.IZkConnection;
+import org.apache.helix.zookeeper.zkclient.ZkClient;
+import org.apache.zookeeper.AddWatchMode;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestZooKeeperConnection extends ZkTestBase {
+  final int count = 100;
+  final int[] get_count = {0};
+  CountDownLatch countDownLatch = new CountDownLatch(count*2);
+
+
+  /*
+  This function tests persist watchers' behavior in {@link org.apache.helix.zookeeper.zkclient.ZkConnection}
+  1. Register a persist watcher on a path and create 100 children Znode, edit the ZNode for 100 times.
+  Expecting 200 events.
+  2. register a one time listener on the path. Make the same change and count the total number of event.
+  */
+  @Test
+  void testPersistWatcher() throws Exception {
+    Watcher watcher1 = new PersistWatcher();
+    ZkClient zkClient =   new org.apache.helix.zookeeper.impl.client.ZkClient(ZK_ADDR);
+    IZkConnection _zk = zkClient.getConnection();
+    String path="/testPersistWatcher";
+    _zk.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+    // register a persist listener on a path, change the ZNode 100 times, create 100 child ZNode,
+    // and expecting 200 events
+    _zk.addWatch(path, watcher1, AddWatchMode.PERSISTENT);
+    for (int i=0; i<count; ++i) {

Review Comment:
   nit: just curious - style guide doesn't complain about spacing etc?



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


[GitHub] [helix] xyuanlu commented on a diff in pull request #2465: Add exception for register ZK one time watcher when _usePersistWatcher flag is on

Posted by "xyuanlu (via GitHub)" <gi...@apache.org>.
xyuanlu commented on code in PR #2465:
URL: https://github.com/apache/helix/pull/2465#discussion_r1181725259


##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -1360,6 +1360,13 @@ public List<String> getChildren(String path) {
   }
 
   protected List<String> getChildren(final String path, final boolean watch) {
+    // Throws exception when try to subscribe watch when using _usePersistWatcher. When ZkClient
+    // is subscribed as persist watcher, resubscribing the same object as onw time watcher will
+    // over write the persist watcher causing missing following event.
+    if (_usePersistWatcher && watch) {

Review Comment:
   TFTR! This is not a public API, it should not change any API contract.



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


[GitHub] [helix] xyuanlu commented on a diff in pull request #2465: Add exception for register ZK one time watcher when _usePersistWatcher flag is on

Posted by "xyuanlu (via GitHub)" <gi...@apache.org>.
xyuanlu commented on code in PR #2465:
URL: https://github.com/apache/helix/pull/2465#discussion_r1181766399


##########
zookeeper-api/src/test/java/org/apache/helix/zookeeper/impl/TestZooKeeperConnection.java:
##########
@@ -0,0 +1,69 @@
+package org.apache.helix.zookeeper.impl;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.helix.zookeeper.zkclient.IZkConnection;
+import org.apache.helix.zookeeper.zkclient.ZkClient;
+import org.apache.zookeeper.AddWatchMode;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+
+public class TestZooKeeperConnection extends ZkTestBase {
+  final int count = 100;
+  final int[] get_count = {0};
+  CountDownLatch countDownLatch = new CountDownLatch(count*2);
+
+
+  /*
+  This function tests persist watchers' behavior in {@link org.apache.helix.zookeeper.zkclient.ZkConnection}
+  1. Register a persist watcher on a path and create 100 children Znode, edit the ZNode for 100 times.
+  Expecting 200 events.
+  2. register a one time listener on the path. Make the same change and count the total number of event.

Review Comment:
   Subscribing one-time listener using Helix/ZkClient will throw exception. This test checks our simple wrapper of native Zk client (ZkConnection) and verify persist/one time behavior. 
    



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


[GitHub] [helix] xyuanlu commented on a diff in pull request #2465: Add exception for register ZK one time watcher when _usePersistWatcher flag is on

Posted by "xyuanlu (via GitHub)" <gi...@apache.org>.
xyuanlu commented on code in PR #2465:
URL: https://github.com/apache/helix/pull/2465#discussion_r1188847626


##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -2152,6 +2173,13 @@ public <T extends Object> T readData(String path, Stat stat) {
 
   @SuppressWarnings("unchecked")
   public <T extends Object> T readData(final String path, final Stat stat, final boolean watch) {
+    // Throws exception when try to subscribe watch when using _usePersistWatcher. When ZkClient
+    // is subscribed as persist watcher, resubscribing the same object as onw time watcher will
+    // over write the persist watcher causing missing following event.
+    if (_usePersistWatcher && watch) {
+      throw new IllegalArgumentException(
+          "Can not subscribe one time watcher when ZkClient is using PersistWatcher");
+    }

Review Comment:
   TFTR. Updated.



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


[GitHub] [helix] xyuanlu merged pull request #2465: Add exception for register ZK one time watcher when _usePersistWatcher flag is on

Posted by "xyuanlu (via GitHub)" <gi...@apache.org>.
xyuanlu merged PR #2465:
URL: https://github.com/apache/helix/pull/2465


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