HADOOP-11534. Minor improvements for raw erasure coders ( Contributed by Kai Zheng )
This commit is contained in:
parent
e50bcea83d
commit
9f19eb9fcf
@ -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 )
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user