Documentation ¶
Overview ¶
Warn: Don't modify it. The galois field tables data is generated by mathtool/gentbls.go
Package reedsolomon implements Erasure Codes (systematic codes), it's based on: Reed-Solomon Codes over GF(2^8). Primitive Polynomial: x^8+x^4+x^3+x^2+1.
Galois Filed arithmetic using Intel SIMD instructions (AVX512 or AVX2).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMismatchVects = errors.New("too few/many vects given") ErrZeroVectSize = errors.New("vect size is 0") ErrMismatchVectSize = errors.New("vects size mismatched") )
var ( ErrNoNeedReconst = errors.New("no need reconst") ErrTooManyLost = errors.New("too many lost") ErrHasLostConflict = errors.New("dpHas&lost are conflicting") )
var ( ErrMismatchParityNum = errors.New("parity number mismatched") ErrIllegalVectIndex = errors.New("illegal vect index") )
var ( ErrTooManyReplace = errors.New("too many data for replacing") ErrMismatchReplace = errors.New("number of replaceRows and data mismatch") )
var EnableAVX512 = true
EnableAVX512 may slow down CPU Clock (maybe not). TODO need more research: https://lemire.me/blog/2018/04/19/by-how-much-does-avx-512-slow-down-your-cpu-a-first-experiment/
You can modify it before new RS.
var ErrIllegalVects = errors.New("illegal data/parity number: <= 0 or data+parity > 256")
var ErrNotSquare = errors.New("not a square matrix")
var ErrSingularMatrix = errors.New("matrix is singular")
Functions ¶
func SplitNeedReconst ¶
SplitNeedReconst splits data lost & parity lost.
Types ¶
type RS ¶
type RS struct { DataNum int // DataNum is the number of data row vectors. ParityNum int // ParityNum is the number of parity row vectors. GenMatrix matrix // Generator matrix. // contains filtered or unexported fields }
RS Reed-Solomon Codes receiver.
func (*RS) Encode ¶
Encode encodes data for generating parity. It multiplies generator matrix by vects[:r.DataNum] to get parity vectors, and write into vects[r.DataNum:].
func (*RS) Reconst ¶
Reconst reconstructs missing vectors, vects: All vectors, len(vects) = dataNum + parityNum. dpHas: Survived data & parity index, need dataNum indexes at least. needReconst: Vectors indexes which need to be reconstructed.
e.g: in 3+2, the whole index: [0,1,2,3,4], if vects[0,4] are lost & they need to be reconstructed (Maybe you only need vects[0], so the needReconst should be [0], but not [0,4]). the "dpHas" will be [1,2,3] ,and you must be sure that vects[1] vects[2] vects[3] have correct data, results will be written into vects[0]&vects[4] directly.
func (*RS) Replace ¶
Replace replaces oldData vectors with 0 or replaces 0 with newData vectors.
In practice, If len(replaceRows) > dataNum-parityNum, it's better to use Encode, because Replace need to read len(replaceRows) + parityNum vectors, if replaceRows are too many, the cost maybe larger than Encode (Encode only need read dataNum). Think about an EC compute node, and dataNum+parityNum data nodes model.
It's used in two situations: 1. We didn't have enough data for filling in a stripe, but still did ec encode, we need replace several zero vectors with new vectors which have data after we get enough data finally. 2. After compact, we may have several useless vectors in a stripe, we need replaces these useless vectors with zero vectors for free space.
Warn: data's index & replaceRows must has the same sort.