HADOOP-13828. Implement getFileChecksum(path, length) for ViewFileSystem. Contributed by Manoj Govindassamy.
This commit is contained in:
parent
5d5614f847
commit
a2b1ff0257
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user