Java Code Examples for org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo#getId()

The following examples show how to use org.apache.hadoop.hdfs.protocol.CacheDirectiveInfo#getId() . 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: FSNDNCacheOp.java    From hadoop with Apache License 2.0 6 votes vote down vote up
static CacheDirectiveInfo addCacheDirective(
    FSNamesystem fsn, CacheManager cacheManager,
    CacheDirectiveInfo directive, EnumSet<CacheFlag> flags,
    boolean logRetryCache)
    throws IOException {

  final FSPermissionChecker pc = getFsPermissionChecker(fsn);

  if (directive.getId() != null) {
    throw new IOException("addDirective: you cannot specify an ID " +
        "for this operation.");
  }
  CacheDirectiveInfo effectiveDirective =
      cacheManager.addDirective(directive, pc, flags);
  fsn.getEditLog().logAddCacheDirectiveInfo(effectiveDirective,
      logRetryCache);
  return effectiveDirective;
}
 
Example 2
Source File: CacheManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Load cache directives from the fsimage
 */
private void loadDirectives(DataInput in) throws IOException {
  StartupProgress prog = NameNode.getStartupProgress();
  Step step = new Step(StepType.CACHE_ENTRIES);
  prog.beginStep(Phase.LOADING_FSIMAGE, step);
  int numDirectives = in.readInt();
  prog.setTotal(Phase.LOADING_FSIMAGE, step, numDirectives);
  Counter counter = prog.getCounter(Phase.LOADING_FSIMAGE, step);
  for (int i = 0; i < numDirectives; i++) {
    CacheDirectiveInfo info = FSImageSerialization.readCacheDirectiveInfo(in);
    // Get pool reference by looking it up in the map
    final String poolName = info.getPool();
    CacheDirective directive =
        new CacheDirective(info.getId(), info.getPath().toUri().getPath(),
            info.getReplication(), info.getExpiration().getAbsoluteMillis());
    addCacheDirective(poolName, directive);
    counter.increment();
  }
  prog.endStep(Phase.LOADING_FSIMAGE, step);
}
 
Example 3
Source File: PBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static CacheDirectiveInfoProto convert
    (CacheDirectiveInfo info) {
  CacheDirectiveInfoProto.Builder builder = 
      CacheDirectiveInfoProto.newBuilder();
  if (info.getId() != null) {
    builder.setId(info.getId());
  }
  if (info.getPath() != null) {
    builder.setPath(info.getPath().toUri().getPath());
  }
  if (info.getReplication() != null) {
    builder.setReplication(info.getReplication());
  }
  if (info.getPool() != null) {
    builder.setPool(info.getPool());
  }
  if (info.getExpiration() != null) {
    builder.setExpiration(convert(info.getExpiration()));
  }
  return builder.build();
}
 
Example 4
Source File: TestRetryCacheWithHA.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
boolean checkNamenodeBeforeReturn() throws Exception {
  for (int i = 0; i < CHECKTIMES; i++) {
    RemoteIterator<CacheDirectiveEntry> iter =
        dfs.listCacheDirectives(
            new CacheDirectiveInfo.Builder().
                setPool(directive.getPool()).
                setPath(directive.getPath()).
                build());
    while (iter.hasNext()) {
      CacheDirectiveInfo result = iter.next().getInfo();
      if ((result.getId() == id) &&
          (result.getReplication().shortValue() == newReplication)) {
        return true;
      }
    }
    Thread.sleep(1000);
  }
  return false;
}
 
Example 5
Source File: FSNDNCacheOp.java    From big-c with Apache License 2.0 6 votes vote down vote up
static CacheDirectiveInfo addCacheDirective(
    FSNamesystem fsn, CacheManager cacheManager,
    CacheDirectiveInfo directive, EnumSet<CacheFlag> flags,
    boolean logRetryCache)
    throws IOException {

  final FSPermissionChecker pc = getFsPermissionChecker(fsn);

  if (directive.getId() != null) {
    throw new IOException("addDirective: you cannot specify an ID " +
        "for this operation.");
  }
  CacheDirectiveInfo effectiveDirective =
      cacheManager.addDirective(directive, pc, flags);
  fsn.getEditLog().logAddCacheDirectiveInfo(effectiveDirective,
      logRetryCache);
  return effectiveDirective;
}
 
Example 6
Source File: CacheManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Load cache directives from the fsimage
 */
private void loadDirectives(DataInput in) throws IOException {
  StartupProgress prog = NameNode.getStartupProgress();
  Step step = new Step(StepType.CACHE_ENTRIES);
  prog.beginStep(Phase.LOADING_FSIMAGE, step);
  int numDirectives = in.readInt();
  prog.setTotal(Phase.LOADING_FSIMAGE, step, numDirectives);
  Counter counter = prog.getCounter(Phase.LOADING_FSIMAGE, step);
  for (int i = 0; i < numDirectives; i++) {
    CacheDirectiveInfo info = FSImageSerialization.readCacheDirectiveInfo(in);
    // Get pool reference by looking it up in the map
    final String poolName = info.getPool();
    CacheDirective directive =
        new CacheDirective(info.getId(), info.getPath().toUri().getPath(),
            info.getReplication(), info.getExpiration().getAbsoluteMillis());
    addCacheDirective(poolName, directive);
    counter.increment();
  }
  prog.endStep(Phase.LOADING_FSIMAGE, step);
}
 
Example 7
Source File: PBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static CacheDirectiveInfoProto convert
    (CacheDirectiveInfo info) {
  CacheDirectiveInfoProto.Builder builder = 
      CacheDirectiveInfoProto.newBuilder();
  if (info.getId() != null) {
    builder.setId(info.getId());
  }
  if (info.getPath() != null) {
    builder.setPath(info.getPath().toUri().getPath());
  }
  if (info.getReplication() != null) {
    builder.setReplication(info.getReplication());
  }
  if (info.getPool() != null) {
    builder.setPool(info.getPool());
  }
  if (info.getExpiration() != null) {
    builder.setExpiration(convert(info.getExpiration()));
  }
  return builder.build();
}
 
Example 8
Source File: TestRetryCacheWithHA.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
boolean checkNamenodeBeforeReturn() throws Exception {
  for (int i = 0; i < CHECKTIMES; i++) {
    RemoteIterator<CacheDirectiveEntry> iter =
        dfs.listCacheDirectives(
            new CacheDirectiveInfo.Builder().
                setPool(directive.getPool()).
                setPath(directive.getPath()).
                build());
    while (iter.hasNext()) {
      CacheDirectiveInfo result = iter.next().getInfo();
      if ((result.getId() == id) &&
          (result.getReplication().shortValue() == newReplication)) {
        return true;
      }
    }
    Thread.sleep(1000);
  }
  return false;
}
 
Example 9
Source File: CacheManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a directive, skipping most error checking. This should only be called
 * internally in special scenarios like edit log replay.
 */
CacheDirectiveInfo addDirectiveFromEditLog(CacheDirectiveInfo directive)
    throws InvalidRequestException {
  long id = directive.getId();
  CacheDirective entry = new CacheDirective(directive);
  CachePool pool = cachePools.get(directive.getPool());
  addInternal(entry, pool);
  if (nextDirectiveId <= id) {
    nextDirectiveId = id + 1;
  }
  return entry.toInfo();
}
 
Example 10
Source File: CacheManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Modifies a directive, skipping most error checking. This is for careful
 * internal use only. modifyDirective can be non-deterministic since its error
 * checking depends on current system time, which poses a problem for edit log
 * replay.
 */
void modifyDirectiveFromEditLog(CacheDirectiveInfo info)
    throws InvalidRequestException {
  // Check for invalid IDs.
  Long id = info.getId();
  if (id == null) {
    throw new InvalidRequestException("Must supply an ID.");
  }
  CacheDirective prevEntry = getById(id);
  CacheDirectiveInfo newInfo = createFromInfoAndDefaults(info, prevEntry);
  removeInternal(prevEntry);
  addInternal(new CacheDirective(newInfo), getCachePool(newInfo.getPool()));
}
 
Example 11
Source File: CacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a directive, skipping most error checking. This should only be called
 * internally in special scenarios like edit log replay.
 */
CacheDirectiveInfo addDirectiveFromEditLog(CacheDirectiveInfo directive)
    throws InvalidRequestException {
  long id = directive.getId();
  CacheDirective entry = new CacheDirective(directive);
  CachePool pool = cachePools.get(directive.getPool());
  addInternal(entry, pool);
  if (nextDirectiveId <= id) {
    nextDirectiveId = id + 1;
  }
  return entry.toInfo();
}
 
Example 12
Source File: CacheManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Modifies a directive, skipping most error checking. This is for careful
 * internal use only. modifyDirective can be non-deterministic since its error
 * checking depends on current system time, which poses a problem for edit log
 * replay.
 */
void modifyDirectiveFromEditLog(CacheDirectiveInfo info)
    throws InvalidRequestException {
  // Check for invalid IDs.
  Long id = info.getId();
  if (id == null) {
    throw new InvalidRequestException("Must supply an ID.");
  }
  CacheDirective prevEntry = getById(id);
  CacheDirectiveInfo newInfo = createFromInfoAndDefaults(info, prevEntry);
  removeInternal(prevEntry);
  addInternal(new CacheDirective(newInfo), getCachePool(newInfo.getPool()));
}
 
Example 13
Source File: CacheRegistry.java    From nnproxy with Apache License 2.0 4 votes vote down vote up
public BatchedRemoteIterator.BatchedListEntries<CacheDirectiveEntry> listCacheDirectives(long prevId,
                                                                                         CacheDirectiveInfo filter) throws InvalidRequestException {
    final int NUM_PRE_ALLOCATED_ENTRIES = 16;
    String filterPath = null;
    if (filter.getPath() != null) {
        filterPath = validatePath(filter);
    }
    if (filter.getReplication() != null) {
        throw new InvalidRequestException(
                "Filtering by replication is unsupported.");
    }

    // Querying for a single ID
    final Long id = filter.getId();
    if (id != null) {
        if (!directivesById.containsKey(id)) {
            throw new InvalidRequestException("Did not find requested id " + id);
        }
        // Since we use a tailMap on directivesById, setting prev to id-1 gets
        // us the directive with the id (if present)
        prevId = id - 1;
    }

    ArrayList<CacheDirectiveEntry> replies =
            new ArrayList<CacheDirectiveEntry>(NUM_PRE_ALLOCATED_ENTRIES);
    int numReplies = 0;
    SortedMap<Long, CacheDirectiveEntry> tailMap =
            directivesById.tailMap(prevId + 1);
    for (Map.Entry<Long, CacheDirectiveEntry> cur : tailMap.entrySet()) {
        if (numReplies >= maxListCacheDirectivesNumResponses) {
            return new BatchedRemoteIterator.BatchedListEntries<>(replies, true);
        }
        CacheDirectiveInfo info = cur.getValue().getInfo();

        // If the requested ID is present, it should be the first item.
        // Hitting this case means the ID is not present, or we're on the second
        // item and should break out.
        if (id != null &&
                !(info.getId().equals(id))) {
            break;
        }
        if (filter.getPool() != null &&
                !info.getPool().equals(filter.getPool())) {
            continue;
        }
        if (filterPath != null &&
                !info.getPath().toUri().getPath().equals(filterPath)) {
            continue;
        }
        replies.add(cur.getValue());
        numReplies++;
    }
    return new BatchedRemoteIterator.BatchedListEntries<>(replies, false);
}