Beispiel #1
0
  @Override
  public synchronized void start() {
    setDaemon(true);
    LOG.info("I'm starting a bookie with journal directory {}", journalDirectory.getName());
    // Start DiskChecker thread
    ledgerDirsManager.start();
    if (indexDirsManager != ledgerDirsManager) {
      indexDirsManager.start();
    }

    // start sync thread first, so during replaying journals, we could do checkpoint
    // which reduce the chance that we need to replay journals again if bookie restarted
    // again before finished journal replays.
    syncThread.start();

    // replay journals
    try {
      readJournal();
    } catch (IOException ioe) {
      LOG.error("Exception while replaying journals, shutting down", ioe);
      shutdown(ExitCode.BOOKIE_EXCEPTION);
      return;
    } catch (BookieException be) {
      LOG.error("Exception while replaying journals, shutting down", be);
      shutdown(ExitCode.BOOKIE_EXCEPTION);
      return;
    }

    // Do a fully flush after journal replay
    try {
      syncThread.requestFlush().get();
    } catch (InterruptedException e) {
      LOG.warn("Interrupting the fully flush after replaying journals : ", e);
      Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
      LOG.error("Error on executing a fully flush after replaying journals.");
      shutdown(ExitCode.BOOKIE_EXCEPTION);
    }

    // start bookie thread
    super.start();

    // After successful bookie startup, register listener for disk
    // error/full notifications.
    ledgerDirsManager.addLedgerDirsListener(getLedgerDirsListener());
    if (indexDirsManager != ledgerDirsManager) {
      indexDirsManager.addLedgerDirsListener(getLedgerDirsListener());
    }

    ledgerStorage.start();

    // set running here.
    // since bookie server use running as a flag to tell bookie server whether it is alive
    // if setting it in bookie thread, the watcher might run before bookie thread.
    running = true;
    try {
      registerBookie(true).get();
    } catch (Exception ie) {
      LOG.error("Couldn't register bookie with zookeeper, shutting down : ", ie);
      shutdown(ExitCode.ZK_REG_FAIL);
    }
  }