Search in sources :

Example 6 with BookieServer

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");
        }
    }
}
Also used : BookieServer(org.apache.bookkeeper.proto.BookieServer) BKTransmitException(com.twitter.distributedlog.exceptions.BKTransmitException) BKException(org.apache.bookkeeper.client.BKException) Test(org.junit.Test)

Example 7 with BookieServer

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;
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) IOException(java.io.IOException) File(java.io.File)

Example 8 with BookieServer

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");
}
Also used : BookieServer(org.apache.bookkeeper.proto.BookieServer) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BookieException(org.apache.bookkeeper.bookie.BookieException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 9 with BookieServer

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);
}
Also used : BookieServer(org.apache.bookkeeper.proto.BookieServer) IOException(java.io.IOException)

Example 10 with BookieServer

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);
    }
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) ArrayList(java.util.ArrayList)

Aggregations

BookieServer (org.apache.bookkeeper.proto.BookieServer)13 IOException (java.io.IOException)4 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)4 File (java.io.File)3 BKTransmitException (com.twitter.distributedlog.exceptions.BKTransmitException)2 BookieException (org.apache.bookkeeper.bookie.BookieException)2 BKException (org.apache.bookkeeper.client.BKException)2 KeeperException (org.apache.zookeeper.KeeperException)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DataSketchesMetricsProvider (org.apache.bokkeeper.stats.datasketches.DataSketchesMetricsProvider)1 BookKeeperTestClient (org.apache.bookkeeper.client.BookKeeperTestClient)1 AutoRecoveryMain (org.apache.bookkeeper.replication.AutoRecoveryMain)1 NullStatsLogger (org.apache.bookkeeper.stats.NullStatsLogger)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 StatsProvider (org.apache.bookkeeper.stats.StatsProvider)1