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/04 19:24:50 UTC

[GitHub] [helix] qqu0127 opened a new pull request, #2333: Prepare zkclient for meta-client DataChangeListener add new method in IZkDataListener

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

   ### Issues
   
   - [ ] My PR addresses the following Helix issues and references them in the PR description:
   N.A.
   
   ### Description
   
   - [X] Here are some details about my PR, including screenshots of any UI changes:
   Prepare zookeeper-api for meta-client implementation.
   Add a new method in `IZkDataListener` and a converter class in `ZkMetaClient` so that it's easier to reuse existing zkclient.
   
   ### Tests
   
   - [X] The following tests are written for this issue:
   
   - The following is the result of the "mvn test" command on the appropriate module:
   - [INFO] Tests run: 67, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1,042.678 s - in TestSuite
   [INFO] 
   [INFO] Results:
   [INFO] 
   [INFO] Tests run: 67, Failures: 0, Errors: 0, Skipped: 0
   [INFO] 
   [INFO] 
   [INFO] --- jacoco-maven-plugin:0.8.6:report (generate-code-coverage-report) @ zookeeper-api ---
   [INFO] Loading execution data file /Users/qqu/workspace/qqu-helix/zookeeper-api/target/jacoco.exec
   [INFO] Analyzed bundle 'Apache Helix :: ZooKeeper API' with 115 classes
   [INFO] ------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time:  17:41 min
   [INFO] Finished at: 2023-01-04T13:23:51-05:00
   [INFO] ------------------------------------------------------------------------
   
   (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] xyuanlu merged pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
xyuanlu merged PR #2333:
URL: https://github.com/apache/helix/pull/2333


-- 
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] qqu0127 commented on a diff in pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1063851112


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -247,4 +249,56 @@ public boolean[] set(List keys, List values, List version) {
   public List<OpResult> transactionOP(Iterable iterable) {
     return null;
   }
+
+  /**
+   * A converter class to transform {@link DataChangeListener} to {@link IZkDataListener}
+   */
+  static class DataListenerConverter implements IZkDataListener {
+    private final DataChangeListener _listener;
+
+    DataListenerConverter(DataChangeListener listener) {
+      _listener = listener;
+    }
+
+    private DataChangeListener.ChangeType convertType(Watcher.Event.EventType eventType) {
+      switch (eventType) {
+        case NodeCreated: return DataChangeListener.ChangeType.ENTRY_CREATED;
+        case NodeDataChanged: return DataChangeListener.ChangeType.ENTRY_UPDATE;
+        case NodeDeleted: return DataChangeListener.ChangeType.ENTRY_DELETED;
+        default: throw new IllegalArgumentException("EventType " + eventType + " is not supported.");
+      }
+    }
+
+    @Override
+    public void handleDataChange(String dataPath, Object data) throws Exception {
+      throw new UnsupportedOperationException("handleDataChange(String dataPath, Object data) is not supported.");
+    }
+
+    @Override
+    public void handleDataDeleted(String dataPath) throws Exception {
+      handleDataChange(dataPath, null, Watcher.Event.EventType.NodeDeleted);
+    }
+
+    @Override
+    public void handleDataChange(String dataPath, Object data, Watcher.Event.EventType eventType) throws Exception {
+      _listener.handleDataChange(dataPath, data, convertType(eventType));
+    }
+
+    @Override
+    public boolean equals(Object o) {

Review Comment:
   Because this is a converter class, as wrapper for the old listener interface. This is to make sure the JVM can recognize the underlying listener when we add/remove the listener.



-- 
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] qqu0127 commented on a diff in pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1062941519


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -247,4 +249,39 @@ public boolean[] set(List keys, List values, List version) {
   public List<OpResult> transactionOP(Iterable iterable) {
     return null;
   }
+
+  /**
+   * A converter class to transform {@link DataChangeListener} to {@link IZkDataListener}
+   */
+  static class DataListenerConverter implements IZkDataListener {

Review Comment:
   This converter will be eventually added as IZkDataListener to zkclient. I don't think we want to make zkMetaCLient itself an listener.



-- 
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 #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
desaikomal commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1063827101


##########
.github/workflows/Helix-PR-CI.yml:
##########
@@ -1,7 +1,7 @@
 name: Helix PR CI
 on:
   pull_request:
-    branches: [ master ]
+    branches: [ master, metaclient ] # TODO: remove side branch

Review Comment:
   new to code base, so we have a new branch created for just metaclient?



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -247,4 +249,56 @@ public boolean[] set(List keys, List values, List version) {
   public List<OpResult> transactionOP(Iterable iterable) {
     return null;
   }
+
+  /**
+   * A converter class to transform {@link DataChangeListener} to {@link IZkDataListener}
+   */
+  static class DataListenerConverter implements IZkDataListener {
+    private final DataChangeListener _listener;
+
+    DataListenerConverter(DataChangeListener listener) {
+      _listener = listener;
+    }
+
+    private DataChangeListener.ChangeType convertType(Watcher.Event.EventType eventType) {
+      switch (eventType) {
+        case NodeCreated: return DataChangeListener.ChangeType.ENTRY_CREATED;
+        case NodeDataChanged: return DataChangeListener.ChangeType.ENTRY_UPDATE;
+        case NodeDeleted: return DataChangeListener.ChangeType.ENTRY_DELETED;
+        default: throw new IllegalArgumentException("EventType " + eventType + " is not supported.");
+      }
+    }
+
+    @Override
+    public void handleDataChange(String dataPath, Object data) throws Exception {
+      throw new UnsupportedOperationException("handleDataChange(String dataPath, Object data) is not supported.");
+    }
+
+    @Override
+    public void handleDataDeleted(String dataPath) throws Exception {
+      handleDataChange(dataPath, null, Watcher.Event.EventType.NodeDeleted);
+    }
+
+    @Override
+    public void handleDataChange(String dataPath, Object data, Watcher.Event.EventType eventType) throws Exception {
+      _listener.handleDataChange(dataPath, data, convertType(eventType));
+    }
+
+    @Override
+    public boolean equals(Object o) {

Review Comment:
   why do we need this?



##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/impl/client/ZkClient.java:
##########
@@ -187,6 +197,16 @@ public static class Builder {
     String _monitorKey;
     String _monitorInstanceName = null;
     boolean _monitorRootPathOnly = true;
+    boolean _connectOnInit = true;
+
+    /**
+     * If set true, the client will connect to ZK during initialization.
+     * Otherwise, user has to call connect() method explicitly before talking to ZK.
+     */
+    public Builder setConnectOnInit(boolean connectOnInit) {

Review Comment:
   since this is during init, will this method be of any use?



##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -240,17 +240,18 @@ protected ZkClient(IZkConnection zkConnection, int connectionTimeout, long opera
       LOG.info("ZkClient monitor key or type is not provided. Skip monitoring.");
     }
 
-    connect(connectionTimeout, this);
-
-    try {

Review Comment:
   why monitoring related code removed?



-- 
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 #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
xyuanlu commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1062911817


##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -247,4 +249,39 @@ public boolean[] set(List keys, List values, List version) {
   public List<OpResult> transactionOP(Iterable iterable) {
     return null;
   }
+
+  /**
+   * A converter class to transform {@link DataChangeListener} to {@link IZkDataListener}
+   */
+  static class DataListenerConverter implements IZkDataListener {

Review Comment:
   May I ask why we need this class? Can zkMetaCLient implement IZkDataListener? 



-- 
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] qqu0127 commented on a diff in pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1063848564


##########
.github/workflows/Helix-PR-CI.yml:
##########
@@ -1,7 +1,7 @@
 name: Helix PR CI
 on:
   pull_request:
-    branches: [ master ]
+    branches: [ master, metaclient ] # TODO: remove side branch

Review Comment:
   Yes, this is going to merge to a feature branch, you can see that on under the PR title.



-- 
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] qqu0127 commented on pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on PR #2333:
URL: https://github.com/apache/helix/pull/2333#issuecomment-1375995980

   Thanks @desaikomal for the review and comments. 
   This PR is for new features, and it blocks https://github.com/apache/helix/pull/2327. So let's try to merge this soon if possible. 
   I'll keep it noted for other PRs. Thanks again.


-- 
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] qqu0127 commented on a diff in pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1063852405


##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/impl/client/ZkClient.java:
##########
@@ -187,6 +197,16 @@ public static class Builder {
     String _monitorKey;
     String _monitorInstanceName = null;
     boolean _monitorRootPathOnly = true;
+    boolean _connectOnInit = true;
+
+    /**
+     * If set true, the client will connect to ZK during initialization.
+     * Otherwise, user has to call connect() method explicitly before talking to ZK.
+     */
+    public Builder setConnectOnInit(boolean connectOnInit) {

Review Comment:
   Sorry, I don't get it. This is the builder class, not zkclient itself.



-- 
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] qqu0127 commented on a diff in pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on code in PR #2333:
URL: https://github.com/apache/helix/pull/2333#discussion_r1063853153


##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -240,17 +240,18 @@ protected ZkClient(IZkConnection zkConnection, int connectionTimeout, long opera
       LOG.info("ZkClient monitor key or type is not provided. Skip monitoring.");
     }
 
-    connect(connectionTimeout, this);
-
-    try {

Review Comment:
   This is moved to inside `connect()`, you can look at the code below. Those two things should be combined and always happen together. 



-- 
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] qqu0127 commented on pull request #2333: Prepare zkclient for meta-client DataChangeListener implementation

Posted by GitBox <gi...@apache.org>.
qqu0127 commented on PR #2333:
URL: https://github.com/apache/helix/pull/2333#issuecomment-1376023526

   This PR is ready to merge, commit message: 
   New features and improvement in zookeeper-api to prepare meta-client implementation.


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