HADOOP-14261. Some refactoring work for erasure coding raw coder. Contributed by Lin Zeng.
This commit is contained in:
parent
b0803388fc
commit
a22fe02fba
|
@ -33,7 +33,7 @@ import org.apache.hadoop.io.erasurecode.coder.ErasureEncoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawErasureCoderFactory;
|
import org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.NativeXORRawErasureCoderFactory;
|
import org.apache.hadoop.io.erasurecode.rawcoder.NativeXORRawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawErasureCoderFactory;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawErasureCoderFactoryLegacy;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSLegacyRawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureCoderFactory;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
|
||||||
|
@ -80,7 +80,7 @@ public final class CodecUtil {
|
||||||
public static final String IO_ERASURECODE_CODEC_RS_LEGACY_RAWCODERS_KEY =
|
public static final String IO_ERASURECODE_CODEC_RS_LEGACY_RAWCODERS_KEY =
|
||||||
IO_ERASURECODE_CODEC + "rs-legacy.rawcoders";
|
IO_ERASURECODE_CODEC + "rs-legacy.rawcoders";
|
||||||
public static final String IO_ERASURECODE_CODEC_RS_LEGACY_RAWCODERS_DEFAULT =
|
public static final String IO_ERASURECODE_CODEC_RS_LEGACY_RAWCODERS_DEFAULT =
|
||||||
RSRawErasureCoderFactoryLegacy.class.getCanonicalName();
|
RSLegacyRawErasureCoderFactory.class.getCanonicalName();
|
||||||
public static final String IO_ERASURECODE_CODEC_RS_RAWCODERS_KEY =
|
public static final String IO_ERASURECODE_CODEC_RS_RAWCODERS_KEY =
|
||||||
IO_ERASURECODE_CODEC + "rs.rawcoders";
|
IO_ERASURECODE_CODEC + "rs.rawcoders";
|
||||||
public static final String IO_ERASURECODE_CODEC_RS_RAWCODERS_DEFAULT =
|
public static final String IO_ERASURECODE_CODEC_RS_RAWCODERS_DEFAULT =
|
||||||
|
|
|
@ -34,12 +34,12 @@ import java.nio.ByteBuffer;
|
||||||
* addressed in HADOOP-11871.
|
* addressed in HADOOP-11871.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class RSRawDecoderLegacy extends RawErasureDecoder {
|
public class RSLegacyRawDecoder extends RawErasureDecoder {
|
||||||
// To describe and calculate the needed Vandermonde matrix
|
// To describe and calculate the needed Vandermonde matrix
|
||||||
private int[] errSignature;
|
private int[] errSignature;
|
||||||
private int[] primitivePower;
|
private int[] primitivePower;
|
||||||
|
|
||||||
public RSRawDecoderLegacy(ErasureCoderOptions coderOptions) {
|
public RSLegacyRawDecoder(ErasureCoderOptions coderOptions) {
|
||||||
super(coderOptions);
|
super(coderOptions);
|
||||||
if (getNumAllUnits() >= RSUtil.GF.getFieldSize()) {
|
if (getNumAllUnits() >= RSUtil.GF.getFieldSize()) {
|
||||||
throw new HadoopIllegalArgumentException(
|
throw new HadoopIllegalArgumentException(
|
|
@ -30,10 +30,10 @@ import java.util.Arrays;
|
||||||
* when possible.
|
* when possible.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class RSRawEncoderLegacy extends RawErasureEncoder {
|
public class RSLegacyRawEncoder extends RawErasureEncoder {
|
||||||
private int[] generatingPolynomial;
|
private int[] generatingPolynomial;
|
||||||
|
|
||||||
public RSRawEncoderLegacy(ErasureCoderOptions coderOptions) {
|
public RSLegacyRawEncoder(ErasureCoderOptions coderOptions) {
|
||||||
super(coderOptions);
|
super(coderOptions);
|
||||||
|
|
||||||
assert (getNumDataUnits() + getNumParityUnits() < RSUtil.GF.getFieldSize());
|
assert (getNumDataUnits() + getNumParityUnits() < RSUtil.GF.getFieldSize());
|
|
@ -24,15 +24,15 @@ import org.apache.hadoop.io.erasurecode.ErasureCoderOptions;
|
||||||
* A raw coder factory for the legacy raw Reed-Solomon coder in Java.
|
* A raw coder factory for the legacy raw Reed-Solomon coder in Java.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class RSRawErasureCoderFactoryLegacy implements RawErasureCoderFactory {
|
public class RSLegacyRawErasureCoderFactory implements RawErasureCoderFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RawErasureEncoder createEncoder(ErasureCoderOptions coderOptions) {
|
public RawErasureEncoder createEncoder(ErasureCoderOptions coderOptions) {
|
||||||
return new RSRawEncoderLegacy(coderOptions);
|
return new RSLegacyRawEncoder(coderOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RawErasureDecoder createDecoder(ErasureCoderOptions coderOptions) {
|
public RawErasureDecoder createDecoder(ErasureCoderOptions coderOptions) {
|
||||||
return new RSRawDecoderLegacy(coderOptions);
|
return new RSLegacyRawDecoder(coderOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -677,7 +677,7 @@
|
||||||
|
|
||||||
<property>
|
<property>
|
||||||
<name>io.erasurecode.codec.rs-legacy.rawcoders</name>
|
<name>io.erasurecode.codec.rs-legacy.rawcoders</name>
|
||||||
<value>org.apache.hadoop.io.erasurecode.rawcoder.RSRawErasureCoderFactoryLegacy</value>
|
<value>org.apache.hadoop.io.erasurecode.rawcoder.RSLegacyRawErasureCoderFactory</value>
|
||||||
<description>
|
<description>
|
||||||
Comma separated raw coder implementations for the rs-legacy codec. The earlier
|
Comma separated raw coder implementations for the rs-legacy codec. The earlier
|
||||||
factory is prior to followings in case of failure of creating raw coders.
|
factory is prior to followings in case of failure of creating raw coders.
|
||||||
|
|
|
@ -20,9 +20,9 @@ package org.apache.hadoop.io.erasurecode;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawErasureCoderFactory;
|
import org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawDecoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawDecoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawDecoderLegacy;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSLegacyRawDecoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawEncoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawEncoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawEncoderLegacy;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSLegacyRawEncoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawErasureCoderFactory;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RSRawErasureCoderFactory;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder;
|
||||||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
|
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
|
||||||
|
@ -62,10 +62,10 @@ public class TestCodecRawCoderMapping {
|
||||||
// should return default raw coder of rs-legacy codec
|
// should return default raw coder of rs-legacy codec
|
||||||
encoder = CodecUtil.createRawEncoder(conf,
|
encoder = CodecUtil.createRawEncoder(conf,
|
||||||
ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
||||||
Assert.assertTrue(encoder instanceof RSRawEncoderLegacy);
|
Assert.assertTrue(encoder instanceof RSLegacyRawEncoder);
|
||||||
decoder = CodecUtil.createRawDecoder(conf,
|
decoder = CodecUtil.createRawDecoder(conf,
|
||||||
ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
||||||
Assert.assertTrue(decoder instanceof RSRawDecoderLegacy);
|
Assert.assertTrue(decoder instanceof RSLegacyRawDecoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -122,10 +122,10 @@ public class TestCodecRawCoderMapping {
|
||||||
// should return default raw coder of rs-legacy codec
|
// should return default raw coder of rs-legacy codec
|
||||||
RawErasureEncoder encoder = CodecUtil.createRawEncoder(
|
RawErasureEncoder encoder = CodecUtil.createRawEncoder(
|
||||||
conf, ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
conf, ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
||||||
Assert.assertTrue(encoder instanceof RSRawEncoderLegacy);
|
Assert.assertTrue(encoder instanceof RSLegacyRawEncoder);
|
||||||
RawErasureDecoder decoder = CodecUtil.createRawDecoder(
|
RawErasureDecoder decoder = CodecUtil.createRawDecoder(
|
||||||
conf, ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
conf, ErasureCodeConstants.RS_LEGACY_CODEC_NAME, coderOptions);
|
||||||
Assert.assertTrue(decoder instanceof RSRawDecoderLegacy);
|
Assert.assertTrue(decoder instanceof RSLegacyRawDecoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -60,7 +60,7 @@ public final class RawErasureCoderBenchmark {
|
||||||
private static final List<RawErasureCoderFactory> CODER_MAKERS =
|
private static final List<RawErasureCoderFactory> CODER_MAKERS =
|
||||||
Collections.unmodifiableList(
|
Collections.unmodifiableList(
|
||||||
Arrays.asList(new DummyRawErasureCoderFactory(),
|
Arrays.asList(new DummyRawErasureCoderFactory(),
|
||||||
new RSRawErasureCoderFactoryLegacy(),
|
new RSLegacyRawErasureCoderFactory(),
|
||||||
new RSRawErasureCoderFactory(),
|
new RSRawErasureCoderFactory(),
|
||||||
new NativeRSRawErasureCoderFactory()));
|
new NativeRSRawErasureCoderFactory()));
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ import java.nio.ByteBuffer;
|
||||||
public class TestDummyRawCoder extends TestRawCoderBase {
|
public class TestDummyRawCoder extends TestRawCoderBase {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
encoderClass = DummyRawEncoder.class;
|
encoderFactoryClass = DummyRawErasureCoderFactory.class;
|
||||||
decoderClass = DummyRawDecoder.class;
|
decoderFactoryClass = DummyRawErasureCoderFactory.class;
|
||||||
setAllowDump(false);
|
setAllowDump(false);
|
||||||
setChunkSize(baseChunkSize);
|
setChunkSize(baseChunkSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class TestNativeRSRawCoder extends TestRSRawCoderBase {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
this.encoderClass = NativeRSRawEncoder.class;
|
this.encoderFactoryClass = NativeRSRawErasureCoderFactory.class;
|
||||||
this.decoderClass = NativeRSRawDecoder.class;
|
this.decoderFactoryClass = NativeRSRawErasureCoderFactory.class;
|
||||||
setAllowDump(true);
|
setAllowDump(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ public class TestNativeXORRawCoder extends TestXORRawCoderBase {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
this.encoderClass = NativeXORRawEncoder.class;
|
this.encoderFactoryClass = NativeXORRawErasureCoderFactory.class;
|
||||||
this.decoderClass = NativeXORRawDecoder.class;
|
this.decoderFactoryClass = NativeXORRawErasureCoderFactory.class;
|
||||||
setAllowDump(true);
|
setAllowDump(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ import org.junit.Before;
|
||||||
/**
|
/**
|
||||||
* Test the legacy raw Reed-solomon coder implemented in Java.
|
* Test the legacy raw Reed-solomon coder implemented in Java.
|
||||||
*/
|
*/
|
||||||
public class TestRSRawCoderLegacy extends TestRSRawCoderBase {
|
public class TestRSLegacyRawCoder extends TestRSRawCoderBase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.encoderClass = RSRawEncoderLegacy.class;
|
this.encoderFactoryClass = RSLegacyRawErasureCoderFactory.class;
|
||||||
this.decoderClass = RSRawDecoderLegacy.class;
|
this.decoderFactoryClass = RSLegacyRawErasureCoderFactory.class;
|
||||||
setAllowDump(false); // Change to true to allow verbose dump for debugging
|
setAllowDump(false); // Change to true to allow verbose dump for debugging
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,8 +26,8 @@ public class TestRSRawCoder extends TestRSRawCoderBase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.encoderClass = RSRawEncoder.class;
|
this.encoderFactoryClass = RSRawErasureCoderFactory.class;
|
||||||
this.decoderClass = RSRawDecoder.class;
|
this.decoderFactoryClass = RSRawErasureCoderFactory.class;
|
||||||
setAllowDump(false);
|
setAllowDump(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class TestRSRawCoderInteroperable1 extends TestRSRawCoderBase {
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
|
|
||||||
this.encoderClass = RSRawEncoder.class;
|
this.encoderFactoryClass = RSRawErasureCoderFactory.class;
|
||||||
this.decoderClass = NativeRSRawDecoder.class;
|
this.decoderFactoryClass = NativeRSRawErasureCoderFactory.class;
|
||||||
setAllowDump(true);
|
setAllowDump(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class TestRSRawCoderInteroperable2 extends TestRSRawCoderBase {
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
|
|
||||||
this.encoderClass = NativeRSRawEncoder.class;
|
this.encoderFactoryClass = NativeRSRawErasureCoderFactory.class;
|
||||||
this.decoderClass = RSRawDecoder.class;
|
this.decoderFactoryClass = RSRawErasureCoderFactory.class;
|
||||||
setAllowDump(true);
|
setAllowDump(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,12 @@ import org.apache.hadoop.io.erasurecode.TestCoderBase;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raw coder test base with utilities.
|
* Raw coder test base with utilities.
|
||||||
*/
|
*/
|
||||||
public abstract class TestRawCoderBase extends TestCoderBase {
|
public abstract class TestRawCoderBase extends TestCoderBase {
|
||||||
protected Class<? extends RawErasureEncoder> encoderClass;
|
protected Class<? extends RawErasureCoderFactory> encoderFactoryClass;
|
||||||
protected Class<? extends RawErasureDecoder> decoderClass;
|
protected Class<? extends RawErasureCoderFactory> decoderFactoryClass;
|
||||||
protected RawErasureEncoder encoder;
|
protected RawErasureEncoder encoder;
|
||||||
protected RawErasureDecoder decoder;
|
protected RawErasureDecoder decoder;
|
||||||
|
|
||||||
|
@ -234,9 +232,8 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
||||||
new ErasureCoderOptions(numDataUnits, numParityUnits,
|
new ErasureCoderOptions(numDataUnits, numParityUnits,
|
||||||
allowChangeInputs, allowDump);
|
allowChangeInputs, allowDump);
|
||||||
try {
|
try {
|
||||||
Constructor<? extends RawErasureEncoder> constructor =
|
RawErasureCoderFactory factory = encoderFactoryClass.newInstance();
|
||||||
encoderClass.getConstructor(ErasureCoderOptions.class);
|
return factory.createEncoder(coderConf);
|
||||||
return constructor.newInstance(coderConf);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to create encoder", e);
|
throw new RuntimeException("Failed to create encoder", e);
|
||||||
}
|
}
|
||||||
|
@ -251,9 +248,8 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
||||||
new ErasureCoderOptions(numDataUnits, numParityUnits,
|
new ErasureCoderOptions(numDataUnits, numParityUnits,
|
||||||
allowChangeInputs, allowDump);
|
allowChangeInputs, allowDump);
|
||||||
try {
|
try {
|
||||||
Constructor<? extends RawErasureDecoder> constructor =
|
RawErasureCoderFactory factory = encoderFactoryClass.newInstance();
|
||||||
decoderClass.getConstructor(ErasureCoderOptions.class);
|
return factory.createDecoder(coderConf);
|
||||||
return constructor.newInstance(coderConf);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to create decoder", e);
|
throw new RuntimeException("Failed to create decoder", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class TestXORRawCoder extends TestXORRawCoderBase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.encoderClass = XORRawEncoder.class;
|
this.encoderFactoryClass = XORRawErasureCoderFactory.class;
|
||||||
this.decoderClass = XORRawDecoder.class;
|
this.decoderFactoryClass = XORRawErasureCoderFactory.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public class TestXORRawCoderInteroperable1 extends TestXORRawCoderBase {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
this.encoderClass = XORRawEncoder.class;
|
this.encoderFactoryClass = XORRawErasureCoderFactory.class;
|
||||||
this.decoderClass = NativeXORRawDecoder.class;
|
this.decoderFactoryClass = NativeXORRawErasureCoderFactory.class;
|
||||||
setAllowDump(true);
|
setAllowDump(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ public class TestXORRawCoderInteroperable2 extends TestXORRawCoderBase {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
this.encoderClass = NativeXORRawEncoder.class;
|
this.encoderFactoryClass = NativeXORRawErasureCoderFactory.class;
|
||||||
this.decoderClass = XORRawDecoder.class;
|
this.decoderFactoryClass = XORRawErasureCoderFactory.class;
|
||||||
setAllowDump(true);
|
setAllowDump(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue