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 371c2145323..7bc99b2370f 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 void triggerAudit() 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 2e1bb55ce1b..de6f68ab768 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.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 void testClusterInfo() throws Exception { 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")); + } + } + }