narendly commented on a change in pull request #846: Make ZKHelixAdmin and 
ZKHelixManager Realm-aware
URL: https://github.com/apache/helix/pull/846#discussion_r390792533
 
 

 ##########
 File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
 ##########
 @@ -1285,4 +1266,63 @@ public void handleSessionEstablishmentError(Throwable 
error) throws Exception {
   public Long getSessionStartTime() {
     return _sessionStartTime;
   }
+
+  private RealmAwareZkClient buildRealmAwareZkClient() {
+    final String shardingKey = buildShardingKey();
+    PathBasedZkSerializer zkSerializer =
+        ChainedPathZkSerializer.builder(new ZNRecordSerializer()).build();
+
+    RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig =
+        new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder()
+            .setRealmMode(RealmAwareZkClient.RealmMode.SINGLE_REALM)
+            .setZkRealmShardingKey(shardingKey)
+            .setSessionTimeout(_sessionTimeout).build();
+
+    RealmAwareZkClient.RealmAwareZkClientConfig clientConfig =
+        new RealmAwareZkClient.RealmAwareZkClientConfig();
+
+    clientConfig.setZkSerializer(zkSerializer)
+        .setConnectInitTimeout(_connectionInitTimeout)
+        .setMonitorType(_instanceType.name())
+        .setMonitorKey(_clusterName)
+        .setMonitorInstanceName(_instanceName)
+        .setMonitorRootPathOnly(isMonitorRootPathOnly());
+
+    RealmAwareZkClient newClient;
+    if (_instanceType == InstanceType.ADMINISTRATOR) {
+      newClient = buildHelixZkClient(SharedZkClientFactory.getInstance(), 
connectionConfig,
+          clientConfig);
+    } else {
+      newClient = buildHelixZkClient(DedicatedZkClientFactory.getInstance(), 
connectionConfig,
+          clientConfig);
+    }
+
+    return newClient;
+  }
+
+  private RealmAwareZkClient buildHelixZkClient(HelixZkClientFactory 
zkClientFactory,
+      RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig,
+      RealmAwareZkClient.RealmAwareZkClientConfig clientConfig) {
+    if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED)) {
+      try {
+        // Create realm-aware ZkClient.
+        return zkClientFactory.buildZkClient(connectionConfig, clientConfig);
+      } catch (IllegalArgumentException | IOException | 
InvalidRoutingDataException e) {
+        throw new HelixException("Not able to connect on realm-aware mode for 
sharding key: "
+            + connectionConfig.getZkRealmShardingKey(), e);
+      }
+    }
+
+    // If multi-zk mode is not enabled, create HelixZkClient with the provided 
zk address.
+    HelixZkClient.ZkClientConfig helixZkClientConfig = 
clientConfig.createHelixZkClientConfig();
+    HelixZkClient.ZkConnectionConfig helixZkConnectionConfig =
+        new HelixZkClient.ZkConnectionConfig(_zkAddress)
+            .setSessionTimeout(connectionConfig.getSessionTimeout());
+
+    return zkClientFactory.buildZkClient(helixZkConnectionConfig, 
helixZkClientConfig);
+  }
 
 Review comment:
   These method names are very confusing. You're creating HelixZkClient in 
buildRealmAwareZkClient() and creating RealmAwareZkClient in 
buildHelixZkClient()? Could we try to improve the naming for these methods so 
that it's easier to read? I think this could be refactored for readability. 
Thoughts?

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