Java Code Examples for org.apache.bookkeeper.conf.ServerConfiguration#setZkServers()

The following examples show how to use org.apache.bookkeeper.conf.ServerConfiguration#setZkServers() . 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: 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 3
Source File: BookKeeperClusterTestCase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
protected ServerConfiguration newServerConfiguration(int port, String zkServers, File journalDir,
        File[] ledgerDirs, String ledgerRootPath) {
    ServerConfiguration conf = new ServerConfiguration(baseConf);
    conf.setBookiePort(port);
    if (ledgerRootPath != "") {
        conf.setMetadataServiceUri("zk://" + zkUtil.getZooKeeperConnectString() + ledgerRootPath);
    }else {
        conf.setZkServers(zkServers);
    }
    conf.setJournalDirName(journalDir.getPath());
    conf.setAllowLoopback(true);
    conf.setFlushInterval(60 * 1000);
    conf.setGcWaitTime(60 * 1000);
    conf.setAllocatorPoolingPolicy(PoolingPolicy.UnpooledHeap);
    String[] ledgerDirNames = new String[ledgerDirs.length];
    for (int i = 0; i < ledgerDirs.length; i++) {
        ledgerDirNames[i] = ledgerDirs[i].getPath();
    }
    conf.setLedgerDirNames(ledgerDirNames);
    conf.setLedgerStorageClass("org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage");
    conf.setProperty(DbLedgerStorage.WRITE_CACHE_MAX_SIZE_MB, 4);
    conf.setProperty(DbLedgerStorage.READ_AHEAD_CACHE_MAX_SIZE_MB, 4);
    return conf;
}
 
Example 4
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 5
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 6
Source File: ZKTestEnv.java    From herddb with Apache License 2.0 4 votes vote down vote up
public void startBookie(boolean format) throws Exception {
        if (bookie != null) {
            throw new Exception("bookie already started");
        }
        ServerConfiguration conf = new ServerConfiguration();
        conf.setBookiePort(0);
        conf.setUseHostNameAsBookieID(true);

        Path targetDir = path.resolve("bookie_data");
        conf.setZkServers("localhost:1282");
        conf.setZkLedgersRootPath("/ledgers");
        conf.setLedgerDirNames(new String[]{targetDir.toAbsolutePath().toString()});
        conf.setJournalDirName(targetDir.toAbsolutePath().toString());
        conf.setFlushInterval(10000);
        conf.setGcWaitTime(5);
        conf.setJournalFlushWhenQueueEmpty(true);
//        conf.setJournalBufferedEntriesThreshold(1);
        conf.setAutoRecoveryDaemonEnabled(false);
        conf.setEnableLocalTransport(true);
        conf.setJournalSyncData(false);

        conf.setAllowLoopback(true);
        conf.setProperty("journalMaxGroupWaitMSec", 10); // default 200ms

        try (ZooKeeperClient zkc = ZooKeeperClient
                .newBuilder()
                .connectString("localhost:1282")
                .sessionTimeoutMs(10000)
                .build()) {

            boolean rootExists = zkc.exists(getPath(), false) != null;

            if (!rootExists) {
                zkc.create(getPath(), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            }

        }

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

        this.bookie = new BookieServer(conf);
        this.bookie.start();
    }