use of org.apache.bookkeeper.bookie.BookieException.InvalidCookieException in project bookkeeper by apache.
the class CookieTest method testRestartWithHostNameAsBookieID.
/**
* Test restart bookie with useHostNameAsBookieID=true, which had cookie generated
* with ipaddress.
*/
@Test
public void testRestartWithHostNameAsBookieID() throws Exception {
String[] ledgerDirs = new String[] { newDirectory(), newDirectory(), newDirectory() };
String journalDir = newDirectory();
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setJournalDirName(journalDir).setLedgerDirNames(ledgerDirs).setBookiePort(bookiePort).setZkServers(zkUtil.getZooKeeperConnectString());
// should work fine
Bookie b = new Bookie(conf);
b.start();
b.shutdown();
conf.setUseHostNameAsBookieID(true);
try {
new Bookie(conf);
fail("Should not start a bookie with hostname if the bookie has been started with an ip");
} catch (InvalidCookieException e) {
// expected
}
}
use of org.apache.bookkeeper.bookie.BookieException.InvalidCookieException in project incubator-pulsar by apache.
the class LocalBookkeeperEnsemble method runBookies.
private void runBookies(ServerConfiguration baseConf) throws Exception {
LOG.info("Starting Bookie(s)");
// Create Bookie Servers (B1, B2, B3)
bs = new BookieServer[numberOfBookies];
bsConfs = new ServerConfiguration[numberOfBookies];
for (int i = 0; i < numberOfBookies; i++) {
File bkDataDir = isNotBlank(bkDataDirName) ? Files.createDirectories(Paths.get(bkDataDirName + Integer.toString(i))).toFile() : Files.createTempDirectory("bk" + Integer.toString(i) + "test").toFile();
if (this.clearOldData) {
cleanDirectory(bkDataDir);
}
bsConfs[i] = new ServerConfiguration(baseConf);
// override settings
bsConfs[i].setBookiePort(initialPort + i);
bsConfs[i].setZkServers("127.0.0.1:" + ZooKeeperDefaultPort);
bsConfs[i].setJournalDirName(bkDataDir.getPath());
bsConfs[i].setLedgerDirNames(new String[] { bkDataDir.getPath() });
bsConfs[i].setAllowLoopback(true);
bsConfs[i].setGcWaitTime(60000);
try {
bs[i] = new BookieServer(bsConfs[i], NullStatsLogger.INSTANCE);
} catch (InvalidCookieException e) {
// from localhost, we can ignore the error
for (String path : zkc.getChildren("/ledgers/cookies", false)) {
zkc.delete("/ledgers/cookies/" + path, -1);
}
// Also clean the on-disk cookie
new File(new File(bkDataDir, "current"), "VERSION").delete();
// Retry to start the bookie after cleaning the old left cookie
bs[i] = new BookieServer(bsConfs[i], NullStatsLogger.INSTANCE);
}
bs[i].start();
LOG.debug("Local BK[{}] started (port: {}, data_directory: {})", i, initialPort + i, bkDataDir.getAbsolutePath());
}
}
Aggregations