mirror of
https://github.com/minio/minio.git
synced 2025-02-03 01:46:00 -05:00
Use missingEncodedBlocksCount directly instead of "-1" workaround in missingEncodedBlocks[]
Makes Code more readable
This commit is contained in:
parent
55d22fa8d6
commit
1ea91d2fa2
@ -25,6 +25,9 @@ import (
|
|||||||
|
|
||||||
// intSlice2CIntArray converts Go int slice to C int array
|
// intSlice2CIntArray converts Go int slice to C int array
|
||||||
func intSlice2CIntArray(srcErrList []int) *C.int32_t {
|
func intSlice2CIntArray(srcErrList []int) *C.int32_t {
|
||||||
|
if len(srcErrList) == 0 {
|
||||||
|
return (*C.int32_t)(unsafe.Pointer(nil))
|
||||||
|
}
|
||||||
var sizeErrInt = int(unsafe.Sizeof(srcErrList[0]))
|
var sizeErrInt = int(unsafe.Sizeof(srcErrList[0]))
|
||||||
switch sizeInt {
|
switch sizeInt {
|
||||||
case sizeErrInt:
|
case sizeErrInt:
|
||||||
|
@ -22,10 +22,10 @@
|
|||||||
#include "ec_minio_common.h"
|
#include "ec_minio_common.h"
|
||||||
|
|
||||||
static
|
static
|
||||||
int32_t _minio_src_index_in_error (int r, int32_t *error_index)
|
int32_t _minio_src_index_in_error (int r, int32_t *error_index, int errs)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; error_index[i] != -1; i++) {
|
for (i = 0; i < errs; i++) {
|
||||||
if (error_index[i] == r) {
|
if (error_index[i] == r) {
|
||||||
// true
|
// true
|
||||||
return 1;
|
return 1;
|
||||||
@ -88,7 +88,7 @@ int minio_init_decoder (int32_t *error_index,
|
|||||||
uint32_t tmp_decode_index[k];
|
uint32_t tmp_decode_index[k];
|
||||||
|
|
||||||
for (i = 0, r = 0; i < k; i++, r++) {
|
for (i = 0, r = 0; i < k; i++, r++) {
|
||||||
while (_minio_src_index_in_error(r, error_index))
|
while (_minio_src_index_in_error(r, error_index, errs))
|
||||||
r++;
|
r++;
|
||||||
for (j = 0; j < k; j++) {
|
for (j = 0; j < k; j++) {
|
||||||
input_matrix[k * i + j] = encode_matrix[k * r + j];
|
input_matrix[k * i + j] = encode_matrix[k * r + j];
|
||||||
|
@ -63,11 +63,9 @@ func (e *Erasure) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData [
|
|||||||
missingEncodedBlocksCount++
|
missingEncodedBlocksCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
missingEncodedBlocks[missingEncodedBlocksCount] = -1
|
|
||||||
missingEncodedBlocksCount++
|
|
||||||
|
|
||||||
// Cannot reconstruct original data. Need at least M number of data or parity blocks.
|
// Cannot reconstruct original data. Need at least M number of data or parity blocks.
|
||||||
if missingEncodedBlocksCount-1 > m {
|
if missingEncodedBlocksCount > m {
|
||||||
return nil, fmt.Errorf("Cannot reconstruct original data. Need at least [%d] data or parity blocks", m)
|
return nil, fmt.Errorf("Cannot reconstruct original data. Need at least [%d] data or parity blocks", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +84,7 @@ func (e *Erasure) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData [
|
|||||||
var decodeMatrix, decodeTbls *C.uchar
|
var decodeMatrix, decodeTbls *C.uchar
|
||||||
var decodeIndex *C.uint32_t
|
var decodeIndex *C.uint32_t
|
||||||
|
|
||||||
C.minio_init_decoder(missingEncodedBlocksC, C.int(k), C.int(n), C.int(missingEncodedBlocksCount-1),
|
C.minio_init_decoder(missingEncodedBlocksC, C.int(k), C.int(n), C.int(missingEncodedBlocksCount),
|
||||||
e.encodeMatrix, &decodeMatrix, &decodeTbls, &decodeIndex)
|
e.encodeMatrix, &decodeMatrix, &decodeTbls, &decodeIndex)
|
||||||
|
|
||||||
// cache this for future needs
|
// cache this for future needs
|
||||||
@ -102,14 +100,14 @@ func (e *Erasure) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData [
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get pointers to source "data" and target "parity" blocks from the output byte array.
|
// Get pointers to source "data" and target "parity" blocks from the output byte array.
|
||||||
ret := C.minio_get_source_target(C.int(missingEncodedBlocksCount-1), C.int(k), C.int(m), missingEncodedBlocksC,
|
ret := C.minio_get_source_target(C.int(missingEncodedBlocksCount), C.int(k), C.int(m), missingEncodedBlocksC,
|
||||||
e.decodeIndex, (**C.uchar)(unsafe.Pointer(&pointers[0])), &source, &target)
|
e.decodeIndex, (**C.uchar)(unsafe.Pointer(&pointers[0])), &source, &target)
|
||||||
if int(ret) == -1 {
|
if int(ret) == -1 {
|
||||||
return nil, errors.New("Unable to decode data")
|
return nil, errors.New("Unable to decode data")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode data
|
// Decode data
|
||||||
C.ec_encode_data(C.int(encodedBlockLen), C.int(k), C.int(missingEncodedBlocksCount-1), e.decodeTbls,
|
C.ec_encode_data(C.int(encodedBlockLen), C.int(k), C.int(missingEncodedBlocksCount), e.decodeTbls,
|
||||||
source, target)
|
source, target)
|
||||||
|
|
||||||
// Allocate buffer to output buffer
|
// Allocate buffer to output buffer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user