Search in sources :

Example 11 with BookieServer

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

the class BookKeeperClusterTestCase method stopBKCluster.

/**
     * Stop cluster. Also, stops all the auto recovery processes for the bookie cluster, if isAutoRecoveryEnabled is
     * true.
     *
     * @throws Exception
     */
protected void stopBKCluster() throws Exception {
    if (bkc != null) {
        bkc.close();
    }
    for (BookieServer server : bs) {
        server.shutdown();
        AutoRecoveryMain autoRecovery = autoRecoveryProcesses.get(server);
        if (autoRecovery != null && isAutoRecoveryEnabled()) {
            autoRecovery.shutdown();
            LOG.debug("Shutdown auto recovery for bookieserver:" + server.getLocalAddress());
        }
    }
    bs.clear();
    for (File f : tmpDirs) {
        FileUtils.deleteDirectory(f);
    }
}
Also used : AutoRecoveryMain(org.apache.bookkeeper.replication.AutoRecoveryMain) BookieServer(org.apache.bookkeeper.proto.BookieServer) File(java.io.File)

Example 12 with BookieServer

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

the class BookKeeperClusterTestCase method startBookie.

/**
     * Helper method to startup a bookie server using a configuration object. Also, starts the auto recovery process if
     * isAutoRecoveryEnabled is true.
     *
     * @param conf
     *            Server Configuration Object
     *
     */
protected BookieServer startBookie(ServerConfiguration conf) throws Exception {
    BookieServer server = new BookieServer(conf);
    bsConfs.add(conf);
    bs.add(server);
    server.start();
    if (bkc == null) {
        bkc = new BookKeeperTestClient(baseClientConf);
    }
    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 : BookieServer(org.apache.bookkeeper.proto.BookieServer) BookKeeperTestClient(org.apache.bookkeeper.client.BookKeeperTestClient)

Example 13 with BookieServer

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

the class BookKeeperClusterTestCase method sleepBookie.

/**
     * Sleep a bookie until I count down the latch
     *
     * @param addr
     *            Socket Address
     * @param latch
     *            Latch to wait on
     * @throws InterruptedException
     * @throws IOException
     */
public void sleepBookie(InetSocketAddress addr, final CountDownLatch l) throws Exception {
    for (final BookieServer bookie : bs) {
        if (bookie.getLocalAddress().equals(addr)) {
            Thread sleeper = new Thread() {

                @Override
                public void run() {
                    try {
                        bookie.suspendProcessing();
                        l.await();
                        bookie.resumeProcessing();
                    } catch (Exception e) {
                        LOG.error("Error suspending bookie", e);
                    }
                }
            };
            sleeper.start();
            return;
        }
    }
    throw new IOException("Bookie not found");
}
Also used : BookieServer(org.apache.bookkeeper.proto.BookieServer) IOException(java.io.IOException) BookieException(org.apache.bookkeeper.bookie.BookieException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 14 with BookieServer

use of org.apache.bookkeeper.proto.BookieServer in project pravega by pravega.

the class BookKeeperServiceRunner method runBookie.

private BookieServer runBookie(int bkPort) throws Exception {
    // Attempt to reuse an existing data directory. This is useful in case of stops & restarts, when we want to perserve
    // already committed data.
    File tmpDir = this.tempDirs.getOrDefault(bkPort, null);
    if (tmpDir == null) {
        tmpDir = IOUtils.createTempDir("bookie_" + bkPort, "test");
        tmpDir.deleteOnExit();
        this.tempDirs.put(bkPort, tmpDir);
        log.info("Created " + tmpDir);
        if (!tmpDir.delete() || !tmpDir.mkdir()) {
            throw new IOException("Couldn't create bookie dir " + tmpDir);
        }
    }
    val conf = new ServerConfiguration();
    conf.setBookiePort(bkPort);
    conf.setZkServers(LOOPBACK_ADDRESS.getHostAddress() + ":" + this.zkPort);
    conf.setJournalDirName(tmpDir.getPath());
    conf.setLedgerDirNames(new String[] { tmpDir.getPath() });
    conf.setAllowLoopback(true);
    conf.setJournalAdaptiveGroupWrites(false);
    conf.setZkLedgersRootPath(ledgersPath);
    if (secureBK) {
        conf.setTLSProvider("OpenSSL");
        conf.setTLSProviderFactoryClass("org.apache.bookkeeper.tls.TLSContextFactory");
        conf.setTLSKeyStore(this.tLSKeyStore);
        conf.setTLSKeyStorePasswordPath(this.tLSKeyStorePasswordPath);
    }
    log.info("Starting Bookie at port " + bkPort);
    val bs = new BookieServer(conf);
    bs.start();
    return bs;
}
Also used : lombok.val(lombok.val) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) BookieServer(org.apache.bookkeeper.proto.BookieServer) IOException(java.io.IOException) File(java.io.File)

Aggregations

BookieServer (org.apache.bookkeeper.proto.BookieServer)14 IOException (java.io.IOException)5 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)5 File (java.io.File)4 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 lombok.val (lombok.val)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