HDFS-15643. EC: Fix checksum computation in case of native encoders. (#2424). Contributed by Ayush Saxena.

This commit is contained in:
Ayush Saxena 2020-11-04 09:28:44 +05:30 committed by GitHub
parent d07dc7afb4
commit 7ac7840fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 3 deletions

View File

@ -87,7 +87,7 @@ public abstract class StripedBlockChecksumReconstructor
// step3: calculate checksum // step3: calculate checksum
checksumDataLen += checksumWithTargetOutput( checksumDataLen += checksumWithTargetOutput(
targetBuffer.array(), toReconstructLen); getBufferArray(targetBuffer), toReconstructLen);
updatePositionInBlock(toReconstructLen); updatePositionInBlock(toReconstructLen);
requestedLen -= toReconstructLen; requestedLen -= toReconstructLen;
@ -140,7 +140,7 @@ public abstract class StripedBlockChecksumReconstructor
// case-2) length of data bytes which is less than bytesPerCRC // case-2) length of data bytes which is less than bytesPerCRC
if (requestedLen <= toReconstructLen) { if (requestedLen <= toReconstructLen) {
int remainingLen = Math.toIntExact(requestedLen); int remainingLen = Math.toIntExact(requestedLen);
outputData = Arrays.copyOf(targetBuffer.array(), remainingLen); outputData = Arrays.copyOf(outputData, remainingLen);
int partialLength = remainingLen % getChecksum().getBytesPerChecksum(); int partialLength = remainingLen % getChecksum().getBytesPerChecksum();
@ -207,4 +207,19 @@ public abstract class StripedBlockChecksumReconstructor
public long getChecksumDataLen() { public long getChecksumDataLen() {
return checksumDataLen; return checksumDataLen;
} }
}
/**
* Gets an array corresponding the buffer.
* @param buffer the input buffer.
* @return the array with content of the buffer.
*/
private static byte[] getBufferArray(ByteBuffer buffer) {
byte[] buff = new byte[buffer.remaining()];
if (buffer.hasArray()) {
buff = buffer.array();
} else {
buffer.slice().get(buff);
}
return buff;
}
}