mirror of https://github.com/minio/minio.git
Merge pull request #289 from harshavardhana/pr_out_remove_minio_calc_chunk_size_c_code_to_write_one_in_golang
This commit is contained in:
commit
a049024643
|
@ -19,14 +19,10 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SIMD_ALIGN 32
|
||||
|
||||
int32_t minio_init_encoder (int technique, int k, int m,
|
||||
uint8_t **encode_matrix,
|
||||
uint8_t **encode_tbls);
|
||||
|
||||
uint32_t minio_calc_chunk_size (int k, uint32_t split_len);
|
||||
|
||||
int32_t minio_init_decoder (int32_t *error_index,
|
||||
int k, int n, int errs,
|
||||
uint8_t *encoding_matrix,
|
||||
|
|
|
@ -35,6 +35,7 @@ int32_t _minio_src_index_in_error (int r, int32_t *error_index)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Separate out source data and target buffers
|
||||
int32_t minio_get_source_target (int errs, int k, int m,
|
||||
int32_t *error_index,
|
||||
uint32_t *decode_index,
|
||||
|
@ -95,7 +96,7 @@ int minio_init_decoder (int32_t *error_index,
|
|||
tmp_decode_index[i] = r;
|
||||
}
|
||||
|
||||
// Not all Vandermonde matrix can be inverted
|
||||
// Not all vandermonde matrix can be inverted
|
||||
if (gf_invert_matrix(input_matrix, inverse_matrix, k) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include "ec-code.h"
|
||||
#include "ec-common.h"
|
||||
|
||||
/*
|
||||
Generate encode matrix during the encoding phase
|
||||
*/
|
||||
|
||||
int32_t minio_init_encoder (int technique, int k, int m,
|
||||
uint8_t **encode_matrix,
|
||||
uint8_t **encode_tbls)
|
||||
|
@ -53,19 +57,3 @@ int32_t minio_init_encoder (int technique, int k, int m,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t minio_calc_chunk_size (int k, uint32_t split_len)
|
||||
{
|
||||
int alignment;
|
||||
int remainder;
|
||||
int padded_len;
|
||||
|
||||
alignment = k * SIMD_ALIGN;
|
||||
remainder = split_len % alignment;
|
||||
|
||||
padded_len = split_len;
|
||||
if (remainder) {
|
||||
padded_len = split_len + (alignment - remainder);
|
||||
}
|
||||
return padded_len / k;
|
||||
}
|
||||
|
|
|
@ -39,12 +39,10 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
|||
|
||||
k := int(e.k)
|
||||
n := int(e.k + e.m)
|
||||
|
||||
if len(chunks) != n {
|
||||
return nil, errors.New(fmt.Sprintf("chunks length must be %d", n))
|
||||
}
|
||||
|
||||
chunk_size := int(C.minio_calc_chunk_size(e.k, C.uint32_t(length)))
|
||||
chunk_size := getChunkSize(k, length)
|
||||
|
||||
error_index := make([]int, n+1)
|
||||
var err_count int = 0
|
||||
|
@ -97,6 +95,7 @@ func (e *Encoder) Decode(chunks [][]byte, length int) ([]byte, error) {
|
|||
recovered_output = append(recovered_output, chunks[i]...)
|
||||
}
|
||||
|
||||
// TODO cache this if necessary
|
||||
e.decode_matrix = decode_matrix
|
||||
e.decode_tbls = decode_tbls
|
||||
|
||||
|
|
|
@ -38,6 +38,10 @@ const (
|
|||
M = 3
|
||||
)
|
||||
|
||||
const (
|
||||
SimdAlign = 32
|
||||
)
|
||||
|
||||
// EncoderParams is a configuration set for building an encoder. It is created using ValidateParams.
|
||||
type EncoderParams struct {
|
||||
K uint8
|
||||
|
@ -112,15 +116,28 @@ func NewEncoder(ep *EncoderParams) *Encoder {
|
|||
}
|
||||
}
|
||||
|
||||
func getChunkSize(k, split_len int) int {
|
||||
var alignment, remainder, padded_len int
|
||||
|
||||
alignment = k * SimdAlign
|
||||
remainder = split_len % alignment
|
||||
|
||||
padded_len = split_len
|
||||
if remainder != 0 {
|
||||
padded_len = split_len + (alignment - remainder)
|
||||
}
|
||||
return padded_len / k
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
chunk_size := int(C.minio_calc_chunk_size(e.k, C.uint32_t(block_len)))
|
||||
chunk_len := chunk_size * int(e.p.K)
|
||||
pad_len := chunk_len - block_len
|
||||
chunk_size := getChunkSize(int(e.k), block_len)
|
||||
chunk_len := chunk_size * int(e.k)
|
||||
pad_len := int(chunk_len) - block_len
|
||||
|
||||
if pad_len > 0 {
|
||||
s := make([]byte, pad_len)
|
||||
|
|
Loading…
Reference in New Issue