|
@@ -19,7 +19,7 @@ package org.apache.hadoop.io.erasurecode.rawcoder;
|
|
|
|
|
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
-import org.apache.hadoop.io.erasurecode.rawcoder.util.CoderUtil;
|
|
|
|
|
|
+import org.apache.hadoop.io.erasurecode.ErasureCoderOptions;
|
|
import org.apache.hadoop.io.erasurecode.rawcoder.util.RSUtil;
|
|
import org.apache.hadoop.io.erasurecode.rawcoder.util.RSUtil;
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteBuffer;
|
|
@@ -34,7 +34,7 @@ import java.nio.ByteBuffer;
|
|
* addressed in HADOOP-11871.
|
|
* addressed in HADOOP-11871.
|
|
*/
|
|
*/
|
|
@InterfaceAudience.Private
|
|
@InterfaceAudience.Private
|
|
-public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
|
|
|
|
+public class RSRawDecoderLegacy extends RawErasureDecoder {
|
|
// To describe and calculate the needed Vandermonde matrix
|
|
// To describe and calculate the needed Vandermonde matrix
|
|
private int[] errSignature;
|
|
private int[] errSignature;
|
|
private int[] primitivePower;
|
|
private int[] primitivePower;
|
|
@@ -61,16 +61,16 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
private ByteBuffer[] adjustedDirectBufferOutputsParameter =
|
|
private ByteBuffer[] adjustedDirectBufferOutputsParameter =
|
|
new ByteBuffer[getNumParityUnits()];
|
|
new ByteBuffer[getNumParityUnits()];
|
|
|
|
|
|
- public RSRawDecoderLegacy(int numDataUnits, int numParityUnits) {
|
|
|
|
- super(numDataUnits, numParityUnits);
|
|
|
|
- if (numDataUnits + numParityUnits >= RSUtil.GF.getFieldSize()) {
|
|
|
|
|
|
+ public RSRawDecoderLegacy(ErasureCoderOptions coderOptions) {
|
|
|
|
+ super(coderOptions);
|
|
|
|
+ if (getNumAllUnits() >= RSUtil.GF.getFieldSize()) {
|
|
throw new HadoopIllegalArgumentException(
|
|
throw new HadoopIllegalArgumentException(
|
|
"Invalid numDataUnits and numParityUnits");
|
|
"Invalid numDataUnits and numParityUnits");
|
|
}
|
|
}
|
|
|
|
|
|
- this.errSignature = new int[numParityUnits];
|
|
|
|
- this.primitivePower = RSUtil.getPrimitivePower(numDataUnits,
|
|
|
|
- numParityUnits);
|
|
|
|
|
|
+ this.errSignature = new int[getNumParityUnits()];
|
|
|
|
+ this.primitivePower = RSUtil.getPrimitivePower(getNumDataUnits(),
|
|
|
|
+ getNumParityUnits());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -129,16 +129,18 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void doDecode(byte[][] inputs, int[] inputOffsets,
|
|
|
|
- int dataLen, int[] erasedIndexes,
|
|
|
|
- byte[][] outputs, int[] outputOffsets) {
|
|
|
|
|
|
+ protected void doDecode(ByteArrayDecodingState decodingState) {
|
|
|
|
+ int dataLen = decodingState.decodeLength;
|
|
|
|
+ CoderUtil.resetOutputBuffers(decodingState.outputs,
|
|
|
|
+ decodingState.outputOffsets, dataLen);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* As passed parameters are friendly to callers but not to the underlying
|
|
* As passed parameters are friendly to callers but not to the underlying
|
|
* implementations, so we have to adjust them before calling doDecodeImpl.
|
|
* implementations, so we have to adjust them before calling doDecodeImpl.
|
|
*/
|
|
*/
|
|
|
|
|
|
int[] erasedOrNotToReadIndexes =
|
|
int[] erasedOrNotToReadIndexes =
|
|
- CoderUtil.getErasedOrNotToReadIndexes(inputs);
|
|
|
|
|
|
+ CoderUtil.getNullIndexes(decodingState.inputs);
|
|
|
|
|
|
// Prepare for adjustedOutputsParameter
|
|
// Prepare for adjustedOutputsParameter
|
|
|
|
|
|
@@ -148,16 +150,18 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
adjustedOutputOffsets[i] = 0;
|
|
adjustedOutputOffsets[i] = 0;
|
|
}
|
|
}
|
|
// Use the caller passed buffers in erasedIndexes positions
|
|
// Use the caller passed buffers in erasedIndexes positions
|
|
- for (int outputIdx = 0, i = 0; i < erasedIndexes.length; i++) {
|
|
|
|
|
|
+ for (int outputIdx = 0, i = 0;
|
|
|
|
+ i < decodingState.erasedIndexes.length; i++) {
|
|
boolean found = false;
|
|
boolean found = false;
|
|
for (int j = 0; j < erasedOrNotToReadIndexes.length; j++) {
|
|
for (int j = 0; j < erasedOrNotToReadIndexes.length; j++) {
|
|
// If this index is one requested by the caller via erasedIndexes, then
|
|
// If this index is one requested by the caller via erasedIndexes, then
|
|
// we use the passed output buffer to avoid copying data thereafter.
|
|
// we use the passed output buffer to avoid copying data thereafter.
|
|
- if (erasedIndexes[i] == erasedOrNotToReadIndexes[j]) {
|
|
|
|
|
|
+ if (decodingState.erasedIndexes[i] == erasedOrNotToReadIndexes[j]) {
|
|
found = true;
|
|
found = true;
|
|
- adjustedByteArrayOutputsParameter[j] = resetBuffer(
|
|
|
|
- outputs[outputIdx], outputOffsets[outputIdx], dataLen);
|
|
|
|
- adjustedOutputOffsets[j] = outputOffsets[outputIdx];
|
|
|
|
|
|
+ adjustedByteArrayOutputsParameter[j] = CoderUtil.resetBuffer(
|
|
|
|
+ decodingState.outputs[outputIdx],
|
|
|
|
+ decodingState.outputOffsets[outputIdx], dataLen);
|
|
|
|
+ adjustedOutputOffsets[j] = decodingState.outputOffsets[outputIdx];
|
|
outputIdx++;
|
|
outputIdx++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -169,22 +173,22 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
// Use shared buffers for other positions (not set yet)
|
|
// Use shared buffers for other positions (not set yet)
|
|
for (int bufferIdx = 0, i = 0; i < erasedOrNotToReadIndexes.length; i++) {
|
|
for (int bufferIdx = 0, i = 0; i < erasedOrNotToReadIndexes.length; i++) {
|
|
if (adjustedByteArrayOutputsParameter[i] == null) {
|
|
if (adjustedByteArrayOutputsParameter[i] == null) {
|
|
- adjustedByteArrayOutputsParameter[i] = resetBuffer(
|
|
|
|
|
|
+ adjustedByteArrayOutputsParameter[i] = CoderUtil.resetBuffer(
|
|
checkGetBytesArrayBuffer(bufferIdx, dataLen), 0, dataLen);
|
|
checkGetBytesArrayBuffer(bufferIdx, dataLen), 0, dataLen);
|
|
adjustedOutputOffsets[i] = 0; // Always 0 for such temp output
|
|
adjustedOutputOffsets[i] = 0; // Always 0 for such temp output
|
|
bufferIdx++;
|
|
bufferIdx++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- doDecodeImpl(inputs, inputOffsets, dataLen, erasedOrNotToReadIndexes,
|
|
|
|
|
|
+ doDecodeImpl(decodingState.inputs, decodingState.inputOffsets,
|
|
|
|
+ dataLen, erasedOrNotToReadIndexes,
|
|
adjustedByteArrayOutputsParameter, adjustedOutputOffsets);
|
|
adjustedByteArrayOutputsParameter, adjustedOutputOffsets);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- protected void doDecode(ByteBuffer[] inputs, int[] erasedIndexes,
|
|
|
|
- ByteBuffer[] outputs) {
|
|
|
|
- ByteBuffer validInput = CoderUtil.findFirstValidInput(inputs);
|
|
|
|
- int dataLen = validInput.remaining();
|
|
|
|
|
|
+ protected void doDecode(ByteBufferDecodingState decodingState) {
|
|
|
|
+ int dataLen = decodingState.decodeLength;
|
|
|
|
+ CoderUtil.resetOutputBuffers(decodingState.outputs, dataLen);
|
|
|
|
|
|
/**
|
|
/**
|
|
* As passed parameters are friendly to callers but not to the underlying
|
|
* As passed parameters are friendly to callers but not to the underlying
|
|
@@ -192,7 +196,7 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
*/
|
|
*/
|
|
|
|
|
|
int[] erasedOrNotToReadIndexes =
|
|
int[] erasedOrNotToReadIndexes =
|
|
- CoderUtil.getErasedOrNotToReadIndexes(inputs);
|
|
|
|
|
|
+ CoderUtil.getNullIndexes(decodingState.inputs);
|
|
|
|
|
|
// Prepare for adjustedDirectBufferOutputsParameter
|
|
// Prepare for adjustedDirectBufferOutputsParameter
|
|
|
|
|
|
@@ -201,15 +205,16 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
adjustedDirectBufferOutputsParameter[i] = null;
|
|
adjustedDirectBufferOutputsParameter[i] = null;
|
|
}
|
|
}
|
|
// Use the caller passed buffers in erasedIndexes positions
|
|
// Use the caller passed buffers in erasedIndexes positions
|
|
- for (int outputIdx = 0, i = 0; i < erasedIndexes.length; i++) {
|
|
|
|
|
|
+ for (int outputIdx = 0, i = 0;
|
|
|
|
+ i < decodingState.erasedIndexes.length; i++) {
|
|
boolean found = false;
|
|
boolean found = false;
|
|
for (int j = 0; j < erasedOrNotToReadIndexes.length; j++) {
|
|
for (int j = 0; j < erasedOrNotToReadIndexes.length; j++) {
|
|
// If this index is one requested by the caller via erasedIndexes, then
|
|
// If this index is one requested by the caller via erasedIndexes, then
|
|
// we use the passed output buffer to avoid copying data thereafter.
|
|
// we use the passed output buffer to avoid copying data thereafter.
|
|
- if (erasedIndexes[i] == erasedOrNotToReadIndexes[j]) {
|
|
|
|
|
|
+ if (decodingState.erasedIndexes[i] == erasedOrNotToReadIndexes[j]) {
|
|
found = true;
|
|
found = true;
|
|
- adjustedDirectBufferOutputsParameter[j] =
|
|
|
|
- resetBuffer(outputs[outputIdx++], dataLen);
|
|
|
|
|
|
+ adjustedDirectBufferOutputsParameter[j] = CoderUtil.resetBuffer(
|
|
|
|
+ decodingState.outputs[outputIdx++], dataLen);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!found) {
|
|
if (!found) {
|
|
@@ -223,12 +228,13 @@ public class RSRawDecoderLegacy extends AbstractRawErasureDecoder {
|
|
ByteBuffer buffer = checkGetDirectBuffer(bufferIdx, dataLen);
|
|
ByteBuffer buffer = checkGetDirectBuffer(bufferIdx, dataLen);
|
|
buffer.position(0);
|
|
buffer.position(0);
|
|
buffer.limit(dataLen);
|
|
buffer.limit(dataLen);
|
|
- adjustedDirectBufferOutputsParameter[i] = resetBuffer(buffer, dataLen);
|
|
|
|
|
|
+ adjustedDirectBufferOutputsParameter[i] =
|
|
|
|
+ CoderUtil.resetBuffer(buffer, dataLen);
|
|
bufferIdx++;
|
|
bufferIdx++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- doDecodeImpl(inputs, erasedOrNotToReadIndexes,
|
|
|
|
|
|
+ doDecodeImpl(decodingState.inputs, erasedOrNotToReadIndexes,
|
|
adjustedDirectBufferOutputsParameter);
|
|
adjustedDirectBufferOutputsParameter);
|
|
}
|
|
}
|
|
|
|
|