From 9212e11b90c30296c75654958617982de814aa22 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 24 Jul 2016 22:49:27 -0700 Subject: [PATCH] XL/GetObject: When disk is not available, checksum should be empty. (#2276) --- xl-v1-metadata.go | 2 +- xl-v1-object.go | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/xl-v1-metadata.go b/xl-v1-metadata.go index 49a16f2b4..7e71d1788 100644 --- a/xl-v1-metadata.go +++ b/xl-v1-metadata.go @@ -156,7 +156,7 @@ func (m *xlMetaV1) AddCheckSum(partName, algorithm, checkSum string) { } // GetCheckSum - get checksum of a part. -func (m *xlMetaV1) GetCheckSum(partName string) (checkSum, algorithm string, err error) { +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 diff --git a/xl-v1-object.go b/xl-v1-object.go index 3554cde93..dd440adb0 100644 --- a/xl-v1-object.go +++ b/xl-v1-object.go @@ -79,14 +79,12 @@ func (xl xlObjects) GetObject(bucket, object string, startOffset int64, length i onlineDisks, modTime := listOnlineDisks(xl.storageDisks, metaArr, errs) // Pick latest valid metadata. - var xlMeta xlMetaV1 - for _, meta := range metaArr { - if meta.IsValid() && meta.Stat.ModTime == modTime { - xlMeta = meta - break - } - } + xlMeta := pickValidXLMeta(metaArr, modTime) + + // Reorder online disks based on erasure distribution order. onlineDisks = getOrderedDisks(xlMeta.Erasure.Distribution, onlineDisks) + + // Reorder parts metadata based on erasure distribution order. metaArr = getOrderedPartsMetadata(xlMeta.Erasure.Distribution, metaArr) // Reply back invalid range if the input offset and length fall out of range. @@ -172,9 +170,14 @@ func (xl xlObjects) GetObject(bucket, object string, startOffset int64, length i // Get the checksums of the current part. checkSums := make([]string, len(onlineDisks)) - for index := range onlineDisks { + for index, disk := range onlineDisks { + // Disk is not found skip the checksum. + if disk == nil { + checkSums[index] = "" + continue + } checkSums[index], _, err = metaArr[index].GetCheckSum(partName) - if err != nil { + if err != nil { // FIXME - relook at returning error here. return toObjectErr(err, bucket, object) } }