|
@@ -77,7 +77,9 @@ import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.FsServerDefaults;
|
|
|
import org.apache.hadoop.fs.FsStatus;
|
|
|
import org.apache.hadoop.fs.InvalidPathException;
|
|
|
+import org.apache.hadoop.fs.MD5MD5CRC32CastagnoliFileChecksum;
|
|
|
import org.apache.hadoop.fs.MD5MD5CRC32FileChecksum;
|
|
|
+import org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum;
|
|
|
import org.apache.hadoop.fs.Options;
|
|
|
import org.apache.hadoop.fs.Options.ChecksumOpt;
|
|
|
import org.apache.hadoop.fs.ParentNotDirectoryException;
|
|
@@ -1349,7 +1351,8 @@ public class DFSClient implements java.io.Closeable {
|
|
|
}
|
|
|
List<LocatedBlock> locatedblocks = blockLocations.getLocatedBlocks();
|
|
|
final DataOutputBuffer md5out = new DataOutputBuffer();
|
|
|
- int bytesPerCRC = 0;
|
|
|
+ int bytesPerCRC = -1;
|
|
|
+ DataChecksum.Type crcType = DataChecksum.Type.DEFAULT;
|
|
|
long crcPerBlock = 0;
|
|
|
boolean refetchBlocks = false;
|
|
|
int lastRetriedIndex = -1;
|
|
@@ -1441,6 +1444,17 @@ public class DFSClient implements java.io.Closeable {
|
|
|
final MD5Hash md5 = new MD5Hash(
|
|
|
checksumData.getMd5().toByteArray());
|
|
|
md5.write(md5out);
|
|
|
+
|
|
|
+ // read crc-type
|
|
|
+ final DataChecksum.Type ct = HdfsProtoUtil.
|
|
|
+ fromProto(checksumData.getCrcType());
|
|
|
+ if (i == 0) { // first block
|
|
|
+ crcType = ct;
|
|
|
+ } else if (crcType != DataChecksum.Type.MIXED
|
|
|
+ && crcType != ct) {
|
|
|
+ // if crc types are mixed in a file
|
|
|
+ crcType = DataChecksum.Type.MIXED;
|
|
|
+ }
|
|
|
|
|
|
done = true;
|
|
|
|
|
@@ -1469,7 +1483,18 @@ public class DFSClient implements java.io.Closeable {
|
|
|
|
|
|
//compute file MD5
|
|
|
final MD5Hash fileMD5 = MD5Hash.digest(md5out.getData());
|
|
|
- return new MD5MD5CRC32FileChecksum(bytesPerCRC, crcPerBlock, fileMD5);
|
|
|
+ switch (crcType) {
|
|
|
+ case CRC32:
|
|
|
+ return new MD5MD5CRC32GzipFileChecksum(bytesPerCRC,
|
|
|
+ crcPerBlock, fileMD5);
|
|
|
+ case CRC32C:
|
|
|
+ return new MD5MD5CRC32CastagnoliFileChecksum(bytesPerCRC,
|
|
|
+ crcPerBlock, fileMD5);
|
|
|
+ default:
|
|
|
+ // we should never get here since the validity was checked
|
|
|
+ // when getCrcType() was called above.
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|