From 9f19eb9fcf47c703c7b9ed7be573266d18baa051 Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Mon, 2 Feb 2015 14:39:53 +0530 Subject: [PATCH] HADOOP-11534. Minor improvements for raw erasure coders ( Contributed by Kai Zheng ) --- .../hadoop-common/CHANGES-HDFS-EC-7285.txt | 5 ++++- .../org/apache/hadoop/io/erasurecode/ECChunk.java | 15 +++++++++++++-- .../rawcoder/AbstractRawErasureCoder.java | 12 ++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) 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 8ce5a894ab7..2124800e6d3 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 f84eb11f2d4..01e8f3580e5 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 class ECChunk { } /** - * 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 474542b8f9a..74d2ab6fc1e 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 @@ package org.apache.hadoop.io.erasurecode.rawcoder; */ 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