This is an automated email from the ASF dual-hosted git repository. hulee pushed a commit to branch zooscalability in repository https://gitbox.apache.org/repos/asf/helix.git
commit afd15240faa6b7a54c522f0c9955b4774c5e10ae Author: Hunter Lee <[email protected]> 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 8e36f83..b0c1add 100644 --- a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java +++ b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java @@ -108,11 +108,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; } @@ -124,9 +124,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; }
