HADOOP-11534. Minor improvements for raw erasure coders ( Contributed by Kai Zheng )

This commit is contained in:
Vinayakumar B 2015-02-02 14:39:53 +05:30 committed by Zhe Zhang
parent e50bcea83d
commit 9f19eb9fcf
3 changed files with 23 additions and 9 deletions

View File

@ -2,3 +2,6 @@
HADOOP-11514. Raw Erasure Coder API for concrete encoding and decoding HADOOP-11514. Raw Erasure Coder API for concrete encoding and decoding
(Kai Zheng via umamahesh) (Kai Zheng via umamahesh)
HADOOP-11534. Minor improvements for raw erasure coders
( Kai Zheng via vinayakumarb )

View File

@ -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 * @param chunks
* @return an array of byte array * @return an array of byte array
*/ */
public static byte[][] toArray(ECChunk[] chunks) { public static byte[][] toArray(ECChunk[] chunks) {
byte[][] bytesArr = new byte[chunks.length][]; byte[][] bytesArr = new byte[chunks.length][];
ByteBuffer buffer;
for (int i = 0; i < chunks.length; i++) { 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; return bytesArr;

View File

@ -24,26 +24,26 @@ package org.apache.hadoop.io.erasurecode.rawcoder;
*/ */
public abstract class AbstractRawErasureCoder implements RawErasureCoder { public abstract class AbstractRawErasureCoder implements RawErasureCoder {
private int dataSize; private int numDataUnits;
private int paritySize; private int numParityUnits;
private int chunkSize; private int chunkSize;
@Override @Override
public void initialize(int numDataUnits, int numParityUnits, public void initialize(int numDataUnits, int numParityUnits,
int chunkSize) { int chunkSize) {
this.dataSize = numDataUnits; this.numDataUnits = numDataUnits;
this.paritySize = numParityUnits; this.numParityUnits = numParityUnits;
this.chunkSize = chunkSize; this.chunkSize = chunkSize;
} }
@Override @Override
public int getNumDataUnits() { public int getNumDataUnits() {
return dataSize; return numDataUnits;
} }
@Override @Override
public int getNumParityUnits() { public int getNumParityUnits() {
return paritySize; return numParityUnits;
} }
@Override @Override