Search in sources :

Example 1 with BookieServer

use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.

the class BookKeeperClusterTestCase method startBookie.

/**
     * Start a bookie with the given bookie instance. Also, starts the auto recovery for this bookie, if
     * isAutoRecoveryEnabled is true.
     */
protected BookieServer startBookie(ServerConfiguration conf, final Bookie b) throws Exception {
    BookieServer server = new BookieServer(conf) {

        @Override
        protected Bookie newBookie(ServerConfiguration conf) throws IOException, KeeperException, InterruptedException, BookieException {
            return b;
        }
    };
    server.start();
    int port = conf.getBookiePort();
    while (bkc.getZkHandle().exists("/ledgers/available/" + InetAddress.getLocalHost().getHostAddress() + ":" + port, false) == null) {
        Thread.sleep(500);
    }
    bkc.readBookiesBlocking();
    LOG.info("New bookie on port " + port + " has been created.");
    return server;
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer)

Example 2 with BookieServer

use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.

the class BookKeeperClusterTestCase method killBookie.

/**
     * Kill a bookie by its socket address. Also, stops the autorecovery process for the corresponding bookie server, if
     * isAutoRecoveryEnabled is true.
     *
     * @param addr
     *            Socket Address
     * @return the configuration of killed bookie
     * @throws InterruptedException
     */
public ServerConfiguration killBookie(InetSocketAddress addr) throws Exception {
    BookieServer toRemove = null;
    int toRemoveIndex = 0;
    for (BookieServer server : bs) {
        if (server.getLocalAddress().equals(addr)) {
            server.shutdown();
            toRemove = server;
            break;
        }
        ++toRemoveIndex;
    }
    if (toRemove != null) {
        stopAutoRecoveryService(toRemove);
        bs.remove(toRemove);
        return bsConfs.remove(toRemoveIndex);
    }
    return null;
}
Also used : BookieServer(org.apache.bookkeeper.proto.BookieServer)

Example 3 with BookieServer

use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.

the class LocalBookkeeperEnsemble method stop.

public void stop() throws Exception {
    LOG.debug("Local ZK/BK stopping ...");
    for (BookieServer bookie : bs) {
        bookie.shutdown();
    }
    for (StatsProvider statsProvider : statsProviders) {
        statsProvider.stop();
    }
    zkc.close();
    zks.shutdown();
    serverFactory.shutdown();
    LOG.debug("Local ZK/BK stopped");
}
Also used : StatsProvider(org.apache.bookkeeper.stats.StatsProvider) BookieServer(org.apache.bookkeeper.proto.BookieServer)

Example 4 with BookieServer

use of org.apache.bookkeeper.proto.BookieServer in project pulsar by yahoo.

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];
    statsProviders = new StatsProvider[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);
        String statsFilePath = FileSystems.getDefault().getPath(bkDataDir.getAbsolutePath(), "bookie-stats.json").toString();
        // Initialize Stats Provider
        statsProviders[i] = new DataSketchesMetricsProvider();
        bsConfs[i].setProperty("dataSketchesMetricsJsonFileReporter", statsFilePath);
        statsProviders[i].start(bsConfs[i]);
        StatsLogger statsLogger = statsProviders[i].getStatsLogger("");
        bs[i] = new BookieServer(bsConfs[i], statsLogger);
        bs[i].start();
        LOG.debug("Local BK[{}] started (port: {}, data_directory: {})", i, initialPort + i, bkDataDir.getAbsolutePath());
    }
}
Also used : DataSketchesMetricsProvider(org.apache.bokkeeper.stats.datasketches.DataSketchesMetricsProvider) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) File(java.io.File)

Example 5 with BookieServer

use of org.apache.bookkeeper.proto.BookieServer in project distributedlog by twitter.

the class TestFailureAndRecovery method testAllBookieFailure.

/**
     * Test that if enough bookies fail to prevent an ensemble,
     * writes the bookkeeper will fail. Test that when once again
     * an ensemble is available, it can continue to write.
     */
@Test(timeout = 60000)
public void testAllBookieFailure() throws Exception {
    BookieServer bookieToFail = bkutil.newBookie();
    BookieServer replacementBookie = null;
    try {
        int ensembleSize = numBookies + 1;
        assertEquals("Begin: 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-allbookiefailure");
        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());
        bookieToFail.shutdown();
        assertEquals("New bookie didn't die", numBookies, bkutil.checkBookiesUp(numBookies, 10));
        try {
            for (long i = 1; i <= 3; i++) {
                LogRecord op = DLMTestUtil.getLogRecordInstance(txid++);
                out.write(op);
                txid++;
            }
            FutureUtils.result(out.flushAndCommit());
            fail("should not get to this stage");
        } catch (BKTransmitException bkte) {
            LOG.debug("Error writing to bookkeeper", bkte);
            assertEquals("Invalid exception message", BKException.Code.NotEnoughBookiesException, bkte.getBKResultCode());
        }
        replacementBookie = bkutil.newBookie();
        assertEquals("Replacement: New bookie didn't start", numBookies + 1, bkutil.checkBookiesUp(numBookies + 1, 10));
        out = bkdlmAndClients.getWriteHandler().startLogSegment(txid);
        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 : BKTransmitException(com.twitter.distributedlog.exceptions.BKTransmitException) BookieServer(org.apache.bookkeeper.proto.BookieServer) BKTransmitException(com.twitter.distributedlog.exceptions.BKTransmitException) BKException(org.apache.bookkeeper.client.BKException) Test(org.junit.Test)

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