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/01 22:47:28 UTC
[helix] 33/49: Instrument ConfigAccessor's constructors (#856)
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 1ee271295402449802d6be758038bed620d5da6a
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 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;
}