mgao0 commented on code in PR #2137:
URL: https://github.com/apache/helix/pull/2137#discussion_r888485202
##########
helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixManager.java:
##########
@@ -1560,30 +1560,47 @@ private RealmAwareZkClient
resolveZkClient(HelixZkClientFactory zkClientFactory,
}
/**
- * Check that not both zkAddress and ZkConnectionConfig are set.
- * If zkAddress is not given and ZkConnectionConfig is given, check that
ZkConnectionConfig has
- * a ZK path sharding key set because HelixManager must work on single-realm
mode.
+ * Check that one and only one among zkAddress, ZkConnectionConfig and
RealmAwareZkConnectionConfig are set.
+ * If zkAddress is not given directly or through ZkConnectionConfig and
RealmAwareZkConnectionConfig
+ * is given, check that RealmAwareZkConnectionConfig has a ZK path sharding
key set because
+ * HelixManager must work on single-realm mode.
* @param zkAddress
* @param helixManagerProperty
*/
private void validateZkConnectionSettings(String zkAddress,
HelixManagerProperty helixManagerProperty) {
- if (helixManagerProperty != null &&
helixManagerProperty.getZkConnectionConfig() != null) {
- if (zkAddress != null) {
- throw new HelixException(
- "ZKHelixManager: cannot have both ZkAddress and ZkConnectionConfig
set!");
- }
+ boolean hasRealmAwareZkConnectionConfig = helixManagerProperty != null
+ && helixManagerProperty.getRealmAwareZkConnectionConfig() != null;
+ boolean hasZkConnectionConfig =
+ helixManagerProperty != null &&
helixManagerProperty.getZkConnectionConfig() != null;
+ if (Stream.of(zkAddress != null, hasRealmAwareZkConnectionConfig,
hasZkConnectionConfig)
+ .filter(condition -> condition).count() != 1) {
+ throw new HelixException(
+ "ZKHelixManager: One and only one of ZkAddress,
RealmAwareZkConnectionConfig and "
+ + "ZkConnectionConfig should be set!");
+ }
+
+ if (hasRealmAwareZkConnectionConfig) {
RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig =
- helixManagerProperty.getZkConnectionConfig();
+ helixManagerProperty.getRealmAwareZkConnectionConfig();
if (connectionConfig.getZkRealmShardingKey() == null || connectionConfig
.getZkRealmShardingKey().isEmpty()) {
throw new HelixException(
"ZKHelixManager::ZK path sharding key must be set for
ZKHelixManager! ZKHelixManager "
+ "is only available on single-realm mode.");
}
_realmAwareZkConnectionConfig = connectionConfig;
+ } else if (hasZkConnectionConfig) {
Review Comment:
These two and zk address should not coexist, there should be only one of
them. Line 1576 - 1577 is used to enforce this relationship.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]