Skip to content

Commit aba28b7

Browse files
committed
HBASE-29248 HBASE-28529 made an incompatible change to hbase.zookeeper.property handling (#6896)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit 26b026c)
1 parent d5510bd commit aba28b7

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

hbase-common/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@
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
4243
public 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;

hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,36 @@ public void testZooKeeperTlsProperties() {
106106
Configuration conf = HBaseConfiguration.create();
107107
for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
108108
conf.set(HConstants.ZK_CFG_PROPERTY_PREFIX + p, p);
109+
String zkprop = "zookeeper." + p;
110+
System.clearProperty(zkprop);
109111
}
110112

111113
// Act
112114
ZKClientConfig zkClientConfig = ZKConfig.getZKClientConfig(conf);
113115

114116
// Assert
115117
for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
116-
assertEquals("Invalid or unset system property: " + p, p, zkClientConfig.getProperty(p));
118+
assertEquals("Invalid or unset system property: " + p, p,
119+
zkClientConfig.getProperty("zookeeper." + p));
120+
}
121+
}
122+
123+
@Test
124+
public void testZooKeeperTlsPropertiesHQuorumPeer() {
125+
// Arrange
126+
Configuration conf = HBaseConfiguration.create();
127+
for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
128+
conf.set(HConstants.ZK_CFG_PROPERTY_PREFIX + p, p);
129+
String zkprop = "zookeeper." + p;
130+
System.clearProperty(zkprop);
131+
}
132+
133+
// Act
134+
Properties zkProps = ZKConfig.makeZKProps(conf);
135+
136+
// Assert
137+
for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
138+
assertEquals("Invalid or unset system property: " + p, p, zkProps.getProperty(p));
117139
}
118140
}
119141

0 commit comments

Comments
 (0)