Search in sources :

Example 16 with DiffReportEntry

use of org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry in project hadoop by apache.

the class TestSnapshotDiffReport method testDiffReportWithRenameAndAppend.

/**
   * Rename a file and then append some data to it
   */
@Test
public void testDiffReportWithRenameAndAppend() throws Exception {
    final Path root = new Path("/");
    final Path foo = new Path(root, "foo");
    DFSTestUtil.createFile(hdfs, foo, BLOCKSIZE, REPLICATION, seed);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s0");
    final Path bar = new Path(root, "bar");
    hdfs.rename(foo, bar);
    // append 10 bytes
    DFSTestUtil.appendFile(hdfs, bar, 10);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s1");
    // we always put modification on the file before rename
    verifyDiffReport(root, "s0", "s1", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("foo")), new DiffReportEntry(DiffType.RENAME, DFSUtil.string2Bytes("foo"), DFSUtil.string2Bytes("bar")));
}
Also used : Path(org.apache.hadoop.fs.Path) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 17 with DiffReportEntry

use of org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry in project hadoop by apache.

the class TestSnapshotDiffReport method testDiffReportWithRenameOutside.

/**
   * Rename a file/dir outside of the snapshottable dir should be reported as
   * deleted. Rename a file/dir from outside should be reported as created.
   */
@Test
public void testDiffReportWithRenameOutside() throws Exception {
    final Path root = new Path("/");
    final Path dir1 = new Path(root, "dir1");
    final Path dir2 = new Path(root, "dir2");
    final Path foo = new Path(dir1, "foo");
    final Path fileInFoo = new Path(foo, "file");
    final Path bar = new Path(dir2, "bar");
    final Path fileInBar = new Path(bar, "file");
    DFSTestUtil.createFile(hdfs, fileInFoo, BLOCKSIZE, REPLICATION, seed);
    DFSTestUtil.createFile(hdfs, fileInBar, BLOCKSIZE, REPLICATION, seed);
    // create snapshot on /dir1
    SnapshotTestHelper.createSnapshot(hdfs, dir1, "s0");
    // move bar into dir1
    final Path newBar = new Path(dir1, "newBar");
    hdfs.rename(bar, newBar);
    // move foo out of dir1 into dir2
    final Path newFoo = new Path(dir2, "new");
    hdfs.rename(foo, newFoo);
    SnapshotTestHelper.createSnapshot(hdfs, dir1, "s1");
    verifyDiffReport(dir1, "s0", "s1", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes(newBar.getName())), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes(foo.getName())));
}
Also used : Path(org.apache.hadoop.fs.Path) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 18 with DiffReportEntry

use of org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry in project hadoop by apache.

the class PBHelperClient method convert.

public static SnapshotDiffReportProto convert(SnapshotDiffReport report) {
    if (report == null) {
        return null;
    }
    List<DiffReportEntry> entries = report.getDiffList();
    List<SnapshotDiffReportEntryProto> entryProtos = new ArrayList<>();
    for (DiffReportEntry entry : entries) {
        SnapshotDiffReportEntryProto entryProto = convert(entry);
        if (entryProto != null)
            entryProtos.add(entryProto);
    }
    return SnapshotDiffReportProto.newBuilder().setSnapshotRoot(report.getSnapshotRoot()).setFromSnapshot(report.getFromSnapshot()).setToSnapshot(report.getLaterSnapshotName()).addAllDiffReportEntries(entryProtos).build();
}
Also used : ArrayList(java.util.ArrayList) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) SnapshotDiffReportEntryProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.SnapshotDiffReportEntryProto)

Example 19 with DiffReportEntry

use of org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry in project hadoop by apache.

the class PBHelperClient method convert.

public static SnapshotDiffReport convert(SnapshotDiffReportProto reportProto) {
    if (reportProto == null) {
        return null;
    }
    String snapshotDir = reportProto.getSnapshotRoot();
    String fromSnapshot = reportProto.getFromSnapshot();
    String toSnapshot = reportProto.getToSnapshot();
    List<SnapshotDiffReportEntryProto> list = reportProto.getDiffReportEntriesList();
    List<DiffReportEntry> entries = new ArrayList<>();
    for (SnapshotDiffReportEntryProto entryProto : list) {
        DiffReportEntry entry = convert(entryProto);
        if (entry != null)
            entries.add(entry);
    }
    return new SnapshotDiffReport(snapshotDir, fromSnapshot, toSnapshot, entries);
}
Also used : SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) SnapshotDiffReportEntryProto(org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.SnapshotDiffReportEntryProto)

Example 20 with DiffReportEntry

use of org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry in project hadoop by apache.

the class SnapshotManager method diff.

/**
   * Compute the difference between two snapshots of a directory, or between a
   * snapshot of the directory and its current tree.
   */
public SnapshotDiffReport diff(final INodesInPath iip, final String snapshotRootPath, final String from, final String to) throws IOException {
    // Find the source root directory path where the snapshots were taken.
    // All the check for path has been included in the valueOf method.
    final INodeDirectory snapshotRoot = getSnapshottableRoot(iip);
    if ((from == null || from.isEmpty()) && (to == null || to.isEmpty())) {
        // both fromSnapshot and toSnapshot indicate the current tree
        return new SnapshotDiffReport(snapshotRootPath, from, to, Collections.<DiffReportEntry>emptyList());
    }
    final SnapshotDiffInfo diffs = snapshotRoot.getDirectorySnapshottableFeature().computeDiff(snapshotRoot, from, to);
    return diffs != null ? diffs.generateReport() : new SnapshotDiffReport(snapshotRootPath, from, to, Collections.<DiffReportEntry>emptyList());
}
Also used : INodeDirectory(org.apache.hadoop.hdfs.server.namenode.INodeDirectory) SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry)

Aggregations

DiffReportEntry (org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry)20 Test (org.junit.Test)14 Path (org.apache.hadoop.fs.Path)11 SnapshotDiffReport (org.apache.hadoop.hdfs.protocol.SnapshotDiffReport)11 ArrayList (java.util.ArrayList)4 INodesInPath (org.apache.hadoop.hdfs.server.namenode.INodesInPath)3 SnapshotDiffReportEntryProto (org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.SnapshotDiffReportEntryProto)2 INode (org.apache.hadoop.hdfs.server.namenode.INode)2 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 INodeDirectory (org.apache.hadoop.hdfs.server.namenode.INodeDirectory)1