Search in sources :

Example 6 with DiffReportEntry

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

the class TestSnapshotDiffReport method testDiffReportWithRenameAndDelete.

/**
   * Renaming a file/dir then delete the ancestor dir of the rename target
   * should be reported as deleted.
   */
@Test
public void testDiffReportWithRenameAndDelete() 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);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s0");
    hdfs.rename(fileInFoo, fileInBar, Rename.OVERWRITE);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s1");
    verifyDiffReport(root, "s0", "s1", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("dir1/foo")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("dir2/bar")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("dir2/bar/file")), new DiffReportEntry(DiffType.RENAME, DFSUtil.string2Bytes("dir1/foo/file"), DFSUtil.string2Bytes("dir2/bar/file")));
    // delete bar
    hdfs.delete(bar, true);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s2");
    verifyDiffReport(root, "s0", "s2", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("dir1/foo")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("dir2")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("dir2/bar")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("dir1/foo/file")));
}
Also used : Path(org.apache.hadoop.fs.Path) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 7 with DiffReportEntry

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

the class TestSnapshotDiffReport method testDiffReportWithRenameToNewDir.

@Test
public void testDiffReportWithRenameToNewDir() throws Exception {
    final Path root = new Path("/");
    final Path foo = new Path(root, "foo");
    final Path fileInFoo = new Path(foo, "file");
    DFSTestUtil.createFile(hdfs, fileInFoo, BLOCKSIZE, REPLICATION, seed);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s0");
    final Path bar = new Path(root, "bar");
    hdfs.mkdirs(bar);
    final Path fileInBar = new Path(bar, "file");
    hdfs.rename(fileInFoo, fileInBar);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s1");
    verifyDiffReport(root, "s0", "s1", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("foo")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("bar")), new DiffReportEntry(DiffType.RENAME, DFSUtil.string2Bytes("foo/file"), DFSUtil.string2Bytes("bar/file")));
}
Also used : Path(org.apache.hadoop.fs.Path) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 8 with DiffReportEntry

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

the class TestSnapshotDiffReport method verifyDiffReport.

/** check the correctness of the diff reports */
private void verifyDiffReport(Path dir, String from, String to, DiffReportEntry... entries) throws IOException {
    SnapshotDiffReport report = hdfs.getSnapshotDiffReport(dir, from, to);
    // reverse the order of from and to
    SnapshotDiffReport inverseReport = hdfs.getSnapshotDiffReport(dir, to, from);
    System.out.println(report.toString());
    System.out.println(inverseReport.toString() + "\n");
    assertEquals(entries.length, report.getDiffList().size());
    assertEquals(entries.length, inverseReport.getDiffList().size());
    for (DiffReportEntry entry : entries) {
        if (entry.getType() == DiffType.MODIFY) {
            assertTrue(report.getDiffList().contains(entry));
            assertTrue(inverseReport.getDiffList().contains(entry));
        } else if (entry.getType() == DiffType.DELETE) {
            assertTrue(report.getDiffList().contains(entry));
            assertTrue(inverseReport.getDiffList().contains(new DiffReportEntry(DiffType.CREATE, entry.getSourcePath())));
        } else if (entry.getType() == DiffType.CREATE) {
            assertTrue(report.getDiffList().contains(entry));
            assertTrue(inverseReport.getDiffList().contains(new DiffReportEntry(DiffType.DELETE, entry.getSourcePath())));
        }
    }
}
Also used : SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry)

Example 9 with DiffReportEntry

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

the class TestSnapshotDiffReport method testDiffReportWithRenameAndSnapshotDeletion.

/**
   * Nested renamed dir/file and the withNameList in the WithCount node of the
   * parental directory is empty due to snapshot deletion. See HDFS-6996 for
   * details.
   */
@Test
public void testDiffReportWithRenameAndSnapshotDeletion() throws Exception {
    final Path root = new Path("/");
    final Path foo = new Path(root, "foo");
    final Path bar = new Path(foo, "bar");
    DFSTestUtil.createFile(hdfs, bar, BLOCKSIZE, REPLICATION, seed);
    SnapshotTestHelper.createSnapshot(hdfs, root, "s0");
    // rename /foo to /foo2
    final Path foo2 = new Path(root, "foo2");
    hdfs.rename(foo, foo2);
    // now /foo/bar becomes /foo2/bar
    final Path bar2 = new Path(foo2, "bar");
    // delete snapshot s0 so that the withNameList inside of the WithCount node
    // of foo becomes empty
    hdfs.deleteSnapshot(root, "s0");
    // create snapshot s1 and rename bar again
    SnapshotTestHelper.createSnapshot(hdfs, root, "s1");
    final Path bar3 = new Path(foo2, "bar-new");
    hdfs.rename(bar2, bar3);
    // we always put modification on the file before rename
    verifyDiffReport(root, "s1", "", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("foo2")), new DiffReportEntry(DiffType.RENAME, DFSUtil.string2Bytes("foo2/bar"), DFSUtil.string2Bytes("foo2/bar-new")));
}
Also used : Path(org.apache.hadoop.fs.Path) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 10 with DiffReportEntry

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

the class TestSnapshotDiffReport method testDiffReport.

/** Test the computation and representation of diff between snapshots */
@Test(timeout = 60000)
public void testDiffReport() throws Exception {
    cluster.getNamesystem().getSnapshotManager().setAllowNestedSnapshots(true);
    Path subsub1 = new Path(sub1, "subsub1");
    Path subsubsub1 = new Path(subsub1, "subsubsub1");
    hdfs.mkdirs(subsubsub1);
    modifyAndCreateSnapshot(sub1, new Path[] { sub1, subsubsub1 });
    modifyAndCreateSnapshot(subsubsub1, new Path[] { sub1, subsubsub1 });
    try {
        hdfs.getSnapshotDiffReport(subsub1, "s1", "s2");
        fail("Expect exception when getting snapshot diff report: " + subsub1 + " is not a snapshottable directory.");
    } catch (IOException e) {
        GenericTestUtils.assertExceptionContains("Directory is not a snapshottable directory: " + subsub1, e);
    }
    final String invalidName = "invalid";
    try {
        hdfs.getSnapshotDiffReport(sub1, invalidName, invalidName);
        fail("Expect exception when providing invalid snapshot name for diff report");
    } catch (IOException e) {
        GenericTestUtils.assertExceptionContains("Cannot find the snapshot of directory " + sub1 + " with name " + invalidName, e);
    }
    // diff between the same snapshot
    SnapshotDiffReport report = hdfs.getSnapshotDiffReport(sub1, "s0", "s0");
    System.out.println(report);
    assertEquals(0, report.getDiffList().size());
    report = hdfs.getSnapshotDiffReport(sub1, "", "");
    System.out.println(report);
    assertEquals(0, report.getDiffList().size());
    report = hdfs.getSnapshotDiffReport(subsubsub1, "s0", "s2");
    System.out.println(report);
    assertEquals(0, report.getDiffList().size());
    // test path with scheme also works
    report = hdfs.getSnapshotDiffReport(hdfs.makeQualified(subsubsub1), "s0", "s2");
    System.out.println(report);
    assertEquals(0, report.getDiffList().size());
    verifyDiffReport(sub1, "s0", "s2", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("file15")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file12")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file11")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("file11")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file13")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("link13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("link13")));
    verifyDiffReport(sub1, "s0", "s5", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("file15")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file12")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file10")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file11")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("file11")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file13")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("link13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("link13")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("subsub1/subsubsub1")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file10")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file11")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/link13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file15")));
    verifyDiffReport(sub1, "s2", "s5", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file10")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("subsub1/subsubsub1")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file10")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file11")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/link13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file15")));
    verifyDiffReport(sub1, "s3", "", new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("subsub1/subsubsub1")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file15")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("subsub1/subsubsub1/file12")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("subsub1/subsubsub1/file10")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("subsub1/subsubsub1/file11")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/file11")), new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("subsub1/subsubsub1/file13")), new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("subsub1/subsubsub1/link13")), new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("subsub1/subsubsub1/link13")));
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) IOException(java.io.IOException) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

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