erasure: Fix block index matching.

This patch fixes an important issue of block reconstruction upon block corruption.
master
Harshavardhana 8 years ago
parent 18b3871705
commit c6ac3fa6db
  1. 21
      erasure-readfile.go
  2. 1
      format-config-v1.go

@ -153,35 +153,36 @@ func metaPartBlockChecksums(disks []StorageAPI, eInfos []erasureInfo, partName s
}
// Takes block index and block distribution to get the disk index.
func toDiskIndex(blockIdx int, distribution []int) (diskIndex int) {
diskIndex = -1
func toDiskIndex(blockIdx int, distribution []int) int {
// Find out the right disk index for the input block index.
for index, blockIndex := range distribution {
if blockIndex == blockIdx {
diskIndex = index
if blockIndex-1 == blockIdx {
return index
}
}
return diskIndex
return -1
}
// isValidBlock - calculates the checksum hash for the block and
// validates if its correct returns true for valid cases, false otherwise.
func isValidBlock(disks []StorageAPI, volume, path string, diskIndex int, blockCheckSums []checkSumInfo) bool {
func isValidBlock(disks []StorageAPI, volume, path string, diskIndex int, blockCheckSums []checkSumInfo) (ok bool) {
ok = false
// Unknown block index requested, treat it as error.
if diskIndex == -1 {
return false
return ok
}
// Disk is not present, treat entire block to be non existent.
if disks[diskIndex] == nil {
return false
return ok
}
// Read everything for a given block and calculate hash.
hashWriter := newHash(blockCheckSums[diskIndex].Algorithm)
hashBytes, err := hashSum(disks[diskIndex], volume, path, hashWriter)
if err != nil {
return false
return ok
}
return hex.EncodeToString(hashBytes) == blockCheckSums[diskIndex].Hash
ok = hex.EncodeToString(hashBytes) == blockCheckSums[diskIndex].Hash
return ok
}
// decodeData - decode encoded blocks.

@ -231,6 +231,7 @@ func checkDisksConsistency(formatConfigs []*formatConfigV1) error {
// Collect currently available disk uuids.
for index, formatConfig := range formatConfigs {
if formatConfig == nil {
disks[index] = ""
continue
}
disks[index] = formatConfig.XL.Disk

Loading…
Cancel
Save