Java Code Examples for org.apache.hadoop.hdfs.server.namenode.INodeDirectory#getParent()

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.INodeDirectory#getParent() . 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: Helper.java    From NNAnalytics with Apache License 2.0 6 votes vote down vote up
/**
 * Returns function that maps an inode to its parent directory down to a specific depth.
 *
 * @param dirDepth the depth of the parent to fetch
 * @return a function
 */
public static Function<INode, String> getDirectoryAtDepthFunction(int dirDepth) {
  return node -> {
    try {
      INodeDirectory parent = node.getParent();
      int topParentDepth = new Path(parent.getFullPathName()).depth();
      if (topParentDepth < dirDepth) {
        return "NO_MAPPING";
      }
      for (int parentTravs = topParentDepth; parentTravs > dirDepth; parentTravs--) {
        parent = parent.getParent();
      }
      return parent.getFullPathName().intern();
    } catch (Exception e) {
      return "NO_MAPPING";
    }
  };
}
 
Example 2
Source File: SnapshotManager.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * List all the snapshottable directories that are owned by the current user.
 * @param userName Current user name.
 * @return Snapshottable directories that are owned by the current user,
 *         represented as an array of {@link SnapshottableDirectoryStatus}. If
 *         {@code userName} is null, return all the snapshottable dirs.
 */
public SnapshottableDirectoryStatus[] getSnapshottableDirListing(
    String userName) {
  if (snapshottables.isEmpty()) {
    return null;
  }
  
  List<SnapshottableDirectoryStatus> statusList = 
      new ArrayList<SnapshottableDirectoryStatus>();
  for (INodeDirectory dir : snapshottables.values()) {
    if (userName == null || userName.equals(dir.getUserName())) {
      SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus(
          dir.getModificationTime(), dir.getAccessTime(),
          dir.getFsPermission(), dir.getUserName(), dir.getGroupName(),
          dir.getLocalNameBytes(), dir.getId(), 
          dir.getChildrenNum(Snapshot.CURRENT_STATE_ID),
          dir.getDirectorySnapshottableFeature().getNumSnapshots(),
          dir.getDirectorySnapshottableFeature().getSnapshotQuota(),
          dir.getParent() == null ? DFSUtil.EMPTY_BYTES :
              DFSUtil.string2Bytes(dir.getParent().getFullPathName()));
      statusList.add(status);
    }
  }
  Collections.sort(statusList, SnapshottableDirectoryStatus.COMPARATOR);
  return statusList.toArray(
      new SnapshottableDirectoryStatus[statusList.size()]);
}
 
Example 3
Source File: DirectorySnapshottableFeature.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the snapshot with the given name from {@link #snapshotsByNames},
 * and delete all the corresponding DirectoryDiff.
 *
 * @param snapshotRoot The directory where we take snapshots
 * @param snapshotName The name of the snapshot to be removed
 * @param collectedBlocks Used to collect information to update blocksMap
 * @return The removed snapshot. Null if no snapshot with the given name
 *         exists.
 */
public Snapshot removeSnapshot(BlockStoragePolicySuite bsps, INodeDirectory snapshotRoot,
    String snapshotName, BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) throws SnapshotException {
  final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName));
  if (i < 0) {
    throw new SnapshotException("Cannot delete snapshot " + snapshotName
        + " from path " + snapshotRoot.getFullPathName()
        + ": the snapshot does not exist.");
  } else {
    final Snapshot snapshot = snapshotsByNames.get(i);
    int prior = Snapshot.findLatestSnapshot(snapshotRoot, snapshot.getId());
    try {
      QuotaCounts counts = snapshotRoot.cleanSubtree(bsps, snapshot.getId(),
          prior, collectedBlocks, removedINodes);
      INodeDirectory parent = snapshotRoot.getParent();
      if (parent != null) {
        // there will not be any WithName node corresponding to the deleted
        // snapshot, thus only update the quota usage in the current tree
        parent.addSpaceConsumed(counts.negation(), true);
      }
    } catch(QuotaExceededException e) {
      INode.LOG.error("BUG: removeSnapshot increases namespace usage.", e);
    }
    // remove from snapshotsByNames after successfully cleaning the subtree
    snapshotsByNames.remove(i);
    return snapshot;
  }
}
 
Example 4
Source File: SnapshotManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * List all the snapshottable directories that are owned by the current user.
 * @param userName Current user name.
 * @return Snapshottable directories that are owned by the current user,
 *         represented as an array of {@link SnapshottableDirectoryStatus}. If
 *         {@code userName} is null, return all the snapshottable dirs.
 */
public SnapshottableDirectoryStatus[] getSnapshottableDirListing(
    String userName) {
  if (snapshottables.isEmpty()) {
    return null;
  }
  
  List<SnapshottableDirectoryStatus> statusList = 
      new ArrayList<SnapshottableDirectoryStatus>();
  for (INodeDirectory dir : snapshottables.values()) {
    if (userName == null || userName.equals(dir.getUserName())) {
      SnapshottableDirectoryStatus status = new SnapshottableDirectoryStatus(
          dir.getModificationTime(), dir.getAccessTime(),
          dir.getFsPermission(), dir.getUserName(), dir.getGroupName(),
          dir.getLocalNameBytes(), dir.getId(), 
          dir.getChildrenNum(Snapshot.CURRENT_STATE_ID),
          dir.getDirectorySnapshottableFeature().getNumSnapshots(),
          dir.getDirectorySnapshottableFeature().getSnapshotQuota(),
          dir.getParent() == null ? DFSUtil.EMPTY_BYTES :
              DFSUtil.string2Bytes(dir.getParent().getFullPathName()));
      statusList.add(status);
    }
  }
  Collections.sort(statusList, SnapshottableDirectoryStatus.COMPARATOR);
  return statusList.toArray(
      new SnapshottableDirectoryStatus[statusList.size()]);
}
 
Example 5
Source File: DirectorySnapshottableFeature.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Remove the snapshot with the given name from {@link #snapshotsByNames},
 * and delete all the corresponding DirectoryDiff.
 *
 * @param snapshotRoot The directory where we take snapshots
 * @param snapshotName The name of the snapshot to be removed
 * @param collectedBlocks Used to collect information to update blocksMap
 * @return The removed snapshot. Null if no snapshot with the given name
 *         exists.
 */
public Snapshot removeSnapshot(BlockStoragePolicySuite bsps, INodeDirectory snapshotRoot,
    String snapshotName, BlocksMapUpdateInfo collectedBlocks,
    final List<INode> removedINodes) throws SnapshotException {
  final int i = searchSnapshot(DFSUtil.string2Bytes(snapshotName));
  if (i < 0) {
    throw new SnapshotException("Cannot delete snapshot " + snapshotName
        + " from path " + snapshotRoot.getFullPathName()
        + ": the snapshot does not exist.");
  } else {
    final Snapshot snapshot = snapshotsByNames.get(i);
    int prior = Snapshot.findLatestSnapshot(snapshotRoot, snapshot.getId());
    try {
      QuotaCounts counts = snapshotRoot.cleanSubtree(bsps, snapshot.getId(),
          prior, collectedBlocks, removedINodes);
      INodeDirectory parent = snapshotRoot.getParent();
      if (parent != null) {
        // there will not be any WithName node corresponding to the deleted
        // snapshot, thus only update the quota usage in the current tree
        parent.addSpaceConsumed(counts.negation(), true);
      }
    } catch(QuotaExceededException e) {
      INode.LOG.error("BUG: removeSnapshot increases namespace usage.", e);
    }
    // remove from snapshotsByNames after successfully cleaning the subtree
    snapshotsByNames.remove(i);
    return snapshot;
  }
}