pkuwm commented on a change in pull request #796: WIP: Add 
SharedZkClient/InnerSharedZkClient implementation
URL: https://github.com/apache/helix/pull/796#discussion_r382376464
 
 

 ##########
 File path: 
zookeeper-api/src/main/java/org/apache/helix/zookeeper/impl/client/SharedZkClient.java
 ##########
 @@ -37,79 +51,549 @@
  * HelixZkClient that uses shared ZkConnection.
  * A SharedZkClient won't manipulate the shared ZkConnection directly.
  */
-public class SharedZkClient extends ZkClient implements HelixZkClient {
+public class SharedZkClient implements RealmAwareZkClient {
   private static Logger LOG = LoggerFactory.getLogger(SharedZkClient.class);
-  /*
-   * Since we cannot really disconnect the ZkConnection, we need a dummy 
ZkConnection placeholder.
-   * This is to ensure connection field is never null even the shared 
RealmAwareZkClient instance is closed so as to avoid NPE.
-   */
-  private final static ZkConnection IDLE_CONNECTION = new 
ZkConnection("Dummy_ZkServers");
-  private final OnCloseCallback _onCloseCallback;
-  private final ZkConnectionManager _connectionManager;
-
-  public interface OnCloseCallback {
-    /**
-     * Triggered after the RealmAwareZkClient is closed.
-     */
-    void onClose();
-  }
-
-  /**
-   * Construct a shared RealmAwareZkClient that uses a shared ZkConnection.
-   *
-   * @param connectionManager     The manager of the shared ZkConnection.
-   * @param clientConfig          ZkClientConfig details to create the shared 
RealmAwareZkClient.
-   * @param callback              Clean up logic when the shared 
RealmAwareZkClient is closed.
-   */
-  public SharedZkClient(ZkConnectionManager connectionManager, ZkClientConfig 
clientConfig,
-      OnCloseCallback callback) {
-    super(connectionManager.getConnection(), 0, 
clientConfig.getOperationRetryTimeout(),
-        clientConfig.getZkSerializer(), clientConfig.getMonitorType(), 
clientConfig.getMonitorKey(),
-        clientConfig.getMonitorInstanceName(), 
clientConfig.isMonitorRootPathOnly());
-    _connectionManager = connectionManager;
-    // Register to the base dedicated RealmAwareZkClient
-    _connectionManager.registerWatcher(this);
-    _onCloseCallback = callback;
+
+  private final HelixZkClient _innerSharedZkClient;
+  private final String _zkRealmShardingKey;
+
+  public SharedZkClient(RealmAwareZkClient.RealmAwareZkConnectionConfig 
connectionConfig,
+      RealmAwareZkClient.RealmAwareZkClientConfig clientConfig,
+      MetadataStoreRoutingData metadataStoreRoutingData) {
+
+    if (connectionConfig == null) {
+      throw new IllegalArgumentException("RealmAwareZkConnectionConfig cannot 
be null!");
+    }
+    _zkRealmShardingKey = connectionConfig.getZkRealmShardingKey();
+
+    // TODO: use _zkRealmShardingKey to generate zkRealmAddress. This can done 
the same way of pull 765 once @hunter check it in.
+    // Get the ZkRealm address based on the ZK path sharding key
+    String zkRealmAddress = null;
+    zkRealmAddress = 
metadataStoreRoutingData.getMetadataStoreRealm(_zkRealmShardingKey);
+
+    // Create an InnerSharedZkClient to actually serve ZK requests
+    // TODO: Rename HelixZkClient in the future or remove it entirely - this 
will be a backward-compatibility breaking change because HelixZkClient is being 
used by Helix users.
+
+    // Note, here delegate _innerSharedZkClient would share the same 
connectionManager. Once the close() API of
+    // SharedZkClient is invoked, we can just call the close() API of delegate 
_innerSharedZkClient. This would follow
+    // exactly the pattern of innerSharedZkClient closing logic, which would 
close the connectionManager when the last
+    // sharedInnerZkClient is closed.
+    HelixZkClient.ZkConnectionConfig zkConnectionConfig =
 
 Review comment:
   It seems HelixZkClient is deprecated. Shall we use RealmawareZkClient?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to