mirror of
https://github.com/minio/minio.git
synced 2025-01-24 13:13:16 -05:00
Adding initial documentation to erasure package
This commit is contained in:
parent
48898d770d
commit
96e42a8443
49
pkgs/erasure/doc.go
Normal file
49
pkgs/erasure/doc.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Package erasure is a Go wrapper for the Intel Intelligent Storage
|
||||||
|
// Acceleration Library (Intel ISA-L). Intel ISA-L is a CPU optimized
|
||||||
|
// implementation of erasure code.
|
||||||
|
//
|
||||||
|
// For more information on Intel ISA-L, please visit:
|
||||||
|
// https://01.org/intel%C2%AE-storage-acceleration-library-open-source-version
|
||||||
|
//
|
||||||
|
// Usage
|
||||||
|
//
|
||||||
|
// TODO: Explain Encode and Decode inputs and outputs
|
||||||
|
//
|
||||||
|
// TODO: Explain matrix size and how it corresponds to protection level
|
||||||
|
//
|
||||||
|
// Encoding data may be performed in 3 steps.
|
||||||
|
//
|
||||||
|
// 1. Create a validated set of encoder parameters
|
||||||
|
// 2. Create a new encoder
|
||||||
|
// 3. Encode data
|
||||||
|
//
|
||||||
|
// Decoding data is also performed in 3 steps.
|
||||||
|
//
|
||||||
|
// 1. Create a validated set of encoder parameters
|
||||||
|
// 2. Create a new encoder
|
||||||
|
// 3. Decode data
|
||||||
|
//
|
||||||
|
// Encoder parameters contain four configurable elements:
|
||||||
|
// ValidateParams(k, m, w, technique int) (EncoderParams, error)
|
||||||
|
// k - Number of rows in matrix
|
||||||
|
// m - Number of colums in matrix
|
||||||
|
// w - Word size, typically 8 or aligned by 8.
|
||||||
|
// technique - Matrix type, can be either CAUCHY (recommended) or VANDERMONDE
|
||||||
|
// constraints: k + m < 256
|
||||||
|
//
|
||||||
|
// Example
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Creating and using an encoder
|
||||||
|
// var bytes []byte
|
||||||
|
// params := erasure.ValidateParams(10,5, 8, erasure.CAUCHY)
|
||||||
|
// encoder := erasure.NewEncoder(params)
|
||||||
|
// encodedData, length := encoder.Encode(bytes)
|
||||||
|
//
|
||||||
|
// Creating and using a decoder
|
||||||
|
// var encodedData [][]byte
|
||||||
|
// var length int
|
||||||
|
// params := erasure.ValidateParams(10,5, 8, erasure.CAUCHY)
|
||||||
|
// encoder := erasure.NewEncoder(params)
|
||||||
|
// originalData, err := encoder.Decode(encodedData, length)
|
||||||
|
package erasure
|
@ -42,12 +42,14 @@ const (
|
|||||||
M = 3
|
M = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// EncoderParams is a configuration set for building an encoder. It is created using ValidateParams.
|
||||||
type EncoderParams struct {
|
type EncoderParams struct {
|
||||||
k,
|
k,
|
||||||
m,
|
m,
|
||||||
technique int // cauchy or vandermonde matrix (RS)
|
technique int // cauchy or vandermonde matrix (RS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Encoder is an object used to encode and decode data.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
p *EncoderParams
|
p *EncoderParams
|
||||||
k,
|
k,
|
||||||
@ -58,7 +60,11 @@ type Encoder struct {
|
|||||||
decode_tbls *C.uchar
|
decode_tbls *C.uchar
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameter validation
|
// ParseEncoderParams creates an EncoderParams object.
|
||||||
|
//
|
||||||
|
// k and n represent the matrix size, which corresponds to the protection level.
|
||||||
|
//
|
||||||
|
// technique is the matrix type. Valid inputs are CAUCHY (recommended) or VANDERMONDE.
|
||||||
func ParseEncoderParams(k, m, technique int) (*EncoderParams, error) {
|
func ParseEncoderParams(k, m, technique int) (*EncoderParams, error) {
|
||||||
if k < 1 {
|
if k < 1 {
|
||||||
return nil, errors.New("k cannot be zero")
|
return nil, errors.New("k cannot be zero")
|
||||||
@ -88,6 +94,7 @@ func ParseEncoderParams(k, m, technique int) (*EncoderParams, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewEncoder creates an encoder with a given set of parameters.
|
||||||
func NewEncoder(ep *EncoderParams) *Encoder {
|
func NewEncoder(ep *EncoderParams) *Encoder {
|
||||||
var k = C.int(ep.k)
|
var k = C.int(ep.k)
|
||||||
var m = C.int(ep.m)
|
var m = C.int(ep.m)
|
||||||
@ -110,6 +117,9 @@ func NewEncoder(ep *EncoderParams) *Encoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
func (e *Encoder) Encode(block []byte) ([][]byte, int) {
|
||||||
var block_len = len(block)
|
var block_len = len(block)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user