|
|
@ -2,6 +2,7 @@ package encodedstorage |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
|
|
|
|
"crypto/md5" |
|
|
|
"encoding/gob" |
|
|
|
"encoding/gob" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"io" |
|
|
|
"io" |
|
|
@ -27,7 +28,7 @@ type encodedStorage struct { |
|
|
|
|
|
|
|
|
|
|
|
type StorageEntry struct { |
|
|
|
type StorageEntry struct { |
|
|
|
Path string |
|
|
|
Path string |
|
|
|
Md5sum string |
|
|
|
Md5sum []byte |
|
|
|
Blocks []StorageBlockEntry |
|
|
|
Blocks []StorageBlockEntry |
|
|
|
Encoderparams erasure.EncoderParams |
|
|
|
Encoderparams erasure.EncoderParams |
|
|
|
} |
|
|
|
} |
|
|
@ -109,7 +110,7 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error { |
|
|
|
encoder := erasure.NewEncoder(encoderParameters) |
|
|
|
encoder := erasure.NewEncoder(encoderParameters) |
|
|
|
entry := StorageEntry{ |
|
|
|
entry := StorageEntry{ |
|
|
|
Path: objectPath, |
|
|
|
Path: objectPath, |
|
|
|
Md5sum: "md5sum", |
|
|
|
Md5sum: nil, |
|
|
|
Blocks: make([]StorageBlockEntry, 0), |
|
|
|
Blocks: make([]StorageBlockEntry, 0), |
|
|
|
Encoderparams: erasure.EncoderParams{ |
|
|
|
Encoderparams: erasure.EncoderParams{ |
|
|
|
K: eStorage.K, |
|
|
|
K: eStorage.K, |
|
|
@ -117,10 +118,14 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error { |
|
|
|
Technique: erasure.CAUCHY, |
|
|
|
Technique: erasure.CAUCHY, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// allocate md5
|
|
|
|
|
|
|
|
hash := md5.New() |
|
|
|
i := 0 |
|
|
|
i := 0 |
|
|
|
// encode
|
|
|
|
// encode
|
|
|
|
for chunk := range chunks { |
|
|
|
for chunk := range chunks { |
|
|
|
if chunk.Err == nil { |
|
|
|
if chunk.Err == nil { |
|
|
|
|
|
|
|
// md5sum on chunk
|
|
|
|
|
|
|
|
hash.Write(chunk.Data) |
|
|
|
// encode each
|
|
|
|
// encode each
|
|
|
|
blocks, length := encoder.Encode(chunk.Data) |
|
|
|
blocks, length := encoder.Encode(chunk.Data) |
|
|
|
// store each
|
|
|
|
// store each
|
|
|
@ -140,6 +145,7 @@ func (eStorage *encodedStorage) Put(objectPath string, object io.Reader) error { |
|
|
|
} |
|
|
|
} |
|
|
|
i++ |
|
|
|
i++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
entry.Md5sum = hash.Sum(nil) |
|
|
|
eStorage.objects[objectPath] = entry |
|
|
|
eStorage.objects[objectPath] = entry |
|
|
|
var gobBuffer bytes.Buffer |
|
|
|
var gobBuffer bytes.Buffer |
|
|
|
gobEncoder := gob.NewEncoder(&gobBuffer) |
|
|
|
gobEncoder := gob.NewEncoder(&gobBuffer) |
|
|
|