HADOOP-11705. Make erasure coder configurable. Contributed by Kai Zheng
This commit is contained in:
parent
f05c21285e
commit
292e367d07
@ -18,3 +18,7 @@
|
|||||||
HADOOP-11646. Erasure Coder API for encoding and decoding of block group
|
HADOOP-11646. Erasure Coder API for encoding and decoding of block group
|
||||||
( Kai Zheng via vinayakumarb )
|
( Kai Zheng via vinayakumarb )
|
||||||
|
|
||||||
|
HADOOP-11705. Make erasure coder configurable. Contributed by Kai Zheng
|
||||||
|
( Kai Zheng )
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,12 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.io.erasurecode.coder;
|
package org.apache.hadoop.io.erasurecode.coder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configured;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A common class of basic facilities to be shared by encoder and decoder
|
* A common class of basic facilities to be shared by encoder and decoder
|
||||||
*
|
*
|
||||||
* It implements the {@link ErasureCoder} interface.
|
* It implements the {@link ErasureCoder} interface.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractErasureCoder implements ErasureCoder {
|
public abstract class AbstractErasureCoder
|
||||||
|
extends Configured implements ErasureCoder {
|
||||||
|
|
||||||
private int numDataUnits;
|
private int numDataUnits;
|
||||||
private int numParityUnits;
|
private int numParityUnits;
|
||||||
|
@ -17,12 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.io.erasurecode.rawcoder;
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configured;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A common class of basic facilities to be shared by encoder and decoder
|
* A common class of basic facilities to be shared by encoder and decoder
|
||||||
*
|
*
|
||||||
* It implements the {@link RawErasureCoder} interface.
|
* It implements the {@link RawErasureCoder} interface.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractRawErasureCoder implements RawErasureCoder {
|
public abstract class AbstractRawErasureCoder
|
||||||
|
extends Configured implements RawErasureCoder {
|
||||||
|
|
||||||
private int numDataUnits;
|
private int numDataUnits;
|
||||||
private int numParityUnits;
|
private int numParityUnits;
|
||||||
|
@ -43,6 +43,12 @@ public abstract class TestCoderBase {
|
|||||||
// may go to different coding implementations.
|
// may go to different coding implementations.
|
||||||
protected boolean usingDirectBuffer = true;
|
protected boolean usingDirectBuffer = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare before running the case.
|
||||||
|
* @param numDataUnits
|
||||||
|
* @param numParityUnits
|
||||||
|
* @param erasedIndexes
|
||||||
|
*/
|
||||||
protected void prepare(int numDataUnits, int numParityUnits,
|
protected void prepare(int numDataUnits, int numParityUnits,
|
||||||
int[] erasedIndexes) {
|
int[] erasedIndexes) {
|
||||||
this.numDataUnits = numDataUnits;
|
this.numDataUnits = numDataUnits;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.io.erasurecode.coder;
|
package org.apache.hadoop.io.erasurecode.coder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.io.erasurecode.ECBlock;
|
import org.apache.hadoop.io.erasurecode.ECBlock;
|
||||||
import org.apache.hadoop.io.erasurecode.ECChunk;
|
import org.apache.hadoop.io.erasurecode.ECChunk;
|
||||||
import org.apache.hadoop.io.erasurecode.ECBlockGroup;
|
import org.apache.hadoop.io.erasurecode.ECBlockGroup;
|
||||||
@ -29,6 +30,7 @@ public abstract class TestErasureCoderBase extends TestCoderBase {
|
|||||||
protected Class<? extends ErasureEncoder> encoderClass;
|
protected Class<? extends ErasureEncoder> encoderClass;
|
||||||
protected Class<? extends ErasureDecoder> decoderClass;
|
protected Class<? extends ErasureDecoder> decoderClass;
|
||||||
|
|
||||||
|
private Configuration conf;
|
||||||
protected int numChunksInBlock = 16;
|
protected int numChunksInBlock = 16;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +47,19 @@ public TestBlock(ECChunk[] chunks) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare before running the case.
|
||||||
|
* @param conf
|
||||||
|
* @param numDataUnits
|
||||||
|
* @param numParityUnits
|
||||||
|
* @param erasedIndexes
|
||||||
|
*/
|
||||||
|
protected void prepare(Configuration conf, int numDataUnits,
|
||||||
|
int numParityUnits, int[] erasedIndexes) {
|
||||||
|
this.conf = conf;
|
||||||
|
super.prepare(numDataUnits, numParityUnits, erasedIndexes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generating source data, encoding, recovering and then verifying.
|
* Generating source data, encoding, recovering and then verifying.
|
||||||
* RawErasureCoder mainly uses ECChunk to pass input and output data buffers,
|
* RawErasureCoder mainly uses ECChunk to pass input and output data buffers,
|
||||||
@ -56,6 +71,7 @@ protected void testCoding(boolean usingDirectBuffer) {
|
|||||||
this.usingDirectBuffer = usingDirectBuffer;
|
this.usingDirectBuffer = usingDirectBuffer;
|
||||||
|
|
||||||
ErasureEncoder encoder = createEncoder();
|
ErasureEncoder encoder = createEncoder();
|
||||||
|
|
||||||
// Generate data and encode
|
// Generate data and encode
|
||||||
ECBlockGroup blockGroup = prepareBlockGroupForEncoding();
|
ECBlockGroup blockGroup = prepareBlockGroupForEncoding();
|
||||||
// Backup all the source chunks for later recovering because some coders
|
// Backup all the source chunks for later recovering because some coders
|
||||||
@ -65,17 +81,25 @@ protected void testCoding(boolean usingDirectBuffer) {
|
|||||||
// Make a copy of a strip for later comparing
|
// Make a copy of a strip for later comparing
|
||||||
TestBlock[] toEraseBlocks = copyDataBlocksToErase(clonedDataBlocks);
|
TestBlock[] toEraseBlocks = copyDataBlocksToErase(clonedDataBlocks);
|
||||||
|
|
||||||
ErasureCodingStep codingStep = encoder.encode(blockGroup);
|
ErasureCodingStep codingStep;
|
||||||
performCodingStep(codingStep);
|
try {
|
||||||
|
codingStep = encoder.encode(blockGroup);
|
||||||
|
performCodingStep(codingStep);
|
||||||
|
} finally {
|
||||||
|
encoder.release();
|
||||||
|
}
|
||||||
// Erase the copied sources
|
// Erase the copied sources
|
||||||
eraseSomeDataBlocks(clonedDataBlocks);
|
eraseSomeDataBlocks(clonedDataBlocks);
|
||||||
|
|
||||||
//Decode
|
//Decode
|
||||||
blockGroup = new ECBlockGroup(clonedDataBlocks, blockGroup.getParityBlocks());
|
blockGroup = new ECBlockGroup(clonedDataBlocks, blockGroup.getParityBlocks());
|
||||||
ErasureDecoder decoder = createDecoder();
|
ErasureDecoder decoder = createDecoder();
|
||||||
codingStep = decoder.decode(blockGroup);
|
try {
|
||||||
performCodingStep(codingStep);
|
codingStep = decoder.decode(blockGroup);
|
||||||
|
performCodingStep(codingStep);
|
||||||
|
} finally {
|
||||||
|
decoder.release();
|
||||||
|
}
|
||||||
//Compare
|
//Compare
|
||||||
compareAndVerify(toEraseBlocks, codingStep.getOutputBlocks());
|
compareAndVerify(toEraseBlocks, codingStep.getOutputBlocks());
|
||||||
}
|
}
|
||||||
@ -138,6 +162,7 @@ private ErasureEncoder createEncoder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
encoder.initialize(numDataUnits, numParityUnits, chunkSize);
|
encoder.initialize(numDataUnits, numParityUnits, chunkSize);
|
||||||
|
encoder.setConf(conf);
|
||||||
return encoder;
|
return encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,6 +179,7 @@ private ErasureDecoder createDecoder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decoder.initialize(numDataUnits, numParityUnits, chunkSize);
|
decoder.initialize(numDataUnits, numParityUnits, chunkSize);
|
||||||
|
decoder.setConf(conf);
|
||||||
return decoder;
|
return decoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,11 @@ protected void testCoding(boolean usingDirectBuffer) {
|
|||||||
// Make a copy of a strip for later comparing
|
// Make a copy of a strip for later comparing
|
||||||
ECChunk[] toEraseDataChunks = copyDataChunksToErase(clonedDataChunks);
|
ECChunk[] toEraseDataChunks = copyDataChunksToErase(clonedDataChunks);
|
||||||
|
|
||||||
encoder.encode(dataChunks, parityChunks);
|
try {
|
||||||
|
encoder.encode(dataChunks, parityChunks);
|
||||||
|
} finally {
|
||||||
|
encoder.release();
|
||||||
|
}
|
||||||
// Erase the copied sources
|
// Erase the copied sources
|
||||||
eraseSomeDataBlocks(clonedDataChunks);
|
eraseSomeDataBlocks(clonedDataChunks);
|
||||||
|
|
||||||
@ -58,7 +62,12 @@ protected void testCoding(boolean usingDirectBuffer) {
|
|||||||
parityChunks);
|
parityChunks);
|
||||||
ECChunk[] recoveredChunks = prepareOutputChunksForDecoding();
|
ECChunk[] recoveredChunks = prepareOutputChunksForDecoding();
|
||||||
RawErasureDecoder decoder = createDecoder();
|
RawErasureDecoder decoder = createDecoder();
|
||||||
decoder.decode(inputChunks, getErasedIndexesForDecoding(), recoveredChunks);
|
try {
|
||||||
|
decoder.decode(inputChunks,
|
||||||
|
getErasedIndexesForDecoding(), recoveredChunks);
|
||||||
|
} finally {
|
||||||
|
decoder.release();
|
||||||
|
}
|
||||||
|
|
||||||
//Compare
|
//Compare
|
||||||
compareAndVerify(toEraseDataChunks, recoveredChunks);
|
compareAndVerify(toEraseDataChunks, recoveredChunks);
|
||||||
|
Loading…
Reference in New Issue
Block a user