use of org.apache.bookkeeper.proto.BookieServer in project distributedlog by twitter.
the class TestFailureAndRecovery method testOneBookieFailure.
/**
* Test that a BookKeeper JM can continue to work across the
* failure of a bookie. This should be handled transparently
* by bookkeeper.
*/
@Test(timeout = 60000)
public void testOneBookieFailure() throws Exception {
BookieServer bookieToFail = bkutil.newBookie();
BookieServer replacementBookie = null;
try {
int ensembleSize = numBookies + 1;
assertEquals("New bookie didn't start", ensembleSize, bkutil.checkBookiesUp(ensembleSize, 10));
// ensure that the journal manager has to use all bookies,
// so that a failure will fail the journal manager
DistributedLogConfiguration conf = new DistributedLogConfiguration();
conf.setEnsembleSize(ensembleSize);
conf.setWriteQuorumSize(ensembleSize);
conf.setAckQuorumSize(ensembleSize);
long txid = 1;
DLMTestUtil.BKLogPartitionWriteHandlerAndClients bkdlmAndClients = createNewBKDLM(conf, "distrlog-onebookiefailure");
BKLogSegmentWriter out = bkdlmAndClients.getWriteHandler().startLogSegment(txid);
for (long i = 1; i <= 3; i++) {
LogRecord op = DLMTestUtil.getLogRecordInstance(txid++);
out.write(op);
}
FutureUtils.result(out.flushAndCommit());
replacementBookie = bkutil.newBookie();
assertEquals("replacement bookie didn't start", ensembleSize + 1, bkutil.checkBookiesUp(ensembleSize + 1, 10));
bookieToFail.shutdown();
assertEquals("New bookie didn't die", ensembleSize, bkutil.checkBookiesUp(ensembleSize, 10));
for (long i = 1; i <= 3; i++) {
LogRecord op = DLMTestUtil.getLogRecordInstance(txid++);
out.write(op);
}
FutureUtils.result(out.flushAndCommit());
} catch (Exception e) {
LOG.error("Exception in test", e);
throw e;
} finally {
if (replacementBookie != null) {
replacementBookie.shutdown();
}
bookieToFail.shutdown();
if (bkutil.checkBookiesUp(numBookies, 30) != numBookies) {
LOG.warn("Not all bookies from this test shut down, expect errors");
}
}
}
use of org.apache.bookkeeper.proto.BookieServer in project distributedlog by twitter.
the class LocalDLMEmulator method newBookie.
public BookieServer newBookie() throws Exception {
ServerConfiguration bookieConf = new ServerConfiguration();
bookieConf.setZkTimeout(zkTimeoutSec * 1000);
bookieConf.setBookiePort(0);
bookieConf.setAllowLoopback(true);
File tmpdir = File.createTempFile("bookie" + UUID.randomUUID() + "_", "test");
if (!tmpdir.delete()) {
LOG.debug("Fail to delete tmpdir " + tmpdir);
}
if (!tmpdir.mkdir()) {
throw new IOException("Fail to create tmpdir " + tmpdir);
}
tmpDirs.add(tmpdir);
bookieConf.setZkServers(zkEnsemble);
bookieConf.setJournalDirName(tmpdir.getPath());
bookieConf.setLedgerDirNames(new String[] { tmpdir.getPath() });
BookieServer b = new BookieServer(bookieConf);
b.start();
for (int i = 0; i < 10 && !b.isRunning(); i++) {
Thread.sleep(10000);
}
if (!b.isRunning()) {
throw new IOException("Bookie would not start");
}
return b;
}
use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.
the class BookKeeperClusterTestCase method sleepBookie.
/**
* Sleep a bookie
*
* @param addr
* Socket Address
* @param seconds
* Sleep seconds
* @return Count Down latch which will be counted down when sleep finishes
* @throws InterruptedException
* @throws IOException
*/
public CountDownLatch sleepBookie(InetSocketAddress addr, final int seconds) throws Exception {
for (final BookieServer bookie : bs) {
if (bookie.getLocalAddress().equals(addr)) {
final CountDownLatch l = new CountDownLatch(1);
Thread sleeper = new Thread() {
@Override
public void run() {
try {
bookie.suspendProcessing();
l.countDown();
Thread.sleep(seconds * 1000);
bookie.resumeProcessing();
} catch (Exception e) {
LOG.error("Error suspending bookie", e);
}
}
};
sleeper.start();
return l;
}
}
throw new IOException("Bookie not found");
}
use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.
the class BookKeeperClusterTestCase method killBookie.
/**
* Kill a bookie by index. Also, stops the respective auto recovery process for this bookie, if
* isAutoRecoveryEnabled is true.
*
* @param index
* Bookie Index
* @return the configuration of killed bookie
* @throws InterruptedException
* @throws IOException
*/
public ServerConfiguration killBookie(int index) throws Exception {
if (index >= bs.size()) {
throw new IOException("Bookie does not exist");
}
BookieServer server = bs.get(index);
server.shutdown();
stopAutoRecoveryService(server);
bs.remove(server);
return bsConfs.remove(index);
}
use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.
the class BookKeeperClusterTestCase method restartBookies.
/**
* Restart bookie servers using new configuration settings. Also restart the respective auto recovery process, if
* isAutoRecoveryEnabled is true.
*
* @param newConf
* New Configuration Settings
* @throws InterruptedException
* @throws IOException
* @throws KeeperException
* @throws BookieException
*/
public void restartBookies(ServerConfiguration newConf) throws Exception {
// shut down bookie server
for (BookieServer server : bs) {
server.shutdown();
stopAutoRecoveryService(server);
}
bs.clear();
Thread.sleep(1000);
// restart them to ensure we can't
List<ServerConfiguration> bsConfsCopy = new ArrayList<ServerConfiguration>(bsConfs);
bsConfs.clear();
for (ServerConfiguration conf : bsConfsCopy) {
if (null != newConf) {
conf.loadConf(newConf);
}
startBookie(conf);
}
}
Aggregations