/** * 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; }
/** * 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); }
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; }
/** * 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; }
bookieServer = new BookieServer(conf, statsLogger); bookieServer.start(); for (int i = 0; i < 100; i++) { if (bookieServer.getBookie().isRunning()) { LOG.info("Apache Bookkeeper started"); break;
@Override protected void doStart() { try { this.server.start(); } catch (IOException | UnavailableException | InterruptedException | BKException e) { throw new RuntimeException("Failed to start bookie server", e); } }
public BookieService(BookieConfiguration conf, StatsLogger statsLogger) throws Exception { super(NAME, conf, statsLogger); this.server = new BookieServer(conf.getServerConf(), statsLogger); }
private Bookie getBookie() { return bookieServer == null ? null : bookieServer.getBookie(); }
bookieServer.getBookie().getLedgerStorage().forceGC(); String output = "Triggered GC on BookieServer: " + bookieServer.toString(); String jsonResponse = JsonUtil.toJson(output); if (LOG.isDebugEnabled()) { return response; } else if (HttpServer.Method.GET == request.getMethod()) { Boolean isInForceGC = bookieServer.getBookie().getLedgerStorage().isInForceGC(); Pair<String, String> output = Pair.of("is_in_force_gc", isInForceGC.toString()); String jsonResponse = JsonUtil.toJson(output);
public void join() throws InterruptedException { pulsarService.waitUntilClosed(); if (bookieServer != null) { bookieServer.join(); } if (autoRecoveryMain != null) { autoRecoveryMain.join(); } }
/** * 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); } }
public void start() throws Exception { if (bookieStatsProvider != null) { bookieStatsProvider.start(bookieConfig); log.info("started bookieStatsProvider."); } if (bookieServer != null) { bookieServer.start(); log.info("started bookieServer."); } if (autoRecoveryMain != null) { autoRecoveryMain.start(); log.info("started bookie autoRecoveryMain."); } pulsarService.start(); log.info("PulsarService started."); }
checkNotNull(bookieConfig, "No ServerConfiguration for Bookie"); checkNotNull(bookieStatsProvider, "No Stats Provider for Bookie"); bookieServer = new BookieServer(bookieConfig, bookieStatsProvider.getStatsLogger("")); } else { bookieServer = null;
@Override public HttpServiceResponse handle(HttpServiceRequest request) throws Exception { HttpServiceResponse response = new HttpServiceResponse(); Map<String, String> params = request.getParams(); if (HttpServer.Method.GET == request.getMethod() && (params != null) && params.containsKey("ledger_id")) { Long ledgerId = Long.parseLong(params.get("ledger_id")); LedgerManagerFactory mFactory = bookieServer.getBookie().getLedgerManagerFactory(); LedgerManager manager = mFactory.newLedgerManager(); // output <ledgerId: ledgerMetadata> Map<String, Object> output = Maps.newHashMap(); LedgerMetadata md = manager.readLedgerMetadata(ledgerId).get().getValue(); output.put(ledgerId.toString(), md); manager.close(); String jsonResponse = JsonUtil.toJson(output); LOG.debug("output body:" + jsonResponse); response.setBody(jsonResponse); response.setCode(HttpServer.StatusCode.OK); return response; } else { response.setCode(HttpServer.StatusCode.NOT_FOUND); response.setBody("Not found method. Should be GET method"); return response; } } }
/** * 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; }
/** * 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); } }
List<Long> outputLedgers = null; Map<Long, List<String>> outputLedgersWithMissingReplica = null; LedgerManagerFactory mFactory = bookieServer.getBookie().getLedgerManagerFactory(); LedgerUnderreplicationManager underreplicationManager = mFactory.newLedgerUnderreplicationManager(); Iterator<UnderreplicatedLedger> iter = underreplicationManager.listLedgersToRereplicate(predicate);
bs[i] = new BookieServer(bsConfs[i], NullStatsLogger.INSTANCE); } catch (InvalidCookieException e) { bs[i] = new BookieServer(bsConfs[i], NullStatsLogger.INSTANCE); bs[i].start(); LOG.debug("Local BK[{}] started (port: {}, data_directory: {})", i, bookiePort, bkDataDir.getAbsolutePath());
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)); } finally { if (replacementBookie != null) { replacementBookie.shutdown(); bookieToFail.shutdown();