|
@@ -17,6 +17,7 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.hdfs.server.datanode.erasurecode;
|
|
|
|
|
|
+import java.io.Closeable;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.ByteBuffer;
|
|
|
import java.util.Arrays;
|
|
@@ -32,7 +33,7 @@ import org.apache.hadoop.io.DataOutputBuffer;
|
|
|
*/
|
|
|
@InterfaceAudience.Private
|
|
|
public abstract class StripedBlockChecksumReconstructor
|
|
|
- extends StripedReconstructor {
|
|
|
+ extends StripedReconstructor implements Closeable {
|
|
|
private ByteBuffer targetBuffer;
|
|
|
private final byte[] targetIndices;
|
|
|
|
|
@@ -73,31 +74,27 @@ public abstract class StripedBlockChecksumReconstructor
|
|
|
public void reconstruct() throws IOException {
|
|
|
prepareDigester();
|
|
|
long maxTargetLength = getMaxTargetLength();
|
|
|
- try {
|
|
|
- while (requestedLen > 0 && getPositionInBlock() < maxTargetLength) {
|
|
|
- long remaining = maxTargetLength - getPositionInBlock();
|
|
|
- final int toReconstructLen = (int) Math
|
|
|
- .min(getStripedReader().getBufferSize(), remaining);
|
|
|
- // step1: read from minimum source DNs required for reconstruction.
|
|
|
- // The returned success list is the source DNs we do real read from
|
|
|
- getStripedReader().readMinimumSources(toReconstructLen);
|
|
|
-
|
|
|
- // step2: decode to reconstruct targets
|
|
|
- reconstructTargets(toReconstructLen);
|
|
|
-
|
|
|
- // step3: calculate checksum
|
|
|
- checksumDataLen += checksumWithTargetOutput(
|
|
|
- getBufferArray(targetBuffer), toReconstructLen);
|
|
|
-
|
|
|
- updatePositionInBlock(toReconstructLen);
|
|
|
- requestedLen -= toReconstructLen;
|
|
|
- clearBuffers();
|
|
|
- }
|
|
|
-
|
|
|
- commitDigest();
|
|
|
- } finally {
|
|
|
- cleanup();
|
|
|
+ while (requestedLen > 0 && getPositionInBlock() < maxTargetLength) {
|
|
|
+ long remaining = maxTargetLength - getPositionInBlock();
|
|
|
+ final int toReconstructLen = (int) Math
|
|
|
+ .min(getStripedReader().getBufferSize(), remaining);
|
|
|
+ // step1: read from minimum source DNs required for reconstruction.
|
|
|
+ // The returned success list is the source DNs we do real read from
|
|
|
+ getStripedReader().readMinimumSources(toReconstructLen);
|
|
|
+
|
|
|
+ // step2: decode to reconstruct targets
|
|
|
+ reconstructTargets(toReconstructLen);
|
|
|
+
|
|
|
+ // step3: calculate checksum
|
|
|
+ checksumDataLen += checksumWithTargetOutput(
|
|
|
+ getBufferArray(targetBuffer), toReconstructLen);
|
|
|
+
|
|
|
+ updatePositionInBlock(toReconstructLen);
|
|
|
+ requestedLen -= toReconstructLen;
|
|
|
+ clearBuffers();
|
|
|
}
|
|
|
+
|
|
|
+ commitDigest();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -222,4 +219,10 @@ public abstract class StripedBlockChecksumReconstructor
|
|
|
}
|
|
|
return buff;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void close() throws IOException {
|
|
|
+ getStripedReader().close();
|
|
|
+ cleanup();
|
|
|
+ }
|
|
|
}
|