You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/03/06 04:41:44 UTC

[GitHub] [helix] pkuwm commented on a change in pull request #861: Make ClusterSetup realm-aware

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

 ##########
 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!");
+      }
+      zkClient = SharedZkClientFactory.getInstance()
+          .buildZkClient(new HelixZkClient.ZkConnectionConfig(_zkServerAddress));
+      zkClient.setZkSerializer(new ZNRecordSerializer());
+    }
+
+    _zkClient = zkClient;
     _admin = new ZKHelixAdmin(_zkClient);
     _usesExternalZkClient = false;
   }
 
-  public ClusterSetup(HelixZkClient zkClient) {
+  public ClusterSetup(RealmAwareZkClient zkClient) {
     _zkServerAddress = zkClient.getServers();
     _zkClient = zkClient;
     _admin = new ZKHelixAdmin(_zkClient);
     _usesExternalZkClient = true;
   }
 
-  public ClusterSetup(HelixZkClient zkClient, HelixAdmin zkHelixAdmin) {
+  public ClusterSetup(RealmAwareZkClient zkClient, HelixAdmin zkHelixAdmin) {
     _zkServerAddress = zkClient.getServers();
     _zkClient = zkClient;
     _admin = zkHelixAdmin;
     _usesExternalZkClient = true;
   }
 
+  private ClusterSetup(Builder builder) throws IOException, InvalidRoutingDataException {
 
 Review comment:
   Like you mentioned, do we need the checked exception signature? If yes, what is the consideration to have it thrown checked exceptions?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org