fix: Restore empty files when healing (#5257)

HealFile() does not process the case when an empty file is lost in
some disks. Since, Reedsolomon erasure doesn't handle restoring empty
data, HealFile will create empty files similarly to CreateFile().
master
A. Elleuch 7 years ago committed by kannappanr
parent 1a3dbbc9dd
commit 6ef0161835
  1. 18
      cmd/erasure-healfile.go

@ -78,12 +78,14 @@ func (s ErasureStorage) HealFile(staleDisks []StorageAPI, volume, path string, b
blocks[i] = make([]byte, chunksize) blocks[i] = make([]byte, chunksize)
} }
var chunkOffset, blockOffset int64 var chunkOffset, blockOffset int64
for ; blockOffset < size; blockOffset += blocksize {
// The for loop below is entered when size == 0 and
// blockOffset == 0 to allow for reconstructing empty files.
for ; blockOffset == 0 || blockOffset < size; blockOffset += blocksize {
// last iteration may have less than blocksize data // last iteration may have less than blocksize data
// left, so chunksize needs to be recomputed. // left, so chunksize needs to be recomputed.
if size < blockOffset+blocksize { if size < blockOffset+blocksize {
blocksize = size - blockOffset chunksize = getChunkSize(size-blockOffset, s.dataBlocks)
chunksize = getChunkSize(blocksize, s.dataBlocks)
for i := range blocks { for i := range blocks {
blocks[i] = blocks[i][:chunksize] blocks[i] = blocks[i][:chunksize]
} }
@ -121,9 +123,13 @@ func (s ErasureStorage) HealFile(staleDisks []StorageAPI, volume, path string, b
// iteration // iteration
chunkOffset += chunksize chunkOffset += chunksize
// reconstruct data - this computes all data and parity shards // reconstruct data - this computes all data and
if err = s.ErasureDecodeDataAndParityBlocks(blocks); err != nil { // parity shards - but we skip this step if we are
return f, err // reconstructing an empty file.
if chunksize > 0 {
if err = s.ErasureDecodeDataAndParityBlocks(blocks); err != nil {
return f, err
}
} }
// write computed shards as chunks on file in each // write computed shards as chunks on file in each

Loading…
Cancel
Save