Java Code Examples for org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot#Root

The following examples show how to use org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot#Root . 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: FSDirStatAndListingOp.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Get a listing of all the snapshots of a snapshottable directory
 */
private static DirectoryListing getSnapshotsListing(
    FSDirectory fsd, String src, byte[] startAfter)
    throws IOException {
  Preconditions.checkState(fsd.hasReadLock());
  Preconditions.checkArgument(
      src.endsWith(HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR),
      "%s does not end with %s", src, HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR);

  final String dirPath = FSDirectory.normalizePath(src.substring(0,
      src.length() - HdfsConstants.DOT_SNAPSHOT_DIR.length()));

  final INode node = fsd.getINode(dirPath);
  final INodeDirectory dirNode = INodeDirectory.valueOf(node, dirPath);
  final DirectorySnapshottableFeature sf = dirNode.getDirectorySnapshottableFeature();
  if (sf == null) {
    throw new SnapshotException(
        "Directory is not a snapshottable directory: " + dirPath);
  }
  final ReadOnlyList<Snapshot> snapshots = sf.getSnapshotList();
  int skipSize = ReadOnlyList.Util.binarySearch(snapshots, startAfter);
  skipSize = skipSize < 0 ? -skipSize - 1 : skipSize + 1;
  int numOfListing = Math.min(snapshots.size() - skipSize, fsd.getLsLimit());
  final HdfsFileStatus listing[] = new HdfsFileStatus[numOfListing];
  for (int i = 0; i < numOfListing; i++) {
    Snapshot.Root sRoot = snapshots.get(i + skipSize).getRoot();
    listing[i] = createFileStatus(fsd, src, sRoot.getLocalNameBytes(), sRoot,
        BlockStoragePolicySuite.ID_UNSPECIFIED, Snapshot.CURRENT_STATE_ID,
        false, INodesInPath.fromINode(sRoot));
  }
  return new DirectoryListing(
      listing, snapshots.size() - skipSize - numOfListing);
}
 
Example 2
Source File: FSDirStatAndListingOp.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Get a listing of all the snapshots of a snapshottable directory
 */
private static DirectoryListing getSnapshotsListing(
    FSDirectory fsd, String src, byte[] startAfter)
    throws IOException {
  Preconditions.checkState(fsd.hasReadLock());
  Preconditions.checkArgument(
      src.endsWith(HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR),
      "%s does not end with %s", src, HdfsConstants.SEPARATOR_DOT_SNAPSHOT_DIR);

  final String dirPath = FSDirectory.normalizePath(src.substring(0,
      src.length() - HdfsConstants.DOT_SNAPSHOT_DIR.length()));

  final INode node = fsd.getINode(dirPath);
  final INodeDirectory dirNode = INodeDirectory.valueOf(node, dirPath);
  final DirectorySnapshottableFeature sf = dirNode.getDirectorySnapshottableFeature();
  if (sf == null) {
    throw new SnapshotException(
        "Directory is not a snapshottable directory: " + dirPath);
  }
  final ReadOnlyList<Snapshot> snapshots = sf.getSnapshotList();
  int skipSize = ReadOnlyList.Util.binarySearch(snapshots, startAfter);
  skipSize = skipSize < 0 ? -skipSize - 1 : skipSize + 1;
  int numOfListing = Math.min(snapshots.size() - skipSize, fsd.getLsLimit());
  final HdfsFileStatus listing[] = new HdfsFileStatus[numOfListing];
  for (int i = 0; i < numOfListing; i++) {
    Snapshot.Root sRoot = snapshots.get(i + skipSize).getRoot();
    listing[i] = createFileStatus(fsd, src, sRoot.getLocalNameBytes(), sRoot,
        BlockStoragePolicySuite.ID_UNSPECIFIED, Snapshot.CURRENT_STATE_ID,
        false, INodesInPath.fromINode(sRoot));
  }
  return new DirectoryListing(
      listing, snapshots.size() - skipSize - numOfListing);
}
 
Example 3
Source File: INodeDirectory.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
    final int snapshot) {
  super.dumpTreeRecursively(out, prefix, snapshot);
  out.print(", childrenSize=" + getChildrenList(snapshot).size());
  final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature();
  if (q != null) {
    out.print(", " + q);
  }
  if (this instanceof Snapshot.Root) {
    out.print(", snapshotId=" + snapshot);
  }
  out.println();

  if (prefix.length() >= 2) {
    prefix.setLength(prefix.length() - 2);
    prefix.append("  ");
  }
  dumpTreeRecursively(out, prefix, new Iterable<SnapshotAndINode>() {
    final Iterator<INode> i = getChildrenList(snapshot).iterator();
    
    @Override
    public Iterator<SnapshotAndINode> iterator() {
      return new Iterator<SnapshotAndINode>() {
        @Override
        public boolean hasNext() {
          return i.hasNext();
        }

        @Override
        public SnapshotAndINode next() {
          return new SnapshotAndINode(snapshot, i.next());
        }

        @Override
        public void remove() {
          throw new UnsupportedOperationException();
        }
      };
    }
  });

  final DirectorySnapshottableFeature s = getDirectorySnapshottableFeature();
  if (s != null) {
    s.dumpTreeRecursively(this, out, prefix, snapshot);
  }
}
 
Example 4
Source File: INodeDirectory.java    From big-c with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
@Override
public void dumpTreeRecursively(PrintWriter out, StringBuilder prefix,
    final int snapshot) {
  super.dumpTreeRecursively(out, prefix, snapshot);
  out.print(", childrenSize=" + getChildrenList(snapshot).size());
  final DirectoryWithQuotaFeature q = getDirectoryWithQuotaFeature();
  if (q != null) {
    out.print(", " + q);
  }
  if (this instanceof Snapshot.Root) {
    out.print(", snapshotId=" + snapshot);
  }
  out.println();

  if (prefix.length() >= 2) {
    prefix.setLength(prefix.length() - 2);
    prefix.append("  ");
  }
  dumpTreeRecursively(out, prefix, new Iterable<SnapshotAndINode>() {
    final Iterator<INode> i = getChildrenList(snapshot).iterator();
    
    @Override
    public Iterator<SnapshotAndINode> iterator() {
      return new Iterator<SnapshotAndINode>() {
        @Override
        public boolean hasNext() {
          return i.hasNext();
        }

        @Override
        public SnapshotAndINode next() {
          return new SnapshotAndINode(snapshot, i.next());
        }

        @Override
        public void remove() {
          throw new UnsupportedOperationException();
        }
      };
    }
  });

  final DirectorySnapshottableFeature s = getDirectorySnapshottableFeature();
  if (s != null) {
    s.dumpTreeRecursively(this, out, prefix, snapshot);
  }
}