Skip to content

Commit

Permalink
[fix]Decommission command throws KeeperErrorCode exception when autoR…
Browse files Browse the repository at this point in the history
…ecovery is disabled (#4490)

Fix #4489

### Motivation
Fix decommission command throws KeeperErrorCode exception when autoRecovery is disabled

Co-authored-by: ZhangJian He <[email protected]>
  • Loading branch information
315157973 and shoothzj authored Sep 3, 2024
1 parent 42407f7 commit 1f1df81
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
}

}

0 comments on commit 1f1df81

Please sign in to comment.