3434 * Utility methods for reading, and building the ZooKeeper configuration. The order and priority for
3535 * reading the config are as follows:
3636 * <ol>
37- * <li>Property with "hbase.zookeeper.property." prefix from HBase XML.</li>
37+ * <li>Property with "hbase.zookeeper.property." prefix from HBase XML is added with "zookeeper."
38+ * prefix</li>
3839 * <li>other zookeeper related properties in HBASE XML</li>
3940 * </ol>
4041 */
4142@ InterfaceAudience .Private
4243public final class ZKConfig {
4344
4445 private static final String VARIABLE_START = "${" ;
46+ private static final String ZOOKEEPER_JAVA_PROPERTY_PREFIX = "zookeeper." ;
4547
4648 private ZKConfig () {
4749 }
@@ -53,14 +55,29 @@ private ZKConfig() {
5355 * @return Properties holding mappings representing ZooKeeper config file.
5456 */
5557 public static Properties makeZKProps (Configuration conf ) {
56- return makeZKPropsFromHbaseConfig (conf );
58+ return makeZKServerPropsFromHBaseConfig (conf );
59+ }
60+
61+ private static Properties extractZKClientPropsFromHBaseConfig (final Configuration conf ) {
62+ return extractZKPropsFromHBaseConfig (conf , ZOOKEEPER_JAVA_PROPERTY_PREFIX );
63+ }
64+
65+ // This is only used for the in-process ZK Quorums used mainly for testing, not for
66+ // deployments with an external Zookeeper.
67+ private static Properties extractZKServerPropsFromHBaseConfig (final Configuration conf ) {
68+ return extractZKPropsFromHBaseConfig (conf , "" );
5769 }
5870
5971 /**
60- * Directly map all the hbase.zookeeper.property.KEY properties. Synchronize on conf so no loading
61- * of configs while we iterate
72+ * Map all hbase.zookeeper.property.KEY properties to targetPrefix.KEY. Synchronize on conf so no
73+ * loading of configs while we iterate This is rather messy, as we use the same prefix for both
74+ * ZKClientConfig and for the HQuorum properties. ZKClientConfig props all have the zookeeper.
75+ * prefix, while the HQuorum server props don't, and ZK automagically sets a system property
76+ * adding a zookeeper. prefix to the non HQuorum properties, so we need to add the "zookeeper."
77+ * prefix for ZKClientConfig but not for the HQuorum props.
6278 */
63- private static Properties extractZKPropsFromHBaseConfig (final Configuration conf ) {
79+ private static Properties extractZKPropsFromHBaseConfig (final Configuration conf ,
80+ final String targetPrefix ) {
6481 Properties zkProperties = new Properties ();
6582
6683 synchronized (conf ) {
@@ -73,7 +90,7 @@ private static Properties extractZKPropsFromHBaseConfig(final Configuration conf
7390 if (value .contains (VARIABLE_START )) {
7491 value = conf .get (key );
7592 }
76- zkProperties .setProperty (zkKey , value );
93+ zkProperties .setProperty (targetPrefix + zkKey , value );
7794 }
7895 }
7996 }
@@ -82,13 +99,14 @@ private static Properties extractZKPropsFromHBaseConfig(final Configuration conf
8299 }
83100
84101 /**
85- * Make a Properties object holding ZooKeeper config. Parses the corresponding config options from
86- * the HBase XML configs and generates the appropriate ZooKeeper properties.
102+ * Make a Properties object holding ZooKeeper config for the optional in-process ZK Quorum
103+ * servers. Parses the corresponding config options from the HBase XML configs and generates the
104+ * appropriate ZooKeeper properties.
87105 * @param conf Configuration to read from.
88106 * @return Properties holding mappings representing ZooKeeper config file.
89107 */
90- private static Properties makeZKPropsFromHbaseConfig (Configuration conf ) {
91- Properties zkProperties = extractZKPropsFromHBaseConfig (conf );
108+ private static Properties makeZKServerPropsFromHBaseConfig (Configuration conf ) {
109+ Properties zkProperties = extractZKServerPropsFromHBaseConfig (conf );
92110
93111 // If clientPort is not set, assign the default.
94112 if (zkProperties .getProperty (HConstants .CLIENT_PORT_STR ) == null ) {
@@ -325,7 +343,7 @@ public String getZnodeParent() {
325343 }
326344
327345 public static ZKClientConfig getZKClientConfig (Configuration conf ) {
328- Properties zkProperties = extractZKPropsFromHBaseConfig (conf );
346+ Properties zkProperties = extractZKClientPropsFromHBaseConfig (conf );
329347 ZKClientConfig zkClientConfig = new ZKClientConfig ();
330348 zkProperties .forEach ((k , v ) -> zkClientConfig .setProperty (k .toString (), v .toString ()));
331349 return zkClientConfig ;
0 commit comments