You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hu...@apache.org on 2020/04/08 22:54:03 UTC

[helix] 33/50: Instrument ConfigAccessor's constructors (#856)

This is an automated email from the ASF dual-hosted git repository.

hulee pushed a commit to branch zooscalability_merge
in repository https://gitbox.apache.org/repos/asf/helix.git

commit 3cb4d692a279de6392a5867ec4bb5e95e38c5ee2
Author: Hunter Lee <hu...@linkedin.com>
AuthorDate: Wed Mar 4 12:24:34 2020 -0800

    Instrument ConfigAccessor's constructors (#856)
    
    This diff instruments ConfigAccessor's constructors to make it realm-aware. If ConfigAccessor is unable to start on multi-realm mode, then it falls back to starting on single-realm mode.
---
 .../main/java/org/apache/helix/ConfigAccessor.java | 23 +++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
index 031fbf1..52894b1 100644
--- a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
@@ -109,11 +109,11 @@ public class ConfigAccessor {
   /**
    * Initialize an accessor with a Zookeeper client
    * Note: it is recommended to use the other constructor instead to avoid having to create a
-   * HelixZkClient.
+   * RealmAwareZkClient.
    * @param zkClient
    */
   @Deprecated
-  public ConfigAccessor(HelixZkClient zkClient) {
+  public ConfigAccessor(RealmAwareZkClient zkClient) {
     _zkClient = zkClient;
     _usesExternalZkClient = true;
   }
@@ -125,9 +125,22 @@ public class ConfigAccessor {
    * @param zkAddress
    */
   public ConfigAccessor(String zkAddress) {
-    _zkClient = SharedZkClientFactory.getInstance()
-        .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddress),
-            new HelixZkClient.ZkClientConfig().setZkSerializer(new ZNRecordSerializer()));
+    // First, attempt to connect on multi-realm mode using FederatedZkClient
+    RealmAwareZkClient zkClient;
+    try {
+      zkClient = new FederatedZkClient(
+          new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build(),
+          new RealmAwareZkClient.RealmAwareZkClientConfig());
+    } catch (IOException | InvalidRoutingDataException | IllegalStateException e) {
+      // Connecting multi-realm failed - fall back to creating it on single-realm mode using the given ZK address
+      LOG.info(
+          "ConfigAccessor: not able to connect on multi-realm mode; connecting single-realm mode to ZK: {}",
+          zkAddress, e);
+      zkClient = SharedZkClientFactory.getInstance()
+          .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddress),
+              new HelixZkClient.ZkClientConfig().setZkSerializer(new ZNRecordSerializer()));
+    }
+    _zkClient = zkClient;
     _usesExternalZkClient = false;
   }