From 06ffeb8d4d705d14e8755364099286ac4ed3bb83 Mon Sep 17 00:00:00 2001 From: Masatake Iwasaki Date: Wed, 10 May 2017 14:14:20 +0900 Subject: [PATCH] HADOOP-14405. Fix performance regression due to incorrect use of DataChecksum. Contributed by LiXin Ge. --- .../java/org/apache/hadoop/util/DataChecksum.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java index 6982a920d24..03946afe04d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DataChecksum.java @@ -296,12 +296,20 @@ public class DataChecksum implements Checksum { public void verifyChunkedSums(ByteBuffer data, ByteBuffer checksums, String fileName, long basePos) throws ChecksumException { if (type.size == 0) return; - + if (data.hasArray() && checksums.hasArray()) { final int dataOffset = data.arrayOffset() + data.position(); final int crcsOffset = checksums.arrayOffset() + checksums.position(); - verifyChunked(type, summer, data.array(), dataOffset, data.remaining(), - bytesPerChecksum, checksums.array(), crcsOffset, fileName, basePos); + + if (NativeCrc32.isAvailable()) { + NativeCrc32.verifyChunkedSumsByteArray(bytesPerChecksum, type.id, + checksums.array(), crcsOffset, data.array(), dataOffset, + data.remaining(), fileName, basePos); + } else { + verifyChunked(type, summer, data.array(), dataOffset, data.remaining(), + bytesPerChecksum, checksums.array(), crcsOffset, fileName, + basePos); + } return; } if (NativeCrc32.isAvailable() && data.isDirect()) {