Пример #1
0
  /**
   * Determine whether a checkpoint should be run. 1. If the force parameter is specified, always
   * checkpoint. 2. If the config object specifies time or log size, use that. 3. If the environment
   * is configured to use log size based checkpointing, check the log. 4. Lastly, use time based
   * checking.
   */
  private boolean isRunnable(CheckpointConfig config) throws DatabaseException {

    /* Figure out if we're using log size or time to determine interval.*/
    long useBytesInterval = 0;
    long useTimeInterval = 0;
    DbLsn nextLsn = null;
    try {
      if (config.getForce()) {
        return true;
      } else if (config.getKBytes() != 0) {
        useBytesInterval = config.getKBytes() << 10;
      } else if (config.getMinutes() != 0) {
        // convert to millis
        useTimeInterval = config.getMinutes() * 60 * 1000;
      } else if (logSizeBytesInterval != 0) {
        useBytesInterval = logSizeBytesInterval;
      } else {
        useTimeInterval = timeInterval;
      }

      /*
       * If our checkpoint interval is defined by log size, check
       * on how much log has grown since the last checkpoint.
       */
      if (useBytesInterval != 0) {
        nextLsn = envImpl.getFileManager().getNextLsn();
        if (nextLsn.getNoCleaningDistance(lastCheckpointEnd, logFileMax) >= useBytesInterval) {
          return true;
        } else {
          return false;
        }
      } else if (useTimeInterval != 0) {

        /*
         * Our checkpoint is determined by time.  If enough
         * time has passed and some log data has been written,
         * do a checkpoint.
         */
        DbLsn lastUsedLsn = envImpl.getFileManager().getLastUsedLsn();
        if (((System.currentTimeMillis() - lastCheckpointMillis) >= useTimeInterval)
            && (lastUsedLsn.compareTo(lastCheckpointEnd) != 0)) {
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    } finally {
      StringBuffer sb = new StringBuffer();
      sb.append("size interval=").append(useBytesInterval);
      if (nextLsn != null) {
        sb.append(" nextLsn=").append(nextLsn.getNoFormatString());
      }
      if (lastCheckpointEnd != null) {
        sb.append(" lastCkpt=");
        sb.append(lastCheckpointEnd.getNoFormatString());
      }
      sb.append(" time interval=").append(useTimeInterval);
      sb.append(" force=").append(config.getForce());

      Tracer.trace(Level.FINEST, envImpl, sb.toString());
    }
  }