forked from apache/hadoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HADOOP-19180. EC: Fix calculation errors caused by special index order (
apache#6813). Contributed by zhengchenyu. Reviewed-by: He Xiaoqiao <[email protected]> Signed-off-by: Shuyan Zhang <[email protected]>
- Loading branch information
1 parent
59dba6e
commit e5b76dc
Showing
5 changed files
with
195 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...mmon/src/test/java/org/apache/hadoop/io/erasurecode/TestErasureCodingEncodeAndDecode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* 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; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder; | ||
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder; | ||
import org.junit.Test; | ||
|
||
import java.util.Random; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
public class TestErasureCodingEncodeAndDecode { | ||
|
||
private final static int CHUNCK = 1024; | ||
private final static int DATAB_LOCKS = 6; | ||
private final static int PARITY_BLOCKS = 3; | ||
private final static int TOTAL_BLOCKS = DATAB_LOCKS + PARITY_BLOCKS; | ||
|
||
@Test | ||
public void testEncodeAndDecode() throws Exception { | ||
Configuration conf = new Configuration(); | ||
int totalBytes = CHUNCK * DATAB_LOCKS; | ||
Random random = new Random(); | ||
byte[] tmpBytes = new byte[totalBytes]; | ||
random.nextBytes(tmpBytes); | ||
byte[][] data = new byte[DATAB_LOCKS][CHUNCK]; | ||
for (int i = 0; i < DATAB_LOCKS; i++) { | ||
System.arraycopy(tmpBytes, i * CHUNCK, data[i], 0, CHUNCK); | ||
} | ||
ErasureCoderOptions coderOptions = new ErasureCoderOptions(DATAB_LOCKS, PARITY_BLOCKS); | ||
|
||
// 1 Encode | ||
RawErasureEncoder encoder = | ||
CodecUtil.createRawEncoder(conf, ErasureCodeConstants.RS_CODEC_NAME, coderOptions); | ||
byte[][] parity = new byte[PARITY_BLOCKS][CHUNCK]; | ||
encoder.encode(data, parity); | ||
|
||
// 2 Compose the complete data | ||
byte[][] all = new byte[DATAB_LOCKS + PARITY_BLOCKS][CHUNCK]; | ||
for (int i = 0; i < DATAB_LOCKS; i++) { | ||
System.arraycopy(data[i], 0, all[i], 0, CHUNCK); | ||
} | ||
for (int i = 0; i < PARITY_BLOCKS; i++) { | ||
System.arraycopy(parity[i], 0, all[i + DATAB_LOCKS], 0, CHUNCK); | ||
} | ||
|
||
// 3 Decode | ||
RawErasureDecoder rawDecoder = | ||
CodecUtil.createRawDecoder(conf, ErasureCodeConstants.RS_CODEC_NAME, coderOptions); | ||
byte[][] backup = new byte[PARITY_BLOCKS][CHUNCK]; | ||
for (int i = 0; i < TOTAL_BLOCKS; i++) { | ||
for (int j = 0; j < TOTAL_BLOCKS; j++) { | ||
for (int k = 0; k < TOTAL_BLOCKS; k++) { | ||
int[] erasedIndexes; | ||
if (i == j && j == k) { | ||
erasedIndexes = new int[]{i}; | ||
backup[0] = all[i]; | ||
all[i] = null; | ||
} else if (i == j) { | ||
erasedIndexes = new int[]{i, k}; | ||
backup[0] = all[i]; | ||
backup[1] = all[k]; | ||
all[i] = null; | ||
all[k] = null; | ||
} else if ((i == k) || ((j == k))) { | ||
erasedIndexes = new int[]{i, j}; | ||
backup[0] = all[i]; | ||
backup[1] = all[j]; | ||
all[i] = null; | ||
all[j] = null; | ||
} else { | ||
erasedIndexes = new int[]{i, j, k}; | ||
backup[0] = all[i]; | ||
backup[1] = all[j]; | ||
backup[2] = all[k]; | ||
all[i] = null; | ||
all[j] = null; | ||
all[k] = null; | ||
} | ||
byte[][] decoded = new byte[erasedIndexes.length][CHUNCK]; | ||
rawDecoder.decode(all, erasedIndexes, decoded); | ||
for (int l = 0; l < erasedIndexes.length; l++) { | ||
assertArrayEquals(backup[l], decoded[l]); | ||
all[erasedIndexes[l]] = backup[l]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |