Search in sources :

Example 6 with SnapshotDiffReport

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

the class TestRenameWithSnapshots method testRenameTwiceInSnapshot.

@Test(timeout = 60000)
public void testRenameTwiceInSnapshot() throws Exception {
    hdfs.mkdirs(sub1);
    hdfs.allowSnapshot(sub1);
    DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPL, SEED);
    hdfs.createSnapshot(sub1, snap1);
    hdfs.rename(file1, file2);
    hdfs.createSnapshot(sub1, snap2);
    hdfs.rename(file2, file3);
    SnapshotDiffReport diffReport;
    // Query the diff report and make sure it looks as expected.
    diffReport = hdfs.getSnapshotDiffReport(sub1, snap1, snap2);
    LOG.info("DiffList is " + diffReport.toString());
    List<DiffReportEntry> entries = diffReport.getDiffList();
    assertTrue(entries.size() == 2);
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, "", null));
    assertTrue(existsInDiffReport(entries, DiffType.RENAME, file1.getName(), file2.getName()));
    diffReport = hdfs.getSnapshotDiffReport(sub1, snap2, "");
    LOG.info("DiffList is " + diffReport.toString());
    entries = diffReport.getDiffList();
    assertTrue(entries.size() == 2);
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, "", null));
    assertTrue(existsInDiffReport(entries, DiffType.RENAME, file2.getName(), file3.getName()));
    diffReport = hdfs.getSnapshotDiffReport(sub1, snap1, "");
    LOG.info("DiffList is " + diffReport.toString());
    entries = diffReport.getDiffList();
    assertTrue(entries.size() == 2);
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, "", null));
    assertTrue(existsInDiffReport(entries, DiffType.RENAME, file1.getName(), file3.getName()));
}
Also used : SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 7 with SnapshotDiffReport

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

the class TestRenameWithSnapshots method testRenameFileNotInSnapshot.

/**
   * Rename a file under a snapshottable directory, file does not exist
   * in a snapshot.
   */
@Test(timeout = 60000)
public void testRenameFileNotInSnapshot() throws Exception {
    hdfs.mkdirs(sub1);
    hdfs.allowSnapshot(sub1);
    hdfs.createSnapshot(sub1, snap1);
    DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPL, SEED);
    hdfs.rename(file1, file2);
    // Query the diff report and make sure it looks as expected.
    SnapshotDiffReport diffReport = hdfs.getSnapshotDiffReport(sub1, snap1, "");
    List<DiffReportEntry> entries = diffReport.getDiffList();
    assertTrue(entries.size() == 2);
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, "", null));
    assertTrue(existsInDiffReport(entries, DiffType.CREATE, file2.getName(), null));
}
Also used : SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 8 with SnapshotDiffReport

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

the class TestRenameWithSnapshots method testRenameFileInSnapshot.

/**
   * Rename a file under a snapshottable directory, file exists
   * in a snapshot.
   */
@Test
public void testRenameFileInSnapshot() throws Exception {
    hdfs.mkdirs(sub1);
    hdfs.allowSnapshot(sub1);
    DFSTestUtil.createFile(hdfs, file1, BLOCKSIZE, REPL, SEED);
    hdfs.createSnapshot(sub1, snap1);
    hdfs.rename(file1, file2);
    // Query the diff report and make sure it looks as expected.
    SnapshotDiffReport diffReport = hdfs.getSnapshotDiffReport(sub1, snap1, "");
    System.out.println("DiffList is " + diffReport.toString());
    List<DiffReportEntry> entries = diffReport.getDiffList();
    assertTrue(entries.size() == 2);
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, "", null));
    assertTrue(existsInDiffReport(entries, DiffType.RENAME, file1.getName(), file2.getName()));
}
Also used : SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 9 with SnapshotDiffReport

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

the class TestRenameWithSnapshots method testRenameFileInSubDirOfDirWithSnapshot.

@Test(timeout = 60000)
public void testRenameFileInSubDirOfDirWithSnapshot() throws Exception {
    final Path sub2 = new Path(sub1, "sub2");
    final Path sub2file1 = new Path(sub2, "sub2file1");
    final Path sub2file2 = new Path(sub2, "sub2file2");
    final String sub1snap1 = "sub1snap1";
    hdfs.mkdirs(sub1);
    hdfs.mkdirs(sub2);
    DFSTestUtil.createFile(hdfs, sub2file1, BLOCKSIZE, REPL, SEED);
    SnapshotTestHelper.createSnapshot(hdfs, sub1, sub1snap1);
    // Rename the file in the subdirectory.
    hdfs.rename(sub2file1, sub2file2);
    // Query the diff report and make sure it looks as expected.
    SnapshotDiffReport diffReport = hdfs.getSnapshotDiffReport(sub1, sub1snap1, "");
    LOG.info("DiffList is \n\"" + diffReport.toString() + "\"");
    List<DiffReportEntry> entries = diffReport.getDiffList();
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, sub2.getName(), null));
    assertTrue(existsInDiffReport(entries, DiffType.RENAME, sub2.getName() + "/" + sub2file1.getName(), sub2.getName() + "/" + sub2file2.getName()));
}
Also used : Path(org.apache.hadoop.fs.Path) INodesInPath(org.apache.hadoop.hdfs.server.namenode.INodesInPath) SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DiffReportEntry(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry) Test(org.junit.Test)

Example 10 with SnapshotDiffReport

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

the class SnapshotDiff method run.

@Override
public int run(String[] argv) throws Exception {
    String description = "hdfs snapshotDiff <snapshotDir> <from> <to>:\n" + "\tGet the difference between two snapshots, \n" + "\tor between a snapshot and the current tree of a directory.\n" + "\tFor <from>/<to>, users can use \".\" to present the current status,\n" + "\tand use \".snapshot/snapshot_name\" to present a snapshot,\n" + "\twhere \".snapshot/\" can be omitted\n";
    if (argv.length != 3) {
        System.err.println("Usage: \n" + description);
        return 1;
    }
    FileSystem fs = FileSystem.get(new Path(argv[0]).toUri(), getConf());
    if (!(fs instanceof DistributedFileSystem)) {
        System.err.println("SnapshotDiff can only be used in DistributedFileSystem");
        return 1;
    }
    DistributedFileSystem dfs = (DistributedFileSystem) fs;
    Path snapshotRoot = new Path(argv[0]);
    String fromSnapshot = getSnapshotName(argv[1]);
    String toSnapshot = getSnapshotName(argv[2]);
    try {
        SnapshotDiffReport diffReport = dfs.getSnapshotDiffReport(snapshotRoot, fromSnapshot, toSnapshot);
        System.out.println(diffReport.toString());
    } catch (IOException e) {
        String[] content = e.getLocalizedMessage().split("\n");
        System.err.println("snapshotDiff: " + content[0]);
        return 1;
    }
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem)

Aggregations

SnapshotDiffReport (org.apache.hadoop.hdfs.protocol.SnapshotDiffReport)30 Test (org.junit.Test)18 Path (org.apache.hadoop.fs.Path)11 DiffReportEntry (org.apache.hadoop.hdfs.protocol.SnapshotDiffReport.DiffReportEntry)11 HashMap (java.util.HashMap)5 Map (java.util.Map)5 IOException (java.io.IOException)4 Text (org.apache.hadoop.io.Text)4 Mapper (org.apache.hadoop.mapreduce.Mapper)4 Credentials (org.apache.hadoop.security.Credentials)4 CopyMapper (org.apache.hadoop.tools.mapred.CopyMapper)4 FsShell (org.apache.hadoop.fs.FsShell)3 INodesInPath (org.apache.hadoop.hdfs.server.namenode.INodesInPath)3 ArrayList (java.util.ArrayList)2 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)2 ByteString (com.google.protobuf.ByteString)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1