mirror of
https://github.com/pgsty/minio.git
synced 2026-07-19 20:20:25 +03:00
XL: Cleanup, comments and all the updated functions. (#1830)
This commit is contained in:
-74
@@ -15,77 +15,3 @@
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"hash"
|
||||
|
||||
"github.com/klauspost/reedsolomon"
|
||||
)
|
||||
|
||||
// erasure storage layer.
|
||||
type erasureConfig struct {
|
||||
reedSolomon reedsolomon.Encoder // Erasure encoder/decoder.
|
||||
dataBlocks int // Calculated data disks.
|
||||
storageDisks []StorageAPI // Initialized storage disks.
|
||||
distribution []int // Erasure block distribution.
|
||||
hashWriters []hash.Hash // Allocate hash writers.
|
||||
|
||||
// Carries hex checksums needed for validating Reads.
|
||||
hashChecksums []string
|
||||
checkSumAlgo string
|
||||
}
|
||||
|
||||
// newErasure instantiate a new erasure.
|
||||
func newErasure(disks []StorageAPI, distribution []int) *erasureConfig {
|
||||
// Initialize E.
|
||||
e := &erasureConfig{}
|
||||
|
||||
// Calculate data and parity blocks.
|
||||
dataBlocks, parityBlocks := len(disks)/2, len(disks)/2
|
||||
|
||||
// Initialize reed solomon encoding.
|
||||
rs, err := reedsolomon.New(dataBlocks, parityBlocks)
|
||||
fatalIf(err, "Unable to initialize reedsolomon package.")
|
||||
|
||||
// Save the reedsolomon.
|
||||
e.dataBlocks = dataBlocks
|
||||
e.reedSolomon = rs
|
||||
|
||||
// Save all the initialized storage disks.
|
||||
e.storageDisks = disks
|
||||
|
||||
// Save the distribution.
|
||||
e.distribution = distribution
|
||||
|
||||
// Return successfully initialized.
|
||||
return e
|
||||
}
|
||||
|
||||
// SaveAlgo - FIXME.
|
||||
func (e *erasureConfig) SaveAlgo(algo string) {
|
||||
e.checkSumAlgo = algo
|
||||
}
|
||||
|
||||
// Save hex encoded hashes - saves hashes that need to be validated
|
||||
// during reads for each blocks.
|
||||
func (e *erasureConfig) SaveHashes(hashes []string) {
|
||||
e.hashChecksums = hashes
|
||||
}
|
||||
|
||||
// InitHash - initializes new hash for all blocks.
|
||||
func (e *erasureConfig) InitHash(algo string) {
|
||||
e.hashWriters = make([]hash.Hash, len(e.storageDisks))
|
||||
for index := range e.storageDisks {
|
||||
e.hashWriters[index] = newHash(algo)
|
||||
}
|
||||
}
|
||||
|
||||
// GetHashes - returns a slice of hex encoded hash.
|
||||
func (e erasureConfig) GetHashes() []string {
|
||||
var hexHashes = make([]string, len(e.storageDisks))
|
||||
for index, hashWriter := range e.hashWriters {
|
||||
hexHashes[index] = hex.EncodeToString(hashWriter.Sum(nil))
|
||||
}
|
||||
return hexHashes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user