Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]Decommission command throws KeeperErrorCode exception when autoRecovery is disabled #4490

Merged
merged 7 commits into from
Sep 3, 2024
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"));
}
}

}