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

 ##########
 File path: 
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java
 ##########
 @@ -1285,4 +1266,62 @@ 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) {
+    try {
+      return zkClientFactory.buildZkClient(connectionConfig, clientConfig);
+    } catch (IllegalArgumentException | IOException | 
InvalidRoutingDataException e) {
+      LOG.info("Not able to connect on realm-aware mode for sharding key: {}, 
caused by: {} ."
+              + "Trying to connect to ZK: {}.", 
connectionConfig.getZkRealmShardingKey(),
+          e.getMessage(), _zkAddress);
+    }
+
+    // Fall back to HelixZkClient
+    HelixZkClient.ZkClientConfig helixZkClientConfig = 
clientConfig.createHelixZkClientConfig();
+    HelixZkClient.ZkConnectionConfig helixZkConnectionConfig =
+        new HelixZkClient.ZkConnectionConfig(_zkAddress)
+            .setSessionTimeout(connectionConfig.getSessionTimeout());
+
+    return zkClientFactory.buildZkClient(helixZkConnectionConfig, 
helixZkClientConfig);
+  }
+
 
 Review comment:
   Nit: remove extra line

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