Skip to content

Commit cb11fd8

Browse files
committed
HDFS-15643. EC: Fix checksum computation in case of native encoders. (#2424). Contributed by Ayush Saxena.
1 parent e48dd9d commit cb11fd8

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/erasurecode/StripedBlockChecksumReconstructor.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void reconstruct() throws IOException {
8787

8888
// step3: calculate checksum
8989
checksumDataLen += checksumWithTargetOutput(
90-
targetBuffer.array(), toReconstructLen);
90+
getBufferArray(targetBuffer), toReconstructLen);
9191

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

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

@@ -207,4 +207,19 @@ private void clearBuffers() {
207207
public long getChecksumDataLen() {
208208
return checksumDataLen;
209209
}
210-
}
210+
211+
/**
212+
* Gets an array corresponding the buffer.
213+
* @param buffer the input buffer.
214+
* @return the array with content of the buffer.
215+
*/
216+
private static byte[] getBufferArray(ByteBuffer buffer) {
217+
byte[] buff = new byte[buffer.remaining()];
218+
if (buffer.hasArray()) {
219+
buff = buffer.array();
220+
} else {
221+
buffer.slice().get(buff);
222+
}
223+
return buff;
224+
}
225+
}

0 commit comments

Comments
 (0)