Search in sources :

Example 11 with InvalidRequestException

use of org.apache.hadoop.fs.InvalidRequestException in project hadoop by apache.

the class CacheManager method validateExpiryTime.

/**
   * Calculates the absolute expiry time of the directive from the
   * {@link CacheDirectiveInfo.Expiration}. This converts a relative Expiration
   * into an absolute time based on the local clock.
   * 
   * @param info to validate.
   * @param maxRelativeExpiryTime of the info's pool.
   * @return the expiration time, or the pool's max absolute expiration if the
   *         info's expiration was not set.
   * @throws InvalidRequestException if the info's Expiration is invalid.
   */
private static long validateExpiryTime(CacheDirectiveInfo info, long maxRelativeExpiryTime) throws InvalidRequestException {
    LOG.trace("Validating directive {} pool maxRelativeExpiryTime {}", info, maxRelativeExpiryTime);
    final long now = new Date().getTime();
    final long maxAbsoluteExpiryTime = now + maxRelativeExpiryTime;
    if (info == null || info.getExpiration() == null) {
        return maxAbsoluteExpiryTime;
    }
    Expiration expiry = info.getExpiration();
    if (expiry.getMillis() < 0l) {
        throw new InvalidRequestException("Cannot set a negative expiration: " + expiry.getMillis());
    }
    long relExpiryTime, absExpiryTime;
    if (expiry.isRelative()) {
        relExpiryTime = expiry.getMillis();
        absExpiryTime = now + relExpiryTime;
    } else {
        absExpiryTime = expiry.getMillis();
        relExpiryTime = absExpiryTime - now;
    }
    // Need to cap the expiry so we don't overflow a long when doing math
    if (relExpiryTime > Expiration.MAX_RELATIVE_EXPIRY_MS) {
        throw new InvalidRequestException("Expiration " + expiry.toString() + " is too far in the future!");
    }
    // Fail if the requested expiry is greater than the max
    if (relExpiryTime > maxRelativeExpiryTime) {
        throw new InvalidRequestException("Expiration " + expiry.toString() + " exceeds the max relative expiration time of " + maxRelativeExpiryTime + " ms.");
    }
    return absExpiryTime;
}
Also used : Expiration(org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo.Expiration) InvalidRequestException(org.apache.hadoop.fs.InvalidRequestException) Date(java.util.Date)

Aggregations

InvalidRequestException (org.apache.hadoop.fs.InvalidRequestException)11 CacheDirectiveInfo (org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo)6 Path (org.apache.hadoop.fs.Path)4 CacheDirective (org.apache.hadoop.hdfs.protocol.CacheDirective)4 CacheDirectiveEntry (org.apache.hadoop.hdfs.protocol.CacheDirectiveEntry)4 CachePoolInfo (org.apache.hadoop.hdfs.protocol.CachePoolInfo)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 Date (java.util.Date)3 CachePoolEntry (org.apache.hadoop.hdfs.protocol.CachePoolEntry)2 ShmId (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.ShmId)2 Slot (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 ArrayList (java.util.ArrayList)1 BatchedListEntries (org.apache.hadoop.fs.BatchedRemoteIterator.BatchedListEntries)1 CacheFlag (org.apache.hadoop.fs.CacheFlag)1 FsPermission (org.apache.hadoop.fs.permission.FsPermission)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 Expiration (org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo.Expiration)1 CachePoolStats (org.apache.hadoop.hdfs.protocol.CachePoolStats)1