diff --git a/hadoop-common-project/hadoop-common/CHANGES-HDFS-EC-7285.txt b/hadoop-common-project/hadoop-common/CHANGES-HDFS-EC-7285.txt index 8ce5a894ab..2124800e6d 100644 --- a/hadoop-common-project/hadoop-common/CHANGES-HDFS-EC-7285.txt +++ b/hadoop-common-project/hadoop-common/CHANGES-HDFS-EC-7285.txt @@ -1,4 +1,7 @@ BREAKDOWN OF HADOOP-11264 SUBTASKS AND RELATED JIRAS (Common part of HDFS-7285) HADOOP-11514. Raw Erasure Coder API for concrete encoding and decoding - (Kai Zheng via umamahesh) \ No newline at end of file + (Kai Zheng via umamahesh) + + HADOOP-11534. Minor improvements for raw erasure coders + ( Kai Zheng via vinayakumarb ) \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECChunk.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECChunk.java index f84eb11f2d..01e8f3580e 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECChunk.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/ECChunk.java @@ -66,15 +66,26 @@ public static ByteBuffer[] toBuffers(ECChunk[] chunks) { } /** - * Convert an array of this chunks to an array of byte array + * Convert an array of this chunks to an array of byte array. + * Note the chunk buffers are not affected. * @param chunks * @return an array of byte array */ public static byte[][] toArray(ECChunk[] chunks) { byte[][] bytesArr = new byte[chunks.length][]; + ByteBuffer buffer; for (int i = 0; i < chunks.length; i++) { - bytesArr[i] = chunks[i].getBuffer().array(); + buffer = chunks[i].getBuffer(); + if (buffer.hasArray()) { + bytesArr[i] = buffer.array(); + } else { + bytesArr[i] = new byte[buffer.remaining()]; + // Avoid affecting the original one + buffer.mark(); + buffer.get(bytesArr[i]); + buffer.reset(); + } } return bytesArr; diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/AbstractRawErasureCoder.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/AbstractRawErasureCoder.java index 474542b8f9..74d2ab6fc1 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/AbstractRawErasureCoder.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/AbstractRawErasureCoder.java @@ -24,26 +24,26 @@ */ public abstract class AbstractRawErasureCoder implements RawErasureCoder { - private int dataSize; - private int paritySize; + private int numDataUnits; + private int numParityUnits; private int chunkSize; @Override public void initialize(int numDataUnits, int numParityUnits, int chunkSize) { - this.dataSize = numDataUnits; - this.paritySize = numParityUnits; + this.numDataUnits = numDataUnits; + this.numParityUnits = numParityUnits; this.chunkSize = chunkSize; } @Override public int getNumDataUnits() { - return dataSize; + return numDataUnits; } @Override public int getNumParityUnits() { - return paritySize; + return numParityUnits; } @Override