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
(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
* @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;

View File

@ -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