HDFS-2065. Add null checks in DFSClient.getFileChecksum(..). Contributed by Uma Maheswara Rao G
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1195731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c46876982e
commit
8d1a09b741
@ -1232,6 +1232,9 @@ Release 0.23.0 - Unreleased
|
||||
getFileStatus on non-existing files; fix bugs in getBlockLocations; and
|
||||
changed getFileChecksum json response root to "FileChecksum". (szetszwo)
|
||||
|
||||
HDFS-2065. Add null checks in DFSClient.getFileChecksum(..). (Uma
|
||||
Maheswara Rao G via szetszwo)
|
||||
|
||||
BREAKDOWN OF HDFS-1073 SUBTASKS
|
||||
|
||||
HDFS-1521. Persist transaction ID on disk between NN restarts.
|
||||
|
@ -1106,8 +1106,11 @@ public static MD5MD5CRC32FileChecksum getFileChecksum(String src,
|
||||
ClientProtocol namenode, SocketFactory socketFactory, int socketTimeout
|
||||
) throws IOException {
|
||||
//get all block locations
|
||||
List<LocatedBlock> locatedblocks
|
||||
= callGetBlockLocations(namenode, src, 0, Long.MAX_VALUE).getLocatedBlocks();
|
||||
LocatedBlocks blockLocations = callGetBlockLocations(namenode, src, 0, Long.MAX_VALUE);
|
||||
if (null == blockLocations) {
|
||||
throw new FileNotFoundException("File does not exist: " + src);
|
||||
}
|
||||
List<LocatedBlock> locatedblocks = blockLocations.getLocatedBlocks();
|
||||
final DataOutputBuffer md5out = new DataOutputBuffer();
|
||||
int bytesPerCRC = 0;
|
||||
long crcPerBlock = 0;
|
||||
@ -1117,8 +1120,11 @@ public static MD5MD5CRC32FileChecksum getFileChecksum(String src,
|
||||
//get block checksum for each block
|
||||
for(int i = 0; i < locatedblocks.size(); i++) {
|
||||
if (refetchBlocks) { // refetch to get fresh tokens
|
||||
locatedblocks = callGetBlockLocations(namenode, src, 0, Long.MAX_VALUE)
|
||||
.getLocatedBlocks();
|
||||
blockLocations = callGetBlockLocations(namenode, src, 0, Long.MAX_VALUE);
|
||||
if (null == blockLocations) {
|
||||
throw new FileNotFoundException("File does not exist: " + src);
|
||||
}
|
||||
locatedblocks = blockLocations.getLocatedBlocks();
|
||||
refetchBlocks = false;
|
||||
}
|
||||
LocatedBlock lb = locatedblocks.get(i);
|
||||
|
@ -412,6 +412,25 @@ public void testFileChecksum() throws Exception {
|
||||
final UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
|
||||
current.getShortUserName() + "x", new String[]{"user"});
|
||||
|
||||
try {
|
||||
((DistributedFileSystem) hdfs).getFileChecksum(new Path(
|
||||
"/test/TestNonExistingFile"));
|
||||
fail("Expecting FileNotFoundException");
|
||||
} catch (FileNotFoundException e) {
|
||||
assertTrue("Not throwing the intended exception message", e.getMessage()
|
||||
.contains("File does not exist: /test/TestNonExistingFile"));
|
||||
}
|
||||
|
||||
try {
|
||||
Path path = new Path("/test/TestExistingDir/");
|
||||
hdfs.mkdirs(path);
|
||||
((DistributedFileSystem) hdfs).getFileChecksum(path);
|
||||
fail("Expecting FileNotFoundException");
|
||||
} catch (FileNotFoundException e) {
|
||||
assertTrue("Not throwing the intended exception message", e.getMessage()
|
||||
.contains("File does not exist: /test/TestExistingDir"));
|
||||
}
|
||||
|
||||
//hftp
|
||||
final String hftpuri = "hftp://" + nnAddr;
|
||||
System.out.println("hftpuri=" + hftpuri);
|
||||
|
Loading…
Reference in New Issue
Block a user