Search in sources :

Example 6 with DirectorySnapshottableFeature

use of org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature in project hadoop by apache.

the class FSNamesystem method listCorruptFileBlocksWithSnapshot.

/**
   * Get the list of corrupt blocks and corresponding full file path
   * including snapshots in given snapshottable directories.
   * @param path Restrict corrupt files to this portion of namespace.
   * @param snapshottableDirs Snapshottable directories. Passing in null
   *                          will only return corrupt blocks in non-snapshots.
   * @param cookieTab Support for continuation; cookieTab tells where
   *                  to start from.
   * @return a list in which each entry describes a corrupt file/block
   * @throws IOException
   */
List<String> listCorruptFileBlocksWithSnapshot(String path, List<String> snapshottableDirs, String[] cookieTab) throws IOException {
    final Collection<CorruptFileBlockInfo> corruptFileBlocks = listCorruptFileBlocks(path, cookieTab);
    List<String> list = new ArrayList<String>();
    // Precalculate snapshottableFeature list
    List<DirectorySnapshottableFeature> lsf = new ArrayList<>();
    if (snapshottableDirs != null) {
        for (String snap : snapshottableDirs) {
            final INode isnap = getFSDirectory().getINode(snap, DirOp.READ_LINK);
            final DirectorySnapshottableFeature sf = isnap.asDirectory().getDirectorySnapshottableFeature();
            if (sf == null) {
                throw new SnapshotException("Directory is not a snapshottable directory: " + snap);
            }
            lsf.add(sf);
        }
    }
    for (CorruptFileBlockInfo c : corruptFileBlocks) {
        if (getFileInfo(c.path, true) != null) {
            list.add(c.toString());
        }
        final Collection<String> snaps = FSDirSnapshotOp.getSnapshotFiles(getFSDirectory(), lsf, c.path);
        if (snaps != null) {
            for (String snap : snaps) {
                // follow the syntax of CorruptFileBlockInfo#toString()
                list.add(c.block.getBlockName() + "\t" + snap);
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) DirectorySnapshottableFeature(org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature) SnapshotException(org.apache.hadoop.hdfs.protocol.SnapshotException)

Example 7 with DirectorySnapshottableFeature

use of org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature in project hadoop by apache.

the class INodeDirectory method dumpTreeRecursively.

@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);
    }
}
Also used : Iterator(java.util.Iterator) DirectorySnapshottableFeature(org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

DirectorySnapshottableFeature (org.apache.hadoop.hdfs.server.namenode.snapshot.DirectorySnapshottableFeature)7 SnapshotException (org.apache.hadoop.hdfs.protocol.SnapshotException)3 ArrayList (java.util.ArrayList)2 DirectoryWithSnapshotFeature (org.apache.hadoop.hdfs.server.namenode.snapshot.DirectoryWithSnapshotFeature)2 Snapshot (org.apache.hadoop.hdfs.server.namenode.snapshot.Snapshot)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Iterator (java.util.Iterator)1 DirectoryListing (org.apache.hadoop.hdfs.protocol.DirectoryListing)1 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)1 ChunkedArrayList (org.apache.hadoop.util.ChunkedArrayList)1