Ejemplo n.º 1
0
  public Bookie(ServerConfiguration conf, StatsLogger statsLogger)
      throws IOException, KeeperException, InterruptedException, BookieException {
    super("Bookie-" + conf.getBookiePort());
    this.statsLogger = statsLogger;
    this.bookieRegistrationPath = conf.getZkAvailableBookiesPath() + "/";
    this.bookieReadonlyRegistrationPath = this.bookieRegistrationPath + READONLY;
    this.conf = conf;
    this.journalDirectory = getCurrentDirectory(conf.getJournalDir());
    this.ledgerDirsManager =
        new LedgerDirsManager(
            conf, conf.getLedgerDirs(), statsLogger.scope(BOOKIE_SCOPE).scope(LD_LEDGER_SCOPE));
    File[] idxDirs = conf.getIndexDirs();
    if (null == idxDirs) {
      this.indexDirsManager = this.ledgerDirsManager;
    } else {
      this.indexDirsManager =
          new LedgerDirsManager(
              conf, idxDirs, statsLogger.scope(BOOKIE_SCOPE).scope(LD_INDEX_SCOPE));
    }
    // Expose stats
    this.addEntryStats = statsLogger.getOpStatsLogger(BOOKIE_ADD_ENTRY);
    this.recoveryAddEntryStats = statsLogger.getOpStatsLogger(BOOKIE_RECOVERY_ADD_ENTRY);
    this.readEntryStats = statsLogger.getOpStatsLogger(BOOKIE_READ_ENTRY);
    this.readLastConfirmedStats = statsLogger.getOpStatsLogger(BOOKIE_READ_LAST_CONFIRMED);
    // 1 : up, 0 : readonly, -1 : unregistered
    statsLogger.registerGauge(
        SERVER_STATUS,
        new Gauge<Number>() {
          @Override
          public Number getDefaultValue() {
            return 0;
          }

          @Override
          public Number getSample() {
            return zkRegistered.get() ? (readOnly.get() ? 0 : 1) : -1;
          }
        });
  }