HADOOP-11798. Native raw erasure coder in XOR codes. Contributed by SammiChen.
This commit is contained in:
parent
084bdab156
commit
d88dca844a
|
@ -640,6 +640,8 @@
|
||||||
<javahClassName>org.apache.hadoop.io.erasurecode.ErasureCodeNative</javahClassName>
|
<javahClassName>org.apache.hadoop.io.erasurecode.ErasureCodeNative</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawEncoder</javahClassName>
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawEncoder</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawDecoder</javahClassName>
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawDecoder</javahClassName>
|
||||||
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeXORRawEncoder</javahClassName>
|
||||||
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeXORRawDecoder</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.crypto.OpensslCipher</javahClassName>
|
<javahClassName>org.apache.hadoop.crypto.OpensslCipher</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.crypto.random.OpensslSecureRandom</javahClassName>
|
<javahClassName>org.apache.hadoop.crypto.random.OpensslSecureRandom</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.util.NativeCrc32</javahClassName>
|
<javahClassName>org.apache.hadoop.util.NativeCrc32</javahClassName>
|
||||||
|
@ -780,6 +782,8 @@
|
||||||
<javahClassName>org.apache.hadoop.io.erasurecode.ErasureCodeNative</javahClassName>
|
<javahClassName>org.apache.hadoop.io.erasurecode.ErasureCodeNative</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawEncoder</javahClassName>
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawEncoder</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawDecoder</javahClassName>
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeRSRawDecoder</javahClassName>
|
||||||
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeXORRawEncoder</javahClassName>
|
||||||
|
<javahClassName>org.apache.hadoop.io.erasurecode.rawcoder.NativeXORRawDecoder</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.crypto.OpensslCipher</javahClassName>
|
<javahClassName>org.apache.hadoop.crypto.OpensslCipher</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.crypto.random.OpensslSecureRandom</javahClassName>
|
<javahClassName>org.apache.hadoop.crypto.random.OpensslSecureRandom</javahClassName>
|
||||||
<javahClassName>org.apache.hadoop.util.NativeCrc32</javahClassName>
|
<javahClassName>org.apache.hadoop.util.NativeCrc32</javahClassName>
|
||||||
|
|
|
@ -113,7 +113,9 @@ if (ISAL_LIBRARY)
|
||||||
${SRC}/io/erasurecode/jni_erasure_code_native.c
|
${SRC}/io/erasurecode/jni_erasure_code_native.c
|
||||||
${SRC}/io/erasurecode/jni_common.c
|
${SRC}/io/erasurecode/jni_common.c
|
||||||
${SRC}/io/erasurecode/jni_rs_encoder.c
|
${SRC}/io/erasurecode/jni_rs_encoder.c
|
||||||
${SRC}/io/erasurecode/jni_rs_decoder.c)
|
${SRC}/io/erasurecode/jni_rs_decoder.c
|
||||||
|
${SRC}/io/erasurecode/jni_xor_encoder.c
|
||||||
|
${SRC}/io/erasurecode/jni_xor_decoder.c)
|
||||||
|
|
||||||
add_executable(erasure_code_test
|
add_executable(erasure_code_test
|
||||||
${SRC}/io/erasurecode/isal_load.c
|
${SRC}/io/erasurecode/isal_load.c
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCoderOptions;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A XOR raw decoder using Intel ISA-L library.
|
||||||
|
*/
|
||||||
|
@InterfaceAudience.Private
|
||||||
|
public class NativeXORRawDecoder extends AbstractNativeRawDecoder {
|
||||||
|
|
||||||
|
static {
|
||||||
|
ErasureCodeNative.checkNativeCodeLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NativeXORRawDecoder(ErasureCoderOptions coderOptions) {
|
||||||
|
super(coderOptions);
|
||||||
|
initImpl(coderOptions.getNumDataUnits(), coderOptions.getNumParityUnits());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void performDecodeImpl(ByteBuffer[] inputs, int[] inputOffsets,
|
||||||
|
int dataLen, int[] erased, ByteBuffer[] outputs, int[] outputOffsets) {
|
||||||
|
decodeImpl(inputs, inputOffsets, dataLen, erased, outputs, outputOffsets);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release() {
|
||||||
|
destroyImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private native void initImpl(int numDataUnits, int numParityUnits);
|
||||||
|
|
||||||
|
private native void decodeImpl(
|
||||||
|
ByteBuffer[] inputs, int[] inputOffsets, int dataLen, int[] erased,
|
||||||
|
ByteBuffer[] outputs, int[] outputOffsets);
|
||||||
|
|
||||||
|
private native void destroyImpl();
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCoderOptions;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A XOR raw encoder using Intel ISA-L library.
|
||||||
|
*/
|
||||||
|
@InterfaceAudience.Private
|
||||||
|
public class NativeXORRawEncoder extends AbstractNativeRawEncoder {
|
||||||
|
|
||||||
|
static {
|
||||||
|
ErasureCodeNative.checkNativeCodeLoaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NativeXORRawEncoder(ErasureCoderOptions coderOptions) {
|
||||||
|
super(coderOptions);
|
||||||
|
initImpl(coderOptions.getNumDataUnits(), coderOptions.getNumParityUnits());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void performEncodeImpl(
|
||||||
|
ByteBuffer[] inputs, int[] inputOffsets, int dataLen,
|
||||||
|
ByteBuffer[] outputs, int[] outputOffsets) {
|
||||||
|
encodeImpl(inputs, inputOffsets, dataLen, outputs, outputOffsets);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void release() {
|
||||||
|
destroyImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private native void initImpl(int numDataUnits, int numParityUnits);
|
||||||
|
|
||||||
|
private native void encodeImpl(ByteBuffer[] inputs, int[] inputOffsets,
|
||||||
|
int dataLen, ByteBuffer[] outputs,
|
||||||
|
int[] outputOffsets);
|
||||||
|
|
||||||
|
private native void destroyImpl();
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCoderOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A raw coder factory for xor coder in native using Intel ISA-L library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@InterfaceAudience.Private
|
||||||
|
public class NativeXORRawErasureCoderFactory implements RawErasureCoderFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RawErasureEncoder createEncoder(ErasureCoderOptions coderOptions) {
|
||||||
|
return new NativeXORRawEncoder(coderOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RawErasureDecoder createDecoder(ErasureCoderOptions coderOptions) {
|
||||||
|
return new NativeXORRawDecoder(coderOptions);
|
||||||
|
}
|
||||||
|
}
|
|
@ -156,14 +156,14 @@
|
||||||
<ClCompile Include="src\org\apache\hadoop\util\bulk_crc32.c" />
|
<ClCompile Include="src\org\apache\hadoop\util\bulk_crc32.c" />
|
||||||
<ClCompile Include="src\org\apache\hadoop\util\NativeCodeLoader.c">
|
<ClCompile Include="src\org\apache\hadoop\util\NativeCodeLoader.c">
|
||||||
<AdditionalOptions Condition="'$(SnappyEnabled)' == 'true'">/D HADOOP_SNAPPY_LIBRARY=L\"snappy.dll\"</AdditionalOptions>
|
<AdditionalOptions Condition="'$(SnappyEnabled)' == 'true'">/D HADOOP_SNAPPY_LIBRARY=L\"snappy.dll\"</AdditionalOptions>
|
||||||
<AdditionalOptions Condition="'$(IsalEnabled)' == 'true'">/D HADOOP_ISAL_LIBRARY=\"isa-l.dll\"</AdditionalOptions>
|
<AdditionalOptions Condition="'$(IsalEnabled)' == 'true'">/D HADOOP_ISAL_LIBRARY=L\"isa-l.dll\"</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\org\apache\hadoop\util\NativeCrc32.c" />
|
<ClCompile Include="src\org\apache\hadoop\util\NativeCrc32.c" />
|
||||||
<ClCompile Include="src\org\apache\hadoop\yarn\server\nodemanager\windows_secure_container_executor.c">
|
<ClCompile Include="src\org\apache\hadoop\yarn\server\nodemanager\windows_secure_container_executor.c">
|
||||||
<AdditionalIncludeDirectories>src\org\apache\hadoop\io\nativeio;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>src\org\apache\hadoop\io\nativeio;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\isal_load.c" Condition="'$(IsalEnabled)' == 'true'">
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\isal_load.c" Condition="'$(IsalEnabled)' == 'true'">
|
||||||
<AdditionalOptions>/D HADOOP_ISAL_LIBRARY=\"isa-l.dll\"</AdditionalOptions>
|
<AdditionalOptions>/D HADOOP_ISAL_LIBRARY=L\"isa-l.dll\"</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\erasure_code.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\erasure_code.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\gf_util.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\gf_util.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
|
@ -173,6 +173,8 @@
|
||||||
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_common.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_common.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_rs_encoder.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_rs_encoder.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_rs_decoder.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_rs_decoder.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_xor_encoder.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
|
<ClCompile Include="src\org\apache\hadoop\io\erasurecode\jni_xor_decoder.c" Condition="'$(IsalEnabled)' == 'true'"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\src\org\apache\hadoop\util\crc32c_tables.h" />
|
<ClInclude Include="..\src\org\apache\hadoop\util\crc32c_tables.h" />
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include "org_apache_hadoop.h"
|
||||||
|
#include "erasure_code.h"
|
||||||
|
#include "gf_util.h"
|
||||||
|
#include "jni_common.h"
|
||||||
|
#include "org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawDecoder.h"
|
||||||
|
|
||||||
|
typedef struct _XOREncoder {
|
||||||
|
IsalCoder isalCoder;
|
||||||
|
unsigned char* inputs[MMAX];
|
||||||
|
unsigned char* outputs[1];
|
||||||
|
} XORDecoder;
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawDecoder_initImpl(
|
||||||
|
JNIEnv *env, jobject thiz, jint numDataUnits, jint numParityUnits) {
|
||||||
|
XORDecoder* xorDecoder =
|
||||||
|
(XORDecoder*)malloc(sizeof(XORDecoder));
|
||||||
|
memset(xorDecoder, 0, sizeof(*xorDecoder));
|
||||||
|
initCoder(&xorDecoder->isalCoder, numDataUnits, numParityUnits);
|
||||||
|
|
||||||
|
setCoder(env, thiz, &xorDecoder->isalCoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawDecoder_decodeImpl(
|
||||||
|
JNIEnv *env, jobject thiz, jobjectArray inputs, jintArray inputOffsets,
|
||||||
|
jint dataLen, jintArray erasedIndexes, jobjectArray outputs,
|
||||||
|
jintArray outputOffsets) {
|
||||||
|
int i, j, numDataUnits, numParityUnits, chunkSize;
|
||||||
|
XORDecoder* xorDecoder;
|
||||||
|
|
||||||
|
xorDecoder = (XORDecoder*)getCoder(env, thiz);
|
||||||
|
numDataUnits = ((IsalCoder*)xorDecoder)->numDataUnits;
|
||||||
|
numParityUnits = ((IsalCoder*)xorDecoder)->numParityUnits;
|
||||||
|
chunkSize = (int)dataLen;
|
||||||
|
|
||||||
|
getInputs(env, inputs, inputOffsets, xorDecoder->inputs,
|
||||||
|
numDataUnits + numParityUnits);
|
||||||
|
getOutputs(env, outputs, outputOffsets, xorDecoder->outputs, numParityUnits);
|
||||||
|
|
||||||
|
for (i = 0; i < numDataUnits + numParityUnits; i++) {
|
||||||
|
if (xorDecoder->inputs[i] == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (j = 0; j < chunkSize; j++) {
|
||||||
|
xorDecoder->outputs[0][j] ^= xorDecoder->inputs[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawDecoder_destroyImpl
|
||||||
|
(JNIEnv *env, jobject thiz){
|
||||||
|
XORDecoder* xorDecoder = (XORDecoder*)getCoder(env, thiz);
|
||||||
|
free(xorDecoder);
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include "org_apache_hadoop.h"
|
||||||
|
#include "erasure_code.h"
|
||||||
|
#include "gf_util.h"
|
||||||
|
#include "jni_common.h"
|
||||||
|
#include "org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawEncoder.h"
|
||||||
|
|
||||||
|
typedef struct _XOREncoder {
|
||||||
|
IsalCoder isalCoder;
|
||||||
|
unsigned char* inputs[MMAX];
|
||||||
|
unsigned char* outputs[1];
|
||||||
|
} XOREncoder;
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawEncoder_initImpl
|
||||||
|
(JNIEnv *env, jobject thiz, jint numDataUnits, jint numParityUnits) {
|
||||||
|
XOREncoder* xorEncoder =
|
||||||
|
(XOREncoder*)malloc(sizeof(XOREncoder));
|
||||||
|
memset(xorEncoder, 0, sizeof(*xorEncoder));
|
||||||
|
initCoder(&xorEncoder->isalCoder, numDataUnits, numParityUnits);
|
||||||
|
|
||||||
|
setCoder(env, thiz, &xorEncoder->isalCoder);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawEncoder_encodeImpl(
|
||||||
|
JNIEnv *env, jobject thiz, jobjectArray inputs, jintArray inputOffsets,
|
||||||
|
jint dataLen, jobjectArray outputs, jintArray outputOffsets) {
|
||||||
|
|
||||||
|
int i, j, numDataUnits, numParityUnits, chunkSize;
|
||||||
|
XOREncoder* xorEncoder;
|
||||||
|
|
||||||
|
xorEncoder = (XOREncoder*)getCoder(env, thiz);
|
||||||
|
numDataUnits = ((IsalCoder*)xorEncoder)->numDataUnits;
|
||||||
|
numParityUnits = ((IsalCoder*)xorEncoder)->numParityUnits;
|
||||||
|
chunkSize = (int)dataLen;
|
||||||
|
|
||||||
|
getInputs(env, inputs, inputOffsets, xorEncoder->inputs, numDataUnits);
|
||||||
|
getOutputs(env, outputs, outputOffsets, xorEncoder->outputs, numParityUnits);
|
||||||
|
|
||||||
|
// Get the first buffer's data.
|
||||||
|
for (j = 0; j < chunkSize; j++) {
|
||||||
|
xorEncoder->outputs[0][j] = xorEncoder->inputs[0][j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// XOR with everything else.
|
||||||
|
for (i = 1; i < numDataUnits; i++) {
|
||||||
|
for (j = 0; j < chunkSize; j++) {
|
||||||
|
xorEncoder->outputs[0][j] ^= xorEncoder->inputs[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_apache_hadoop_io_erasurecode_rawcoder_NativeXORRawEncoder_destroyImpl
|
||||||
|
(JNIEnv *env, jobject thiz) {
|
||||||
|
XOREncoder* xorEncoder = (XOREncoder*)getCoder(env, thiz);
|
||||||
|
free(xorEncoder);
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test NativeXOR encoding and decoding.
|
||||||
|
*/
|
||||||
|
public class TestNativeXORRawCoder extends TestXORRawCoderBase {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
|
this.encoderClass = NativeXORRawEncoder.class;
|
||||||
|
this.decoderClass = NativeXORRawDecoder.class;
|
||||||
|
setAllowDump(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,49 +18,15 @@
|
||||||
package org.apache.hadoop.io.erasurecode.rawcoder;
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test XOR encoding and decoding.
|
* Test pure Java XOR encoding and decoding.
|
||||||
*/
|
*/
|
||||||
public class TestXORRawCoder extends TestRawCoderBase {
|
public class TestXORRawCoder extends TestXORRawCoderBase {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.encoderClass = XORRawEncoder.class;
|
this.encoderClass = XORRawEncoder.class;
|
||||||
this.decoderClass = XORRawDecoder.class;
|
this.decoderClass = XORRawDecoder.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCoding_10x1_erasing_d0() {
|
|
||||||
prepare(null, 10, 1, new int[] {0}, new int[0]);
|
|
||||||
testCodingDoMixAndTwice();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCoding_10x1_erasing_p0() {
|
|
||||||
prepare(null, 10, 1, new int[0], new int[] {0});
|
|
||||||
testCodingDoMixAndTwice();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCoding_10x1_erasing_d5() {
|
|
||||||
prepare(null, 10, 1, new int[]{5}, new int[0]);
|
|
||||||
testCodingDoMixAndTwice();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCodingNegative_10x1_erasing_too_many() {
|
|
||||||
prepare(null, 10, 1, new int[]{2}, new int[]{0});
|
|
||||||
testCodingWithErasingTooMany();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCodingNegative_10x1_erasing_d5() {
|
|
||||||
prepare(null, 10, 1, new int[]{5}, new int[0]);
|
|
||||||
testCodingWithBadInput(true);
|
|
||||||
testCodingWithBadOutput(false);
|
|
||||||
testCodingWithBadInput(true);
|
|
||||||
testCodingWithBadOutput(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test base for raw XOR coders.
|
||||||
|
*/
|
||||||
|
public abstract class TestXORRawCoderBase extends TestRawCoderBase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCoding_10x1_erasing_d0() {
|
||||||
|
prepare(null, 10, 1, new int[] {0}, new int[0]);
|
||||||
|
testCodingDoMixAndTwice();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCoding_10x1_erasing_p0() {
|
||||||
|
prepare(null, 10, 1, new int[0], new int[] {0});
|
||||||
|
testCodingDoMixAndTwice();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCoding_10x1_erasing_d5() {
|
||||||
|
prepare(null, 10, 1, new int[]{5}, new int[0]);
|
||||||
|
testCodingDoMixAndTwice();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCodingNegative_10x1_erasing_too_many() {
|
||||||
|
prepare(null, 10, 1, new int[]{2}, new int[]{0});
|
||||||
|
testCodingWithErasingTooMany();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCodingNegative_10x1_erasing_d5() {
|
||||||
|
prepare(null, 10, 1, new int[]{5}, new int[0]);
|
||||||
|
testCodingWithBadInput(true);
|
||||||
|
testCodingWithBadOutput(false);
|
||||||
|
testCodingWithBadInput(true);
|
||||||
|
testCodingWithBadOutput(false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test raw XOR coder implemented in Java.
|
||||||
|
*/
|
||||||
|
public class TestXORRawCoderInteroperable1 extends TestXORRawCoderBase {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
|
this.encoderClass = XORRawEncoder.class;
|
||||||
|
this.decoderClass = NativeXORRawDecoder.class;
|
||||||
|
setAllowDump(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.hadoop.io.erasurecode.rawcoder;
|
||||||
|
|
||||||
|
import org.apache.hadoop.io.erasurecode.ErasureCodeNative;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test raw XOR coder implemented in Java.
|
||||||
|
*/
|
||||||
|
public class TestXORRawCoderInteroperable2 extends TestXORRawCoderBase {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
Assume.assumeTrue(ErasureCodeNative.isNativeCodeLoaded());
|
||||||
|
this.encoderClass = NativeXORRawEncoder.class;
|
||||||
|
this.decoderClass = XORRawDecoder.class;
|
||||||
|
setAllowDump(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue