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

[GitHub] [helix] rahulrane50 commented on a diff in pull request #2391: add support for state change

rahulrane50 commented on code in PR #2391:
URL: https://github.com/apache/helix/pull/2391#discussion_r1129910557


##########
meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java:
##########
@@ -65,11 +68,15 @@ enum ConnectState {
     // Server has expired this connection.
     EXPIRED,
 
-    // When client failed to connect server.
-    INIT_FAILED,
-
     // When client explicitly call disconnect.
-    CLOSED_BY_CLIENT
+    CLOSED_BY_CLIENT,
+
+    // Connection between client and server is lost.
+    DISCONNECTED,
+
+    // Client is authenticated. They can perform operation with authorized permissions.
+    // This state is not in use as of now.
+    AUTHENTICATED

Review Comment:
   IMHO we should add neither "AUTHENTICATED" nor "AUTH_FAILED" because that's not "connection state" but just return code of connection request but upto i don't have any strong objection on this.



##########
meta-client/src/main/java/org/apache/helix/metaclient/api/MetaClientInterface.java:
##########
@@ -65,11 +68,15 @@ enum ConnectState {
     // Server has expired this connection.
     EXPIRED,
 
-    // When client failed to connect server.
-    INIT_FAILED,

Review Comment:
   Curious, why did we remove this?



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -275,7 +276,8 @@ public DirectChildSubscribeResult subscribeDirectChildChange(String key,
 
   @Override
   public boolean subscribeStateChanges(ConnectStateChangeListener listener) {
-    return false;
+    _zkClient.subscribeStateChanges(new StateChangeListenerAdapter(listener));
+    return true;

Review Comment:
   If returning true means successful subscription then we should update it's documentation correctly that "it would either return true in case of success or raise an exception" here or in MetaClientInterface.java



##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/IZkStateListener.java:
##########
@@ -58,4 +58,8 @@ public interface IZkStateListener {
    *             On any error.
    */
   void handleSessionEstablishmentError(final Throwable error) throws Exception;
+
+  default void handleStateChanged(KeeperState prevState, KeeperState curState) throws Exception {

Review Comment:
   I think intention here is to have backward compatibility with old API until we move to new API which accepts both args. It would be good to have this added in comments.



##########
meta-client/src/test/java/org/apache/helix/metaclient/impl/zk/TestZkMetaClient.java:
##########
@@ -334,6 +320,35 @@ public void handleDirectChildChange(String key) throws Exception {
     }
   }
 
+  @Test
+  public void testConnectStateChangeListener() throws Exception {

Review Comment:
   neat : good to add few comments above this test what all test scenarios it's covering. Once it covers all scenarios it's obvious so no comment is needed but until then reader might not understand what is covered and what is left.



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/util/ZkMetaClientUtil.java:
##########
@@ -239,6 +240,29 @@ public static MetaClientException translateZkExceptionToMetaclientException(ZkEx
     return new MetaClientException(e);
   }
 
+  public static MetaClientInterface.ConnectState translateKeeperStateToMetaClientConnectState(
+      Watcher.Event.KeeperState keeperState) {
+    if (keeperState == null)
+      return MetaClientInterface.ConnectState.NOT_CONNECTED;
+    switch (keeperState) {
+      case AuthFailed:
+        return MetaClientInterface.ConnectState.AUTH_FAILED;
+      case Closed:
+        return MetaClientInterface.ConnectState.CLOSED_BY_CLIENT;
+      case Disconnected:
+        return MetaClientInterface.ConnectState.DISCONNECTED;
+      case Expired:
+        return MetaClientInterface.ConnectState.EXPIRED;
+      case SaslAuthenticated:

Review Comment:
   neat : this is not entirely true. RIght now we don't use ZK SASL authentication so you will always see Sasl auth failure. But still it's not "auth failed" case because we do x509 authentication. Right not it's fine but may be you can add TODO to fix this when we want to onboard on ZK ACL.



##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/ZkClient.java:
##########
@@ -1485,12 +1485,13 @@ private Stat installWatchOnlyPathExist(final String path) {
 
   protected void processStateChanged(WatchedEvent event) {
     LOG.info("zkclient {}, zookeeper state changed ( {} )", _uid, event.getState());
+    KeeperState prevState = _currentState;
     setCurrentState(event.getState());
     if (getShutdownTrigger()) {
       return;
     }
 
-    fireStateChangedEvent(event.getState());
+    fireStateChangedEvent(prevState, event.getState());

Review Comment:
   neat : we can directly use _currentState here right?



##########
meta-client/src/main/java/org/apache/helix/metaclient/impl/zk/ZkMetaClient.java:
##########
@@ -300,7 +302,7 @@ public void unsubscribeChildChanges(String key, ChildChangeListener listener) {
 
   @Override
   public void unsubscribeConnectStateChanges(ConnectStateChangeListener listener) {
-
+    _zkClient.subscribeStateChanges(new StateChangeListenerAdapter(listener));

Review Comment:
   Just noticed that we don't return any error or return code if unsubscribe fails. I see this comment "No-op if the listener is not subscribed to the key.". Does it mean that caller has to call unsubscribe again if it fails? and if that's the case then how that can be communicated to user?



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