Java Code Examples for org.apache.bookkeeper.proto.BookieServer#start()

The following examples show how to use org.apache.bookkeeper.proto.BookieServer#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BKJMUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
BookieServer newBookie() throws Exception {
  int port = nextPort++;
  ServerConfiguration bookieConf = new ServerConfiguration();
  bookieConf.setBookiePort(port);
  File tmpdir = File.createTempFile("bookie" + Integer.toString(port) + "_",
                                    "test");
  tmpdir.delete();
  tmpdir.mkdir();

  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;
}
 
Example 2
Source File: ZKTestEnv.java    From herddb with Apache License 2.0 6 votes vote down vote up
private String startBookie(boolean format) throws Exception {
    if (format && !bookies.isEmpty()) {
        throw new Exception("cannot format, you aleady have bookies");
    }
    ServerConfiguration conf = createBookieConf(nextBookiePort++);

    if (format) {
        BookKeeperAdmin.initNewCluster(conf);
        BookKeeperAdmin.format(conf, false, true);
    }

    BookieServer bookie = new BookieServer(conf);
    bookies.add(bookie);
    bookie.start();
    return bookie.getLocalAddress().getSocketAddress().toString();
}
 
Example 3
Source File: ZKTestEnv.java    From herddb with Apache License 2.0 6 votes vote down vote up
public void startStoppedBookie(String addr) throws Exception {
    int index = 0;
    for (BookieServer bookie : bookies) {
        if (bookie.getLocalAddress().getSocketAddress().toString().equals(addr)) {
            if (bookie.isRunning()) {
                throw new Exception("you did not stop bookie " + addr);
            }
            ServerConfiguration conf = createBookieConf(bookie.getLocalAddress().getPort());
            BookieServer newBookie = new BookieServer(conf);
            bookies.set(index, newBookie);
            newBookie.start();
            return;
        }
        index++;
    }
    throw new Exception("Cannot find bookie " + addr);
}
 
Example 4
Source File: BKJMUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
BookieServer newBookie() throws Exception {
  int port = nextPort++;
  ServerConfiguration bookieConf = new ServerConfiguration();
  bookieConf.setBookiePort(port);
  File tmpdir = File.createTempFile("bookie" + Integer.toString(port) + "_",
                                    "test");
  tmpdir.delete();
  tmpdir.mkdir();

  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;
}
 
Example 5
Source File: BookKeeperClusterTestCase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * 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, String ledgerRootPath) 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(ledgerRootPath + "/available/" + InetAddress.getLocalHost().getHostAddress() + ":" + port,
            false) == null) {
        Thread.sleep(500);
    }

    bkc.readBookiesBlocking();
    LOG.info("New bookie on port " + port + " has been created.");

    return server;
}
 
Example 6
Source File: LocalDLMEmulator.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: RackAwareTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@BeforeClass
protected void setup() throws Exception {
    super.setup();

    // Start bookies with specific racks
    for (int i = 0; i < NUM_BOOKIES; i++) {
        File bkDataDir = Files.createTempDirectory("bk" + Integer.toString(i) + "test").toFile();
        ServerConfiguration conf = new ServerConfiguration();

        conf.setBookiePort(0);
        conf.setZkServers("127.0.0.1:" + bkEnsemble.getZookeeperPort());
        conf.setJournalDirName(bkDataDir.getPath());
        conf.setLedgerDirNames(new String[] { bkDataDir.getPath() });
        conf.setAllowLoopback(true);

        // Use different advertised addresses for each bookie, so we can place them in different
        // racks.
        // Eg: 1st bookie will be 10.0.0.1, 2nd 10.0.0.2 and so on
        String addr = String.format("10.0.0.%d", i + 1);
        conf.setAdvertisedAddress(addr);

        BookieServer bs = new BookieServer(conf, NullStatsLogger.INSTANCE);

        bs.start();
        bookies.add(bs);
    }

}
 
Example 8
Source File: EmbeddedBookie.java    From herddb with Apache License 2.0 4 votes vote down vote up
public void start() throws Exception {
    org.apache.bookkeeper.conf.ServerConfiguration conf = new org.apache.bookkeeper.conf.ServerConfiguration();
    conf.setZkTimeout(metadataManager.getZkSessionTimeout());
    conf.setZkServers(metadataManager.getZkAddress());
    conf.setZkLedgersRootPath(configuration.getString(ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_PATH, ServerConfiguration.PROPERTY_BOOKKEEPER_LEDGERS_PATH_DEFAULT));
    conf.setStatisticsEnabled(true);
    int port = configuration.getInt(ServerConfiguration.PROPERTY_BOOKKEEPER_BOOKIE_PORT, ServerConfiguration.PROPERTY_BOOKKEEPER_BOOKIE_PORT_DEFAULT);

    conf.setUseHostNameAsBookieID(true);
    Path bookie_dir = baseDirectory.resolve("bookie");
    if (port <= 0) {
        Integer _port = readLocalBookiePort(bookie_dir);
        if (_port == null) {
            _port = NetworkUtils.assignFirstFreePort();
            LOG.log(Level.SEVERE, "As configuration parameter "
                    + ServerConfiguration.PROPERTY_BOOKKEEPER_BOOKIE_PORT + " is {0},I have choosen to listen on port {1}."
                    + " Set to a positive number in order to use a fixed port", new Object[]{Integer.toString(port), Integer.toString(_port)});
            persistLocalBookiePort(bookie_dir, _port);
        }
        port = _port;
    }
    conf.setBookiePort(port);
    Files.createDirectories(bookie_dir);
    Path bookie_data_dir = bookie_dir.resolve("bookie_data").toAbsolutePath();
    Path bookie_journal_dir = bookie_dir.resolve("bookie_journal").toAbsolutePath();
    Files.createDirectories(bookie_data_dir);
    Files.createDirectories(bookie_journal_dir);
    conf.setLedgerDirNames(new String[]{bookie_data_dir.toString()});
    conf.setJournalDirName(bookie_journal_dir.toString());
    conf.setFlushInterval(1000);
    conf.setMaxBackupJournals(5);
    conf.setMaxJournalSizeMB(1048);
    conf.setNumAddWorkerThreads(8);
    conf.setMaxPendingReadRequestPerThread(200000); // new in 4.6
    conf.setMaxPendingAddRequestPerThread(200000); // new in 4.6
    conf.setEnableLocalTransport(true);
    conf.setProperty("journalMaxGroupWaitMSec", 10L); // default 200ms
    conf.setJournalFlushWhenQueueEmpty(true);
    conf.setAutoRecoveryDaemonEnabled(false);
    conf.setLedgerManagerFactoryClass(HierarchicalLedgerManagerFactory.class);

    for (String key : configuration.keys()) {
        if (key.startsWith("bookie.")) {
            String bookieConf = key.substring("bookie.".length());
            String value = configuration.getString(key, null);
            conf.addProperty(bookieConf, value);
            LOG.log(Level.CONFIG, "config {0} remapped to {1}={2}", new Object[]{key, bookieConf, value});
        }
    }
    long _start = System.currentTimeMillis();
    LOG.severe("Booting Apache Bookkeeper on port " + port + ",  base directory: " + bookie_dir);

    Files.createDirectories(bookie_dir);
    dumpBookieConfiguration(bookie_dir, conf);

    boolean forcemetaformat = configuration.getBoolean("bookie.forcemetaformat", false);
    LOG.log(Level.CONFIG, "bookie.forcemetaformat={0}", forcemetaformat);

    boolean result = BookKeeperAdmin.format(conf, false, forcemetaformat);
    if (result) {
        LOG.info("BookKeeperAdmin.format: created a new workspace on ZK");
    } else {
        LOG.info("BookKeeperAdmin.format: ZK space does not need an format operation");
    }

    boolean forceformat = configuration.getBoolean("bookie.forceformat", false);
    LOG.log(Level.CONFIG, "bookie.forceformat={0}", forceformat);
    if (forceformat) {
        result = Bookie.format(conf, false, forceformat);
        if (result) {
            LOG.info("Bookie.format: formatter applied to local bookie");
        } else {
            LOG.info("Bookie.format: local boookie did not need formatting");
        }
    }

    bookieServer = new BookieServer(conf, statsLogger);
    bookieServer.start();
    for (int i = 0; i < 100; i++) {
        if (bookieServer.getBookie().isRunning()) {
            LOG.info("Apache Bookkeeper started");
            break;
        }
        Thread.sleep(500);
    }
    long _stop = System.currentTimeMillis();
    LOG.severe("Booting Apache Bookkeeper finished. Time " + (_stop - _start) + " ms");

}