Skip to content

Commit 37d1e9d

Browse files
committed
Revert "HADOOP-19180. EC: Fix calculation errors caused by special index order (#6813). Contributed by zhengchenyu."
This reverts commit e5b76dc.
1 parent f9f671a commit 37d1e9d

File tree

5 files changed

+62
-195
lines changed

5 files changed

+62
-195
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/erasurecode/rawcoder/RSRawDecoder.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class RSRawDecoder extends RawErasureDecoder {
5151
private byte[] gfTables;
5252
private int[] cachedErasedIndexes;
5353
private int[] validIndexes;
54+
private int numErasedDataUnits;
5455
private boolean[] erasureFlags;
5556

5657
public RSRawDecoder(ErasureCoderOptions coderOptions) {
@@ -119,10 +120,14 @@ private void processErasures(int[] erasedIndexes) {
119120
this.gfTables = new byte[getNumAllUnits() * getNumDataUnits() * 32];
120121

121122
this.erasureFlags = new boolean[getNumAllUnits()];
123+
this.numErasedDataUnits = 0;
122124

123125
for (int i = 0; i < erasedIndexes.length; i++) {
124126
int index = erasedIndexes[i];
125127
erasureFlags[index] = true;
128+
if (index < getNumDataUnits()) {
129+
numErasedDataUnits++;
130+
}
126131
}
127132

128133
generateDecodeMatrix(erasedIndexes);
@@ -151,22 +156,21 @@ private void generateDecodeMatrix(int[] erasedIndexes) {
151156

152157
GF256.gfInvertMatrix(tmpMatrix, invertMatrix, getNumDataUnits());
153158

154-
for (p = 0; p < erasedIndexes.length; p++) {
155-
int erasedIndex = erasedIndexes[p];
156-
if (erasedIndex < getNumDataUnits()) {
159+
for (i = 0; i < numErasedDataUnits; i++) {
160+
for (j = 0; j < getNumDataUnits(); j++) {
161+
decodeMatrix[getNumDataUnits() * i + j] =
162+
invertMatrix[getNumDataUnits() * erasedIndexes[i] + j];
163+
}
164+
}
165+
166+
for (p = numErasedDataUnits; p < erasedIndexes.length; p++) {
167+
for (i = 0; i < getNumDataUnits(); i++) {
168+
s = 0;
157169
for (j = 0; j < getNumDataUnits(); j++) {
158-
decodeMatrix[getNumDataUnits() * p + j] =
159-
invertMatrix[getNumDataUnits() * erasedIndexes[p] + j];
160-
}
161-
} else {
162-
for (i = 0; i < getNumDataUnits(); i++) {
163-
s = 0;
164-
for (j = 0; j < getNumDataUnits(); j++) {
165-
s ^= GF256.gfMul(invertMatrix[j * getNumDataUnits() + i],
166-
encodeMatrix[getNumDataUnits() * erasedIndexes[p] + j]);
167-
}
168-
decodeMatrix[getNumDataUnits() * p + i] = s;
170+
s ^= GF256.gfMul(invertMatrix[j * getNumDataUnits() + i],
171+
encodeMatrix[getNumDataUnits() * erasedIndexes[p] + j]);
169172
}
173+
decodeMatrix[getNumDataUnits() * p + i] = s;
170174
}
171175
}
172176
}

hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/erasurecode/erasure_coder.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ static int processErasures(IsalDecoder* pCoder, unsigned char** inputs,
132132
index = erasedIndexes[i];
133133
pCoder->erasedIndexes[i] = index;
134134
pCoder->erasureFlags[index] = 1;
135+
if (index < numDataUnits) {
136+
pCoder->numErasedDataUnits++;
137+
}
135138
}
136139

137140
pCoder->numErased = numErased;
@@ -172,6 +175,7 @@ int decode(IsalDecoder* pCoder, unsigned char** inputs,
172175

173176
// Clear variables used per decode call
174177
void clearDecoder(IsalDecoder* decoder) {
178+
decoder->numErasedDataUnits = 0;
175179
decoder->numErased = 0;
176180
memset(decoder->gftbls, 0, sizeof(decoder->gftbls));
177181
memset(decoder->decodeMatrix, 0, sizeof(decoder->decodeMatrix));
@@ -201,24 +205,24 @@ int generateDecodeMatrix(IsalDecoder* pCoder) {
201205
h_gf_invert_matrix(pCoder->tmpMatrix,
202206
pCoder->invertMatrix, numDataUnits);
203207

204-
for (p = 0; p < pCoder->numErased; p++) {
208+
for (i = 0; i < pCoder->numErasedDataUnits; i++) {
205209
for (j = 0; j < numDataUnits; j++) {
206-
int erasedIndex = pCoder->erasedIndexes[p];
207-
if (erasedIndex < numDataUnits) {
208-
pCoder->decodeMatrix[numDataUnits * p + j] =
209-
pCoder->invertMatrix[numDataUnits *
210-
pCoder->erasedIndexes[p] + j];
211-
} else {
212-
for (i = 0; i < numDataUnits; i++) {
213-
s = 0;
214-
for (j = 0; j < numDataUnits; j++) {
215-
s ^= h_gf_mul(pCoder->invertMatrix[j * numDataUnits + i],
216-
pCoder->encodeMatrix[numDataUnits *
217-
pCoder->erasedIndexes[p] + j]);
218-
}
219-
pCoder->decodeMatrix[numDataUnits * p + i] = s;
220-
}
210+
pCoder->decodeMatrix[numDataUnits * i + j] =
211+
pCoder->invertMatrix[numDataUnits *
212+
pCoder->erasedIndexes[i] + j];
213+
}
214+
}
215+
216+
for (p = pCoder->numErasedDataUnits; p < pCoder->numErased; p++) {
217+
for (i = 0; i < numDataUnits; i++) {
218+
s = 0;
219+
for (j = 0; j < numDataUnits; j++) {
220+
s ^= h_gf_mul(pCoder->invertMatrix[j * numDataUnits + i],
221+
pCoder->encodeMatrix[numDataUnits *
222+
pCoder->erasedIndexes[p] + j]);
221223
}
224+
225+
pCoder->decodeMatrix[numDataUnits * p + i] = s;
222226
}
223227
}
224228

hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/io/erasurecode/erasure_coder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct _IsalDecoder {
6262
unsigned char erasureFlags[MMAX];
6363
int erasedIndexes[MMAX];
6464
int numErased;
65+
int numErasedDataUnits;
6566
unsigned char* realInputs[MMAX];
6667
} IsalDecoder;
6768

hadoop-common-project/hadoop-common/src/main/native/src/test/org/apache/hadoop/io/erasurecode/erasure_code_test.c

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,25 @@
2727
#include "erasure_code.h"
2828
#include "gf_util.h"
2929
#include "erasure_coder.h"
30-
#include "dump.h"
3130

3231
#include <stdio.h>
3332
#include <stdlib.h>
3433
#include <string.h>
3534

3635
int main(int argc, char *argv[]) {
37-
int i, j, k, l;
36+
int i, j;
3837
char err[256];
3938
size_t err_len = sizeof(err);
4039
int chunkSize = 1024;
4140
int numDataUnits = 6;
4241
int numParityUnits = 3;
43-
int numTotalUnits = numDataUnits + numParityUnits;
4442
unsigned char** dataUnits;
4543
unsigned char** parityUnits;
4644
IsalEncoder* pEncoder;
47-
int erasedIndexes[3];
45+
int erasedIndexes[2];
4846
unsigned char* allUnits[MMAX];
4947
IsalDecoder* pDecoder;
50-
unsigned char* decodingOutput[3];
48+
unsigned char* decodingOutput[2];
5149
unsigned char** backupUnits;
5250

5351
if (0 == build_support_erasurecode()) {
@@ -84,11 +82,6 @@ int main(int argc, char *argv[]) {
8482
}
8583
}
8684

87-
// Allocate decode output
88-
for (i = 0; i < 3; i++) {
89-
decodingOutput[i] = malloc(chunkSize);
90-
}
91-
9285
pEncoder = (IsalEncoder*)malloc(sizeof(IsalEncoder));
9386
memset(pEncoder, 0, sizeof(*pEncoder));
9487
initEncoder(pEncoder, numDataUnits, numParityUnits);
@@ -102,53 +95,26 @@ int main(int argc, char *argv[]) {
10295
memcpy(allUnits + numDataUnits, parityUnits,
10396
numParityUnits * (sizeof (unsigned char*)));
10497

105-
for (i = 0; i < numTotalUnits; i++) {
106-
for (j = 0; j < numTotalUnits; j++) {
107-
for (k = 0; k < numTotalUnits; k++) {
108-
int numErased;
109-
if (i == j && j == k) {
110-
erasedIndexes[0] = i;
111-
numErased = 1;
112-
backupUnits[0] = allUnits[i];
113-
allUnits[i] = NULL;
114-
} else if (i == j) {
115-
erasedIndexes[0] = i;
116-
erasedIndexes[1] = k;
117-
numErased = 2;
118-
backupUnits[0] = allUnits[i];
119-
backupUnits[1] = allUnits[k];
120-
allUnits[i] = NULL;
121-
allUnits[k] = NULL;
122-
} else if (i == k || j == k) {
123-
erasedIndexes[0] = i;
124-
erasedIndexes[1] = j;
125-
numErased = 2;
126-
backupUnits[0] = allUnits[i];
127-
backupUnits[1] = allUnits[j];
128-
allUnits[i] = NULL;
129-
allUnits[j] = NULL;
130-
} else {
131-
erasedIndexes[0] = i;
132-
erasedIndexes[1] = j;
133-
erasedIndexes[2] = k;
134-
numErased = 3;
135-
backupUnits[0] = allUnits[i];
136-
backupUnits[1] = allUnits[j];
137-
backupUnits[2] = allUnits[k];
138-
allUnits[i] = NULL;
139-
allUnits[j] = NULL;
140-
allUnits[k] = NULL;
141-
}
142-
decode(pDecoder, allUnits, erasedIndexes, numErased, decodingOutput, chunkSize);
143-
for (l = 0; l < pDecoder->numErased; l++) {
144-
if (0 != memcmp(decodingOutput[l], backupUnits[l], chunkSize)) {
145-
printf("Decoding failed\n");
146-
dumpDecoder(pDecoder);
147-
return -1;
148-
}
149-
allUnits[erasedIndexes[l]] = backupUnits[l];
150-
}
151-
}
98+
erasedIndexes[0] = 1;
99+
erasedIndexes[1] = 7;
100+
101+
backupUnits[0] = allUnits[1];
102+
backupUnits[1] = allUnits[7];
103+
104+
allUnits[0] = NULL; // Not to read
105+
allUnits[1] = NULL;
106+
allUnits[7] = NULL;
107+
108+
decodingOutput[0] = malloc(chunkSize);
109+
decodingOutput[1] = malloc(chunkSize);
110+
111+
decode(pDecoder, allUnits, erasedIndexes, 2, decodingOutput, chunkSize);
112+
113+
for (i = 0; i < pDecoder->numErased; i++) {
114+
if (0 != memcmp(decodingOutput[i], backupUnits[i], chunkSize)) {
115+
fprintf(stderr, "Decoding failed\n\n");
116+
dumpDecoder(pDecoder);
117+
return -1;
152118
}
153119
}
154120

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/erasurecode/TestErasureCodingEncodeAndDecode.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)