Co-incide with upstream changes and other misc changes
This commit is contained in:
@@ -29,14 +29,18 @@ var _ = Suite(&MySuite{})
|
||||
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
const (
|
||||
k = 10
|
||||
m = 5
|
||||
)
|
||||
|
||||
func (s *MySuite) TestCauchyDecode(c *C) {
|
||||
ep, _ := ParseEncoderParams(10, 5, Cauchy)
|
||||
ep, _ := ParseEncoderParams(k, m, Cauchy)
|
||||
|
||||
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
|
||||
|
||||
e := NewEncoder(ep)
|
||||
chunks, length := e.Encode(data)
|
||||
c.Assert(length, Equals, len(data))
|
||||
chunks, _ := e.Encode(data)
|
||||
|
||||
chunks[0] = nil
|
||||
chunks[3] = nil
|
||||
@@ -44,7 +48,7 @@ func (s *MySuite) TestCauchyDecode(c *C) {
|
||||
chunks[9] = nil
|
||||
chunks[13] = nil
|
||||
|
||||
recoveredData, err := e.Decode(chunks, length)
|
||||
recoveredData, err := e.Decode(chunks, len(data))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
if !bytes.Equal(data, recoveredData) {
|
||||
|
||||
@@ -37,12 +37,13 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
||||
var decode_index *C.uint32_t
|
||||
var source, target **C.uint8_t
|
||||
|
||||
k := int(e.k)
|
||||
n := int(e.k + e.m)
|
||||
if len(chunks) != n {
|
||||
k := e.params.K
|
||||
m := e.params.M
|
||||
n := k + m
|
||||
if len(chunks) != int(n) {
|
||||
return nil, errors.New(fmt.Sprintf("chunks length must be %d", n))
|
||||
}
|
||||
chunk_size := getChunkSize(k, length)
|
||||
chunk_size := GetEncodedChunkLen(length, uint8(k))
|
||||
|
||||
error_index := make([]int, n+1)
|
||||
var err_count int = 0
|
||||
@@ -58,7 +59,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
||||
err_count++
|
||||
|
||||
// Too many missing chunks, cannot be more than parity `m`
|
||||
if err_count-1 > (n - k) {
|
||||
if err_count-1 > int(n-k) {
|
||||
return nil, errors.New("too many erasures requested, can't decode")
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
C.minio_init_decoder(error_index_ptr, e.k, e.k+e.m, C.int(err_count-1),
|
||||
C.minio_init_decoder(error_index_ptr, C.int(k), C.int(n), C.int(err_count-1),
|
||||
e.encode_matrix, &decode_matrix, &decode_tbls, &decode_index)
|
||||
|
||||
pointers := make([]*byte, n)
|
||||
@@ -80,18 +81,18 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
||||
|
||||
data := (**C.uint8_t)(unsafe.Pointer(&pointers[0]))
|
||||
|
||||
ret := C.minio_get_source_target(C.int(err_count-1), e.k, e.m, error_index_ptr,
|
||||
ret := C.minio_get_source_target(C.int(err_count-1), C.int(k), C.int(m), error_index_ptr,
|
||||
decode_index, data, &source, &target)
|
||||
|
||||
if int(ret) == -1 {
|
||||
return nil, errors.New("Decoding source target failed")
|
||||
}
|
||||
|
||||
C.ec_encode_data(C.int(chunk_size), e.k, C.int(err_count-1), decode_tbls,
|
||||
C.ec_encode_data(C.int(chunk_size), C.int(k), C.int(err_count-1), decode_tbls,
|
||||
source, target)
|
||||
|
||||
recovered_output := make([]byte, 0, chunk_size*k)
|
||||
for i := 0; i < k; i++ {
|
||||
recovered_output := make([]byte, 0, chunk_size*int(k))
|
||||
for i := 0; i < int(k); i++ {
|
||||
recovered_output = append(recovered_output, chunks[i]...)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
SimdAlign = 32
|
||||
SIMDAlign = 32
|
||||
)
|
||||
|
||||
// EncoderParams is a configuration set for building an encoder. It is created using ValidateParams.
|
||||
@@ -51,9 +51,7 @@ type EncoderParams struct {
|
||||
|
||||
// Encoder is an object used to encode and decode data.
|
||||
type Encoder struct {
|
||||
p *EncoderParams
|
||||
k,
|
||||
m C.int
|
||||
params *EncoderParams
|
||||
encode_matrix,
|
||||
encode_tbls,
|
||||
decode_matrix,
|
||||
@@ -96,19 +94,17 @@ func ParseEncoderParams(k, m uint8, technique Technique) (*EncoderParams, error)
|
||||
|
||||
// NewEncoder creates an encoder object with a given set of parameters.
|
||||
func NewEncoder(ep *EncoderParams) *Encoder {
|
||||
var k = C.int(ep.K)
|
||||
var m = C.int(ep.M)
|
||||
|
||||
var encode_matrix *C.uint8_t
|
||||
var encode_tbls *C.uint8_t
|
||||
|
||||
k := C.int(ep.K)
|
||||
m := C.int(ep.M)
|
||||
|
||||
C.minio_init_encoder(C.int(ep.Technique), k, m, &encode_matrix,
|
||||
&encode_tbls)
|
||||
|
||||
return &Encoder{
|
||||
p: ep,
|
||||
k: k,
|
||||
m: m,
|
||||
params: ep,
|
||||
encode_matrix: encode_matrix,
|
||||
encode_tbls: encode_tbls,
|
||||
decode_matrix: nil,
|
||||
@@ -116,59 +112,68 @@ func NewEncoder(ep *EncoderParams) *Encoder {
|
||||
}
|
||||
}
|
||||
|
||||
func getChunkSize(k, split_len int) int {
|
||||
var alignment, remainder, padded_len int
|
||||
func GetEncodedLen(inputLen int, k, m uint8) (outputLen int) {
|
||||
outputLen = GetEncodedChunkLen(inputLen, k) * int(k+m)
|
||||
return outputLen
|
||||
}
|
||||
|
||||
alignment = k * SimdAlign
|
||||
remainder = split_len % alignment
|
||||
func GetEncodedChunkLen(inputLen int, k uint8) (outputChunkLen int) {
|
||||
alignment := int(k) * SIMDAlign
|
||||
remainder := inputLen % alignment
|
||||
|
||||
padded_len = split_len
|
||||
paddedInputLen := inputLen
|
||||
if remainder != 0 {
|
||||
padded_len = split_len + (alignment - remainder)
|
||||
paddedInputLen = inputLen + (alignment - remainder)
|
||||
}
|
||||
return padded_len / k
|
||||
outputChunkLen = paddedInputLen / int(k)
|
||||
return outputChunkLen
|
||||
}
|
||||
|
||||
// Encode encodes a block of data. The input is the original data. The output
|
||||
// is a 2 tuple containing (k + m) chunks of erasure encoded data and the
|
||||
// length of the original object.
|
||||
func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||
var block_len = len(block)
|
||||
func (e *Encoder) Encode(input []byte) ([][]byte, error) {
|
||||
inputLen := len(input)
|
||||
k := C.int(e.params.K)
|
||||
m := C.int(e.params.M)
|
||||
n := k + m
|
||||
|
||||
chunk_size := getChunkSize(int(e.k), block_len)
|
||||
chunk_len := chunk_size * int(e.k)
|
||||
pad_len := int(chunk_len) - block_len
|
||||
chunkLen := GetEncodedChunkLen(inputLen, e.params.K)
|
||||
encodedDataLen := chunkLen * int(k)
|
||||
paddedDataLen := int(encodedDataLen) - inputLen
|
||||
|
||||
if pad_len > 0 {
|
||||
s := make([]byte, pad_len)
|
||||
if paddedDataLen > 0 {
|
||||
s := make([]byte, paddedDataLen)
|
||||
// Expand with new padded blocks to the byte array
|
||||
block = append(block, s...)
|
||||
input = append(input, s...)
|
||||
}
|
||||
|
||||
coded_len := chunk_size * int(e.p.M)
|
||||
c := make([]byte, coded_len)
|
||||
block = append(block, c...)
|
||||
encodedParityLen := chunkLen * int(e.params.M)
|
||||
c := make([]byte, encodedParityLen)
|
||||
input = append(input, c...)
|
||||
|
||||
// encodedOutLen := encodedDataLen + encodedParityLen
|
||||
|
||||
// Allocate chunks
|
||||
chunks := make([][]byte, e.p.K+e.p.M)
|
||||
pointers := make([]*byte, e.p.K+e.p.M)
|
||||
chunks := make([][]byte, k+m)
|
||||
pointers := make([]*byte, k+m)
|
||||
|
||||
var i int
|
||||
// Add data blocks to chunks
|
||||
for i = 0; i < int(e.p.K); i++ {
|
||||
chunks[i] = block[i*chunk_size : (i+1)*chunk_size]
|
||||
for i = 0; i < int(k); i++ {
|
||||
chunks[i] = input[i*chunkLen : (i+1)*chunkLen]
|
||||
pointers[i] = &chunks[i][0]
|
||||
}
|
||||
|
||||
for i = int(e.p.K); i < int(e.p.K+e.p.M); i++ {
|
||||
chunks[i] = make([]byte, chunk_size)
|
||||
for i = int(k); i < int(n); i++ {
|
||||
chunks[i] = make([]byte, chunkLen)
|
||||
pointers[i] = &chunks[i][0]
|
||||
}
|
||||
|
||||
data := (**C.uint8_t)(unsafe.Pointer(&pointers[:e.p.K][0]))
|
||||
coding := (**C.uint8_t)(unsafe.Pointer(&pointers[e.p.K:][0]))
|
||||
data := (**C.uint8_t)(unsafe.Pointer(&pointers[:k][0]))
|
||||
coding := (**C.uint8_t)(unsafe.Pointer(&pointers[k:][0]))
|
||||
|
||||
C.ec_encode_data(C.int(chunk_size), e.k, e.m, e.encode_tbls, data,
|
||||
C.ec_encode_data(C.int(chunkLen), k, m, e.encode_tbls, data,
|
||||
coding)
|
||||
return chunks, block_len
|
||||
return chunks, nil
|
||||
}
|
||||
|
||||
@@ -23,15 +23,14 @@ import (
|
||||
)
|
||||
|
||||
func (s *MySuite) TestVanderMondeDecode(c *C) {
|
||||
ep, _ := ParseEncoderParams(10, 5, Vandermonde)
|
||||
ep, _ := ParseEncoderParams(k, m, Vandermonde)
|
||||
|
||||
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
|
||||
|
||||
e := NewEncoder(ep)
|
||||
chunks, length := e.Encode(data)
|
||||
chunks, err := e.Encode(data)
|
||||
c.Logf("chunks length: %d", len(chunks))
|
||||
c.Logf("length: %d", length)
|
||||
c.Assert(length, Equals, len(data))
|
||||
c.Logf("length: %d", len(data))
|
||||
|
||||
chunks[0] = nil
|
||||
chunks[3] = nil
|
||||
@@ -39,7 +38,7 @@ func (s *MySuite) TestVanderMondeDecode(c *C) {
|
||||
chunks[9] = nil
|
||||
chunks[13] = nil
|
||||
|
||||
recoveredData, err := e.Decode(chunks, length)
|
||||
recoveredData, err := e.Decode(chunks, len(data))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
if !bytes.Equal(recoveredData, data) {
|
||||
|
||||
Reference in New Issue
Block a user