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

shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 1f1df813b9 [fix]Decommission command throws KeeperErrorCode exception 
when autoRecovery is disabled (#4490)
1f1df813b9 is described below

commit 1f1df813b9b4efd410925caadfa45cfb17b811ba
Author: feynmanlin <[email protected]>
AuthorDate: Tue Sep 3 08:19:09 2024 +0800

    [fix]Decommission command throws KeeperErrorCode exception when 
autoRecovery is disabled (#4490)
    
    Fix #4489
    
    ### Motivation
    Fix decommission command throws KeeperErrorCode exception when autoRecovery 
is disabled
    
    Co-authored-by: ZhangJian He <[email protected]>
---
 .../org/apache/bookkeeper/client/BookKeeperAdmin.java     | 12 +++++++++++-
 .../apache/bookkeeper/bookie/ClusterInfoCommandTest.java  | 15 +++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
index 371c214532..7bc99b2370 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/BookKeeperAdmin.java
@@ -1553,7 +1553,17 @@ public class BookKeeperAdmin implements AutoCloseable {
             throw new UnavailableException("Autorecovery is disabled. So 
giving up!");
         }
 
-        BookieId auditorId = getLedgerAuditorManager().getCurrentAuditor();
+        BookieId auditorId = null;
+        try {
+            auditorId = getLedgerAuditorManager().getCurrentAuditor();
+        } catch (IOException e) {
+            if (e.getCause() instanceof KeeperException.NoNodeException) {
+                LOG.error("Unable to find Zookeeper node: {}", 
e.getCause().getMessage());
+                throw new UnavailableException("Autorecovery is disabled due 
to "
+                        + "missing Zookeeper node. Aborting recovery!");
+            }
+            throw e;
+        }
         if (auditorId == null) {
             LOG.error("No auditor elected, though Autorecovery is enabled. So 
giving up.");
             throw new UnavailableException("No auditor elected, though 
Autorecovery is enabled. So giving up.");
diff --git 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/ClusterInfoCommandTest.java
 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/ClusterInfoCommandTest.java
index 2e1bb55ce1..de6f68ab76 100644
--- 
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/ClusterInfoCommandTest.java
+++ 
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/ClusterInfoCommandTest.java
@@ -23,8 +23,11 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
+import org.apache.bookkeeper.client.BookKeeperAdmin;
 import org.apache.bookkeeper.conf.ServerConfiguration;
+import org.apache.bookkeeper.replication.ReplicationException;
 import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
 import org.apache.bookkeeper.tools.cli.commands.bookies.ClusterInfoCommand;
 import org.apache.bookkeeper.tools.framework.CliFlags;
@@ -60,4 +63,16 @@ public class ClusterInfoCommandTest extends 
BookKeeperClusterTestCase {
         assertTrue(info.isLedgerReplicationEnabled());
     }
 
+    @Test
+    public void testRecoveryDisabled() {
+        try (BookKeeperAdmin bookKeeperAdmin = new BookKeeperAdmin(super.bkc)) 
{
+            bookKeeperAdmin.triggerAudit();
+            fail("should failed");
+        } catch (Exception e) {
+            assertTrue(e instanceof ReplicationException.UnavailableException);
+            assertTrue(e.getMessage().contains("Autorecovery is disabled due 
to missing Zookeeper node."
+                    + " Aborting recovery"));
+        }
+    }
+
 }

Reply via email to