Esempio n. 1
0
  // internal shutdown method to let shutdown bookie gracefully
  // when encountering exception
  synchronized int shutdown(int exitCode) {
    try {
      if (running) { // avoid shutdown twice
        // the exitCode only set when first shutdown usually due to exception found
        this.exitCode = exitCode;
        // mark bookie as in shutting down progress
        shuttingdown = true;

        // Shutdown Sync thread
        syncThread.shutdown();

        // Shutdown disk checker
        ledgerDirsManager.shutdown();
        if (indexDirsManager != ledgerDirsManager) {
          indexDirsManager.shutdown();
        }

        // Shutdown journal
        journal.shutdown();
        this.join();

        // Shutdown the EntryLogger which has the GarbageCollector Thread running
        ledgerStorage.shutdown();

        // close Ledger Manager
        try {
          activeLedgerManager.close();
          activeLedgerManagerFactory.uninitialize();
        } catch (IOException ie) {
          LOG.error("Failed to close active ledger manager : ", ie);
        }

        // Shutdown the ZK client
        if (zk != null) zk.close();

        // Shutdown State Service
        stateService.shutdown();

        // setting running to false here, so watch thread in bookie server know it only after bookie
        // shut down
        running = false;
      }
    } catch (InterruptedException ie) {
      LOG.error("Interrupted during shutting down bookie : ", ie);
    }
    return this.exitCode;
  }