mirror of
https://github.com/pgsty/minio.git
synced 2026-08-11 08:43:28 +03:00
XL/Erasure: Make bit-rot verification based on xl.json algo. (#2299)
Currently `xl.json` saves algorithm information for bit-rot verification. Since the bit-rot algo's can change in the future make sure the erasureReadFile doesn't default to a particular algo. Instead use the checkSumInfo.
This commit is contained in:
+27
-21
@@ -52,6 +52,11 @@ type checkSumInfo struct {
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
// Constant indicates current bit-rot algo used when creating objects.
|
||||
const (
|
||||
bitRotAlgo = "blake2b"
|
||||
)
|
||||
|
||||
// erasureInfo - carries erasure coding related information, block
|
||||
// distribution and checksums.
|
||||
type erasureInfo struct {
|
||||
@@ -64,6 +69,28 @@ type erasureInfo struct {
|
||||
Checksum []checkSumInfo `json:"checksum,omitempty"`
|
||||
}
|
||||
|
||||
// AddCheckSum - add checksum of a part.
|
||||
func (e *erasureInfo) AddCheckSumInfo(ckSumInfo checkSumInfo) {
|
||||
for i, sum := range e.Checksum {
|
||||
if sum.Name == ckSumInfo.Name {
|
||||
e.Checksum[i] = ckSumInfo
|
||||
return
|
||||
}
|
||||
}
|
||||
e.Checksum = append(e.Checksum, ckSumInfo)
|
||||
}
|
||||
|
||||
// GetCheckSumInfo - get checksum of a part.
|
||||
func (e erasureInfo) GetCheckSumInfo(partName string) (ckSum checkSumInfo, err error) {
|
||||
// Return the checksum.
|
||||
for _, sum := range e.Checksum {
|
||||
if sum.Name == partName {
|
||||
return sum, nil
|
||||
}
|
||||
}
|
||||
return checkSumInfo{}, errUnexpected
|
||||
}
|
||||
|
||||
// statInfo - carries stat information of the object.
|
||||
type statInfo struct {
|
||||
Size int64 `json:"size"` // Size of the object `xl.json`.
|
||||
@@ -144,27 +171,6 @@ func (m *xlMetaV1) AddObjectPart(partNumber int, partName string, partETag strin
|
||||
sort.Sort(byObjectPartNumber(m.Parts))
|
||||
}
|
||||
|
||||
// AddCheckSum - add checksum of a part.
|
||||
func (m *xlMetaV1) AddCheckSum(partName, algorithm, checkSum string) {
|
||||
for i, sum := range m.Erasure.Checksum {
|
||||
if sum.Name == partName {
|
||||
m.Erasure.Checksum[i] = checkSumInfo{partName, "blake2b", checkSum}
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Erasure.Checksum = append(m.Erasure.Checksum, checkSumInfo{partName, "blake2b", checkSum})
|
||||
}
|
||||
|
||||
// GetCheckSum - get checksum of a part.
|
||||
func (m xlMetaV1) GetCheckSum(partName string) (checkSum, algorithm string, err error) {
|
||||
for _, sum := range m.Erasure.Checksum {
|
||||
if sum.Name == partName {
|
||||
return sum.Hash, sum.Algorithm, nil
|
||||
}
|
||||
}
|
||||
return "", "", errUnexpected
|
||||
}
|
||||
|
||||
// ObjectToPartOffset - translate offset of an object to offset of its individual part.
|
||||
func (m xlMetaV1) ObjectToPartOffset(offset int64) (partIndex int, partOffset int64, err error) {
|
||||
if offset == 0 {
|
||||
|
||||
Reference in New Issue
Block a user