Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDFS-15643. EC: Fix checksum computation in case of native encoders. #2424

Merged
merged 1 commit into from Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -87,7 +87,7 @@ public void reconstruct() throws IOException {

// step3: calculate checksum
checksumDataLen += checksumWithTargetOutput(
targetBuffer.array(), toReconstructLen);
getBufferArray(targetBuffer), toReconstructLen);

updatePositionInBlock(toReconstructLen);
requestedLen -= toReconstructLen;
Expand Down Expand Up @@ -140,7 +140,7 @@ private long checksumWithTargetOutput(byte[] outputData, int toReconstructLen)
// case-2) length of data bytes which is less than bytesPerCRC
if (requestedLen <= toReconstructLen) {
int remainingLen = Math.toIntExact(requestedLen);
outputData = Arrays.copyOf(targetBuffer.array(), remainingLen);
outputData = Arrays.copyOf(outputData, remainingLen);

int partialLength = remainingLen % getChecksum().getBytesPerChecksum();

Expand Down Expand Up @@ -207,4 +207,19 @@ private void clearBuffers() {
public long getChecksumDataLen() {
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;
}
}