mirror of
https://github.com/minio/minio.git
synced 2025-03-03 07:10:07 -05:00
Merge pull request #385 from abperiasamy/erasure_cache_tbls_matrix
This commit is contained in:
commit
68f36f5e08
@ -37,9 +37,6 @@ import (
|
|||||||
// blocks.
|
// blocks.
|
||||||
// "dataLen" is the length of original source data
|
// "dataLen" is the length of original source data
|
||||||
func (e *Encoder) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData []byte, err error) {
|
func (e *Encoder) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData []byte, err error) {
|
||||||
var decodeMatrix *C.uint8_t
|
|
||||||
var decodeTbls *C.uint8_t
|
|
||||||
var decodeIndex *C.uint32_t
|
|
||||||
var source, target **C.uint8_t
|
var source, target **C.uint8_t
|
||||||
|
|
||||||
k := int(e.params.K)
|
k := int(e.params.K)
|
||||||
@ -83,10 +80,20 @@ func (e *Encoder) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialzie decoder
|
// If not already initialized, recompute and cache
|
||||||
|
if e.decodeMatrix == nil || e.decodeTbls == nil || e.decodeIndex == nil {
|
||||||
|
var decodeMatrix, decodeTbls *C.uint8_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-1),
|
||||||
e.encodeMatrix, &decodeMatrix, &decodeTbls, &decodeIndex)
|
e.encodeMatrix, &decodeMatrix, &decodeTbls, &decodeIndex)
|
||||||
|
|
||||||
|
// cache this for future needs
|
||||||
|
e.decodeMatrix = decodeMatrix
|
||||||
|
e.decodeTbls = decodeTbls
|
||||||
|
e.decodeIndex = decodeIndex
|
||||||
|
}
|
||||||
|
|
||||||
// Make a slice of pointers to encoded blocks. Necessary to bridge to the C world.
|
// Make a slice of pointers to encoded blocks. Necessary to bridge to the C world.
|
||||||
pointers := make([]*byte, n)
|
pointers := make([]*byte, n)
|
||||||
for i := range encodedDataBlocks {
|
for i := range encodedDataBlocks {
|
||||||
@ -95,13 +102,13 @@ func (e *Encoder) 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-1), C.int(k), C.int(m), missingEncodedBlocksC,
|
||||||
decodeIndex, (**C.uint8_t)(unsafe.Pointer(&pointers[0])), &source, &target)
|
e.decodeIndex, (**C.uint8_t)(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), decodeTbls,
|
C.ec_encode_data(C.int(encodedBlockLen), C.int(k), C.int(missingEncodedBlocksCount-1), e.decodeTbls,
|
||||||
source, target)
|
source, target)
|
||||||
|
|
||||||
// Allocate buffer to output buffer
|
// Allocate buffer to output buffer
|
||||||
@ -110,9 +117,5 @@ func (e *Encoder) Decode(encodedDataBlocks [][]byte, dataLen int) (decodedData [
|
|||||||
decodedData = append(decodedData, encodedDataBlocks[i]...)
|
decodedData = append(decodedData, encodedDataBlocks[i]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO cache this if necessary
|
|
||||||
e.decodeMatrix = decodeMatrix
|
|
||||||
e.decodeTbls = decodeTbls
|
|
||||||
|
|
||||||
return decodedData[:dataLen], nil
|
return decodedData[:dataLen], nil
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,9 @@ type EncoderParams struct {
|
|||||||
// Encoder is an object used to encode and decode data.
|
// Encoder is an object used to encode and decode data.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
params *EncoderParams
|
params *EncoderParams
|
||||||
encodeMatrix,
|
encodeMatrix, encodeTbls *C.uint8_t
|
||||||
encodeTbls,
|
decodeMatrix, decodeTbls *C.uint8_t
|
||||||
decodeMatrix,
|
decodeIndex *C.uint32_t
|
||||||
decodeTbls *C.uint8_t
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseEncoderParams creates an EncoderParams object.
|
// ParseEncoderParams creates an EncoderParams object.
|
||||||
@ -114,6 +113,7 @@ func NewEncoder(ep *EncoderParams) *Encoder {
|
|||||||
encodeTbls: encodeTbls,
|
encodeTbls: encodeTbls,
|
||||||
decodeMatrix: nil,
|
decodeMatrix: nil,
|
||||||
decodeTbls: nil,
|
decodeTbls: nil,
|
||||||
|
decodeIndex: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user