pkuwm commented on a change in pull request #861: Make ClusterSetup realm-aware
URL: https://github.com/apache/helix/pull/861#discussion_r388712466
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/tools/ClusterSetup.java
 ##########
 @@ -135,37 +138,74 @@
   public static final String removeConstraint = "removeConstraint";
 
   private static final Logger _logger = 
LoggerFactory.getLogger(ClusterSetup.class);
-  private final String _zkServerAddress;
-  private final HelixZkClient _zkClient;
-  // true if ZkBaseDataAccessor was instantiated with a HelixZkClient, false 
otherwise
+  private String _zkServerAddress;
+  private final RealmAwareZkClient _zkClient;
+  // true if ZkBaseDataAccessor was instantiated with a RealmAwareZkClient, 
false otherwise
   // This is used for close() to determine how ZkBaseDataAccessor should close 
the underlying
   // ZkClient
   private final boolean _usesExternalZkClient;
   private final HelixAdmin _admin;
 
   public ClusterSetup(String zkServerAddress) {
     _zkServerAddress = zkServerAddress;
-    _zkClient = SharedZkClientFactory.getInstance()
-        .buildZkClient(new HelixZkClient.ZkConnectionConfig(_zkServerAddress));
-    _zkClient.setZkSerializer(new ZNRecordSerializer());
+
+    // First, try to start on multi-realm mode using FederatedZkClient
+    RealmAwareZkClient zkClient;
+    try {
+      zkClient = new FederatedZkClient(
+          new 
RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build(),
+          new RealmAwareZkClient.RealmAwareZkClientConfig());
+    } catch (InvalidRoutingDataException | IOException | IllegalStateException 
e) {
+      // Note: IllegalStateException is for HttpRoutingDataReader if MSDS 
endpoint cannot be found
+      // Fall back to single-realm mode using SharedZkClient (HelixZkClient)
+      // This is to preserve backward-compatibility
+      if (zkServerAddress == null || zkServerAddress.isEmpty()) {
+        throw new IllegalArgumentException("ZK server address is null or 
empty!");
 
 Review comment:
   If zk address is not set for multi-realm mode, a user would not expect an 
`IllegalArgumentException`. Shall we throw an `IllegalStateException` as the 
user doesn't set this **argument**? And also include the original exception 
message/stack?

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