HADOOP-13828. Implement getFileChecksum(path, length) for ViewFileSystem. Contributed by Manoj Govindassamy.

This commit is contained in:
Andrew Wang 2016-11-28 11:54:43 -08:00
parent 5d5614f847
commit a2b1ff0257
3 changed files with 44 additions and 0 deletions

View File

@ -221,6 +221,12 @@ public FileChecksum getFileChecksum(final Path f)
return super.getFileChecksum(fullPath(f));
}
@Override
public FileChecksum getFileChecksum(final Path f, final long length)
throws IOException {
return super.getFileChecksum(fullPath(f), length);
}
@Override
public FileStatus getFileStatus(final Path f)
throws IOException {

View File

@ -350,6 +350,15 @@ public FileChecksum getFileChecksum(final Path f)
return res.targetFileSystem.getFileChecksum(res.remainingPath);
}
@Override
public FileChecksum getFileChecksum(final Path f, final long length)
throws AccessControlException, FileNotFoundException,
IOException {
InodeTree.ResolveResult<FileSystem> res =
fsState.resolve(getUriPath(f), true);
return res.targetFileSystem.getFileChecksum(res.remainingPath, length);
}
private static FileStatus fixFileStatus(FileStatus orig,
Path qualified) throws IOException {
// FileStatus#getPath is a fully qualified path relative to the root of

View File

@ -31,6 +31,8 @@
import org.apache.hadoop.crypto.key.JavaKeyStoreProvider;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileChecksum;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileSystemTestHelper;
import org.apache.hadoop.fs.FsConstants;
@ -218,4 +220,31 @@ public void testDf() throws Exception {
DFSTestUtil.FsShellRun("-df /", 0, null, newConf);
DFSTestUtil.FsShellRun("-df", 0, null, newConf);
}
@Test
public void testFileChecksum() throws IOException {
ViewFileSystem viewFs = (ViewFileSystem) fsView;
Path mountDataRootPath = new Path("/data");
String fsTargetFileName = "debug.log";
Path fsTargetFilePath = new Path(targetTestRoot, "data/debug.log");
Path mountDataFilePath = new Path(mountDataRootPath, fsTargetFileName);
fileSystemTestHelper.createFile(fsTarget, fsTargetFilePath);
FileStatus fileStatus = viewFs.getFileStatus(mountDataFilePath);
long fileLength = fileStatus.getLen();
FileChecksum fileChecksumViaViewFs =
viewFs.getFileChecksum(mountDataFilePath);
FileChecksum fileChecksumViaTargetFs =
fsTarget.getFileChecksum(fsTargetFilePath);
Assert.assertTrue("File checksum not matching!",
fileChecksumViaViewFs.equals(fileChecksumViaTargetFs));
fileChecksumViaViewFs =
viewFs.getFileChecksum(mountDataFilePath, fileLength / 2);
fileChecksumViaTargetFs =
fsTarget.getFileChecksum(fsTargetFilePath, fileLength / 2);
Assert.assertTrue("File checksum not matching!",
fileChecksumViaViewFs.equals(fileChecksumViaTargetFs));
}
}