You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2025/05/15 14:56:01 UTC

(hbase) branch branch-2.5 updated: HBASE-29313 RecoverableZooKeeper.getZooKeeper() returns null for new object (#6988)

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

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


The following commit(s) were added to refs/heads/branch-2.5 by this push:
     new 4f5f8e597de HBASE-29313 RecoverableZooKeeper.getZooKeeper() returns null for new object (#6988)
4f5f8e597de is described below

commit 4f5f8e597dea910679513755f0480cabfae0f818
Author: Istvan Toth <st...@apache.org>
AuthorDate: Thu May 15 16:54:45 2025 +0200

    HBASE-29313 RecoverableZooKeeper.getZooKeeper() returns null for new object (#6988)
    
    Signed-off-by: Duo Zhang <zh...@apache.org>
---
 .../hadoop/hbase/zookeeper/RecoverableZooKeeper.java       | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
index a70bed2839f..a590512dfcb 100644
--- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
+++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
@@ -805,8 +805,20 @@ public class RecoverableZooKeeper {
     return zk == null ? null : zk.getState();
   }
 
+  /**
+   * Returns the wrapped ZooKeeper client. If the wrapped client hasn't been created yet then tries
+   * create it first.
+   * @return the wrapped ZK client of null if the creation has failed.
+   */
   public synchronized ZooKeeper getZooKeeper() {
-    return zk;
+    // Callers expect an initialized ZooKeeper instance
+    // Pre HBASE-28529 the constructor used to call checkZk()
+    try {
+      return checkZk();
+    } catch (Exception x) {
+      LOG.warn("Failed to initialize Zookeeper object, returning null", x);
+      return null;
+    }
   }
 
   public synchronized byte[] getSessionPasswd() {