This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch branch-3
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-3 by this push:
     new aba28b7cb5a HBASE-29248 HBASE-28529 made an incompatible change to 
hbase.zookeeper.property handling (#6896)
aba28b7cb5a is described below

commit aba28b7cb5a3a98351c48310dab691e506a63fd4
Author: Istvan Toth <[email protected]>
AuthorDate: Mon Apr 14 06:41:44 2025 +0200

    HBASE-29248 HBASE-28529 made an incompatible change to 
hbase.zookeeper.property handling (#6896)
    
    Signed-off-by: Duo Zhang <[email protected]>
    (cherry picked from commit 26b026cc03f963272485a3220c31e67064c86d60)
---
 .../apache/hadoop/hbase/zookeeper/ZKConfig.java    | 40 ++++++++++++++++------
 .../hadoop/hbase/zookeeper/TestZKConfig.java       | 24 ++++++++++++-
 2 files changed, 52 insertions(+), 12 deletions(-)

diff --git 
a/hbase-common/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java 
b/hbase-common/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
index 57009eca660..a19add6be10 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKConfig.java
@@ -34,7 +34,8 @@ import 
org.apache.hbase.thirdparty.com.google.common.base.Splitter;
  * Utility methods for reading, and building the ZooKeeper configuration. The 
order and priority for
  * reading the config are as follows:
  * <ol>
- * <li>Property with "hbase.zookeeper.property." prefix from HBase XML.</li>
+ * <li>Property with "hbase.zookeeper.property." prefix from HBase XML is 
added with "zookeeper."
+ * prefix</li>
  * <li>other zookeeper related properties in HBASE XML</li>
  * </ol>
  */
@@ -42,6 +43,7 @@ import 
org.apache.hbase.thirdparty.com.google.common.base.Splitter;
 public final class ZKConfig {
 
   private static final String VARIABLE_START = "${";
+  private static final String ZOOKEEPER_JAVA_PROPERTY_PREFIX = "zookeeper.";
 
   private ZKConfig() {
   }
@@ -53,14 +55,29 @@ public final class ZKConfig {
    * @return Properties holding mappings representing ZooKeeper config file.
    */
   public static Properties makeZKProps(Configuration conf) {
-    return makeZKPropsFromHbaseConfig(conf);
+    return makeZKServerPropsFromHBaseConfig(conf);
+  }
+
+  private static Properties extractZKClientPropsFromHBaseConfig(final 
Configuration conf) {
+    return extractZKPropsFromHBaseConfig(conf, ZOOKEEPER_JAVA_PROPERTY_PREFIX);
+  }
+
+  // This is only used for the in-process ZK Quorums used mainly for testing, 
not for
+  // deployments with an external Zookeeper.
+  private static Properties extractZKServerPropsFromHBaseConfig(final 
Configuration conf) {
+    return extractZKPropsFromHBaseConfig(conf, "");
   }
 
   /**
-   * Directly map all the hbase.zookeeper.property.KEY properties. Synchronize 
on conf so no loading
-   * of configs while we iterate
+   * Map all hbase.zookeeper.property.KEY properties to targetPrefix.KEY. 
Synchronize on conf so no
+   * loading of configs while we iterate This is rather messy, as we use the 
same prefix for both
+   * ZKClientConfig and for the HQuorum properties. ZKClientConfig props all 
have the zookeeper.
+   * prefix, while the HQuorum server props don't, and ZK automagically sets a 
system property
+   * adding a zookeeper. prefix to the non HQuorum properties, so we need to 
add the "zookeeper."
+   * prefix for ZKClientConfig but not for the HQuorum props.
    */
-  private static Properties extractZKPropsFromHBaseConfig(final Configuration 
conf) {
+  private static Properties extractZKPropsFromHBaseConfig(final Configuration 
conf,
+    final String targetPrefix) {
     Properties zkProperties = new Properties();
 
     synchronized (conf) {
@@ -73,7 +90,7 @@ public final class ZKConfig {
           if (value.contains(VARIABLE_START)) {
             value = conf.get(key);
           }
-          zkProperties.setProperty(zkKey, value);
+          zkProperties.setProperty(targetPrefix + zkKey, value);
         }
       }
     }
@@ -82,13 +99,14 @@ public final class ZKConfig {
   }
 
   /**
-   * Make a Properties object holding ZooKeeper config. Parses the 
corresponding config options from
-   * the HBase XML configs and generates the appropriate ZooKeeper properties.
+   * Make a Properties object holding ZooKeeper config for the optional 
in-process ZK Quorum
+   * servers. Parses the corresponding config options from the HBase XML 
configs and generates the
+   * appropriate ZooKeeper properties.
    * @param conf Configuration to read from.
    * @return Properties holding mappings representing ZooKeeper config file.
    */
-  private static Properties makeZKPropsFromHbaseConfig(Configuration conf) {
-    Properties zkProperties = extractZKPropsFromHBaseConfig(conf);
+  private static Properties makeZKServerPropsFromHBaseConfig(Configuration 
conf) {
+    Properties zkProperties = extractZKServerPropsFromHBaseConfig(conf);
 
     // If clientPort is not set, assign the default.
     if (zkProperties.getProperty(HConstants.CLIENT_PORT_STR) == null) {
@@ -325,7 +343,7 @@ public final class ZKConfig {
   }
 
   public static ZKClientConfig getZKClientConfig(Configuration conf) {
-    Properties zkProperties = extractZKPropsFromHBaseConfig(conf);
+    Properties zkProperties = extractZKClientPropsFromHBaseConfig(conf);
     ZKClientConfig zkClientConfig = new ZKClientConfig();
     zkProperties.forEach((k, v) -> zkClientConfig.setProperty(k.toString(), 
v.toString()));
     return zkClientConfig;
diff --git 
a/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
 
b/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
index 2a7b7bc2768..b5d52f44f81 100644
--- 
a/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
+++ 
b/hbase-common/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKConfig.java
@@ -106,6 +106,8 @@ public class TestZKConfig {
     Configuration conf = HBaseConfiguration.create();
     for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
       conf.set(HConstants.ZK_CFG_PROPERTY_PREFIX + p, p);
+      String zkprop = "zookeeper." + p;
+      System.clearProperty(zkprop);
     }
 
     // Act
@@ -113,7 +115,27 @@ public class TestZKConfig {
 
     // Assert
     for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
-      assertEquals("Invalid or unset system property: " + p, p, 
zkClientConfig.getProperty(p));
+      assertEquals("Invalid or unset system property: " + p, p,
+        zkClientConfig.getProperty("zookeeper." + p));
+    }
+  }
+
+  @Test
+  public void testZooKeeperTlsPropertiesHQuorumPeer() {
+    // Arrange
+    Configuration conf = HBaseConfiguration.create();
+    for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
+      conf.set(HConstants.ZK_CFG_PROPERTY_PREFIX + p, p);
+      String zkprop = "zookeeper." + p;
+      System.clearProperty(zkprop);
+    }
+
+    // Act
+    Properties zkProps = ZKConfig.makeZKProps(conf);
+
+    // Assert
+    for (String p : ZOOKEEPER_CLIENT_TLS_PROPERTIES) {
+      assertEquals("Invalid or unset system property: " + p, p, 
zkProps.getProperty(p));
     }
   }
 

Reply via email to