Search in sources :

Example 16 with SnapshotDiffReport

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

the class TestRenameWithSnapshots method testRenameDirectoryInSnapshot.

@Test(timeout = 60000)
public void testRenameDirectoryInSnapshot() throws Exception {
    final Path sub2 = new Path(sub1, "sub2");
    final Path sub3 = new Path(sub1, "sub3");
    final Path sub2file1 = new Path(sub2, "sub2file1");
    final String sub1snap1 = "sub1snap1";
    hdfs.mkdirs(sub1);
    hdfs.mkdirs(sub2);
    DFSTestUtil.createFile(hdfs, sub2file1, BLOCKSIZE, REPL, SEED);
    SnapshotTestHelper.createSnapshot(hdfs, sub1, sub1snap1);
    // First rename the sub-directory.
    hdfs.rename(sub2, sub3);
    // 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();
    assertEquals(2, entries.size());
    assertTrue(existsInDiffReport(entries, DiffType.MODIFY, "", null));
    assertTrue(existsInDiffReport(entries, DiffType.RENAME, sub2.getName(), sub3.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 17 with SnapshotDiffReport

use of org.apache.hadoop.hdfs.protocol.SnapshotDiffReport 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 18 with SnapshotDiffReport

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

the class TestDistCpSyncReverseBase method testSync5.

/**
   * Test a case with different delete and rename sequences.
   */
@Test
public void testSync5() throws Exception {
    if (isSrcNotSameAsTgt) {
        initData5(source);
    }
    initData5(target);
    enableAndCreateFirstSnapshot();
    // make changes under target
    int numDeletedAndModified = changeData5(target);
    createSecondSnapshotAtTarget();
    SnapshotDiffReport report = dfs.getSnapshotDiffReport(target, "s2", "s1");
    System.out.println(report);
    testAndVerify(numDeletedAndModified);
}
Also used : SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) Test(org.junit.Test)

Example 19 with SnapshotDiffReport

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

the class TestDistCpSyncReverseBase method testSync4.

/**
   * Test a case where multiple level dirs are renamed.
   */
@Test
public void testSync4() throws Exception {
    if (isSrcNotSameAsTgt) {
        initData4(source);
    }
    initData4(target);
    enableAndCreateFirstSnapshot();
    final FsShell shell = new FsShell(conf);
    lsr("Before change target: ", shell, target);
    // make changes under target
    int numDeletedAndModified = changeData4(target);
    createSecondSnapshotAtTarget();
    SnapshotDiffReport report = dfs.getSnapshotDiffReport(target, "s2", "s1");
    System.out.println(report);
    testAndVerify(numDeletedAndModified);
}
Also used : FsShell(org.apache.hadoop.fs.FsShell) SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) Test(org.junit.Test)

Example 20 with SnapshotDiffReport

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

the class TestDistCpSync method testSync.

/**
   * Test the basic functionality.
   */
@Test
public void testSync() throws Exception {
    initData(source);
    initData(target);
    enableAndCreateFirstSnapshot();
    // make changes under source
    int numCreatedModified = changeData(source);
    dfs.createSnapshot(source, "s2");
    // before sync, make some further changes on source. this should not affect
    // the later distcp since we're copying (s2-s1) to target
    final Path toDelete = new Path(source, "foo/d1/foo/f1");
    dfs.delete(toDelete, true);
    final Path newdir = new Path(source, "foo/d1/foo/newdir");
    dfs.mkdirs(newdir);
    SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
    System.out.println(report);
    DistCpSync distCpSync = new DistCpSync(options, conf);
    // do the sync
    Assert.assertTrue(distCpSync.sync());
    // make sure the source path has been updated to the snapshot path
    final Path spath = new Path(source, HdfsConstants.DOT_SNAPSHOT_DIR + Path.SEPARATOR + "s2");
    Assert.assertEquals(spath, options.getSourcePaths().get(0));
    // build copy listing
    final Path listingPath = new Path("/tmp/META/fileList.seq");
    CopyListing listing = new SimpleCopyListing(conf, new Credentials(), distCpSync);
    listing.buildListing(listingPath, options);
    Map<Text, CopyListingFileStatus> copyListing = getListing(listingPath);
    CopyMapper copyMapper = new CopyMapper();
    StubContext stubContext = new StubContext(conf, null, 0);
    Mapper<Text, CopyListingFileStatus, Text, Text>.Context<Text, CopyListingFileStatus, Text, Text> context = stubContext.getContext();
    // Enable append
    context.getConfiguration().setBoolean(DistCpOptionSwitch.APPEND.getConfigLabel(), true);
    copyMapper.setup(context);
    for (Map.Entry<Text, CopyListingFileStatus> entry : copyListing.entrySet()) {
        copyMapper.map(entry.getKey(), entry.getValue(), context);
    }
    // verify that we only list modified and created files/directories
    Assert.assertEquals(numCreatedModified, copyListing.size());
    // verify that we only copied new appended data of f2 and the new file f1
    Assert.assertEquals(BLOCK_SIZE * 3, stubContext.getReporter().getCounter(CopyMapper.Counter.BYTESCOPIED).getValue());
    // verify the source and target now has the same structure
    verifyCopy(dfs.getFileStatus(spath), dfs.getFileStatus(target), false);
}
Also used : Path(org.apache.hadoop.fs.Path) Text(org.apache.hadoop.io.Text) CopyMapper(org.apache.hadoop.tools.mapred.CopyMapper) Mapper(org.apache.hadoop.mapreduce.Mapper) SnapshotDiffReport(org.apache.hadoop.hdfs.protocol.SnapshotDiffReport) CopyMapper(org.apache.hadoop.tools.mapred.CopyMapper) HashMap(java.util.HashMap) Map(java.util.Map) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

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