Java Code Examples for org.apache.hadoop.hbase.HConstants#FOREVER

The following examples show how to use org.apache.hadoop.hbase.HConstants#FOREVER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MajorCompactorTTL.java    From hbase with Apache License 2.0 5 votes vote down vote up
private boolean doesAnyColFamilyHaveTTL(TableDescriptor htd) {
  for (ColumnFamilyDescriptor descriptor : htd.getColumnFamilies()) {
    if (descriptor.getTimeToLive() != HConstants.FOREVER) {
      return true;
    }
  }
  return false;
}
 
Example 2
Source File: HStore.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return TTL in seconds of the specified family
 */
public static long determineTTLFromFamily(final ColumnFamilyDescriptor family) {
  // HCD.getTimeToLive returns ttl in seconds.  Convert to milliseconds.
  long ttl = family.getTimeToLive();
  if (ttl == HConstants.FOREVER) {
    // Default is unlimited ttl.
    ttl = Long.MAX_VALUE;
  } else if (ttl == -1) {
    ttl = Long.MAX_VALUE;
  } else {
    // Second -> ms adjust for user data
    ttl *= 1000;
  }
  return ttl;
}
 
Example 3
Source File: TestRegionCoprocessorHost.java    From hbase with Apache License 2.0 5 votes vote down vote up
private ScanInfo getScanInfo() {
  int oldMaxVersions = 1;
  int oldMinVersions = 0;
  long oldTTL = 10000;

  return new ScanInfo(conf, Bytes.toBytes("cf"), oldMinVersions, oldMaxVersions, oldTTL,
  KeepDeletedCells.FALSE, HConstants.FOREVER, 1000,
    CellComparator.getInstance(), true);
}
 
Example 4
Source File: PrettyPrinter.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a human readable time interval to seconds. Examples of the human readable
 * time intervals are: 50 DAYS 1 HOUR 30 MINUTES , 25000 SECONDS etc.
 * The units of time specified can be in uppercase as well as lowercase. Also, if a
 * single number is specified without any time unit, it is assumed to be in seconds.
 * @param humanReadableInterval
 * @return value in seconds
 */
private static long humanReadableIntervalToSec(final String humanReadableInterval)
        throws HBaseException {
  if (humanReadableInterval == null || humanReadableInterval.equalsIgnoreCase("FOREVER")) {
    return HConstants.FOREVER;
  }

  try {
    return Long.parseLong(humanReadableInterval);
  } catch(NumberFormatException ex) {
    LOG.debug("Given interval value is not a number, parsing for human readable format");
  }

  String days = null;
  String hours = null;
  String minutes = null;
  String seconds = null;
  String expectedTtl = null;
  long ttl;

  Matcher matcher = PrettyPrinter.INTERVAL_PATTERN.matcher(humanReadableInterval);
  if (matcher.matches()) {
    expectedTtl = matcher.group(2);
    days = matcher.group(4);
    hours = matcher.group(6);
    minutes = matcher.group(8);
    seconds = matcher.group(10);
  }
  ttl = 0;
  ttl += days != null ? Long.parseLong(days)*HConstants.DAY_IN_SECONDS:0;
  ttl += hours != null ? Long.parseLong(hours)*HConstants.HOUR_IN_SECONDS:0;
  ttl += minutes != null ? Long.parseLong(minutes)*HConstants.MINUTE_IN_SECONDS:0;
  ttl += seconds != null ? Long.parseLong(seconds):0;

  if (expectedTtl != null && Long.parseLong(expectedTtl) != ttl) {
    throw new HBaseException("Malformed TTL string: TTL values in seconds and human readable" +
            "format do not match");
  }
  return ttl;
}
 
Example 5
Source File: MajorCompactionTTLRequest.java    From hbase with Apache License 2.0 4 votes vote down vote up
private long getColFamilyCutoffTime(ColumnFamilyDescriptor colDesc) {
  if (colDesc.getTimeToLive() == HConstants.FOREVER) {
    return -1;
  }
  return System.currentTimeMillis() - (colDesc.getTimeToLive() * 1000L);
}
 
Example 6
Source File: RatioBasedCompactionPolicy.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldPerformMajorCompaction(Collection<HStoreFile> filesToCompact)
  throws IOException {
  boolean result = false;
  long mcTime = getNextMajorCompactTime(filesToCompact);
  if (filesToCompact == null || filesToCompact.isEmpty() || mcTime == 0) {
    return result;
  }
  // TODO: Use better method for determining stamp of last major (HBASE-2990)
  long lowTimestamp = StoreUtils.getLowestTimestamp(filesToCompact);
  long now = EnvironmentEdgeManager.currentTime();
  if (lowTimestamp > 0L && lowTimestamp < (now - mcTime)) {
    String regionInfo;
    if (this.storeConfigInfo != null && this.storeConfigInfo instanceof HStore) {
      regionInfo = ((HStore)this.storeConfigInfo).getRegionInfo().getRegionNameAsString();
    } else {
      regionInfo = this.toString();
    }
    // Major compaction time has elapsed.
    long cfTTL = HConstants.FOREVER;
    if (this.storeConfigInfo != null) {
       cfTTL = this.storeConfigInfo.getStoreFileTtl();
    }
    if (filesToCompact.size() == 1) {
      // Single file
      HStoreFile sf = filesToCompact.iterator().next();
      OptionalLong minTimestamp = sf.getMinimumTimestamp();
      long oldest = minTimestamp.isPresent() ? now - minTimestamp.getAsLong() : Long.MIN_VALUE;
      if (sf.isMajorCompactionResult() && (cfTTL == Long.MAX_VALUE || oldest < cfTTL)) {
        float blockLocalityIndex =
          sf.getHDFSBlockDistribution().getBlockLocalityIndex(
          DNS.getHostname(comConf.conf, DNS.ServerType.REGIONSERVER));
        if (blockLocalityIndex < comConf.getMinLocalityToForceCompact()) {
          LOG.debug("Major compaction triggered on only store " + regionInfo
            + "; to make hdfs blocks local, current blockLocalityIndex is "
            + blockLocalityIndex + " (min " + comConf.getMinLocalityToForceCompact() + ")");
          result = true;
        } else {
          LOG.debug("Skipping major compaction of " + regionInfo
            + " because one (major) compacted file only, oldestTime " + oldest
            + "ms is < TTL=" + cfTTL + " and blockLocalityIndex is " + blockLocalityIndex
            + " (min " + comConf.getMinLocalityToForceCompact() + ")");
        }
      } else if (cfTTL != HConstants.FOREVER && oldest > cfTTL) {
        LOG.debug("Major compaction triggered on store " + regionInfo
          + ", because keyvalues outdated; time since last major compaction "
          + (now - lowTimestamp) + "ms");
        result = true;
      }
    } else {
      LOG.debug("Major compaction triggered on store " + regionInfo
        + "; time since last major compaction " + (now - lowTimestamp) + "ms");
      result = true;
    }
  }
  return result;
}
 
Example 7
Source File: IndexRebuildRegionScanner.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private boolean isTimestampBeforeTTL(long currentTime, long tsToCheck) {
    if (indexTableTTL == HConstants.FOREVER) {
        return false;
    }
    return tsToCheck < (currentTime - (long) indexTableTTL * 1000);
}
 
Example 8
Source File: GlobalIndexRegionScanner.java    From phoenix with Apache License 2.0 4 votes vote down vote up
protected static boolean isTimestampBeforeTTL(long tableTTL, long currentTime, long tsToCheck) {
    if (tableTTL == HConstants.FOREVER) {
        return false;
    }
    return tsToCheck < (currentTime - tableTTL * 1000);
}