From 85f08d77524644a99e62024c0d5e8ed151075a12 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 5 Sep 2024 13:37:19 -0700 Subject: [PATCH] verify part.N exists before reading part.N.meta (#20383) if part.N doesn't exist we do not have to complete the multipart transaction, it simply means that we have some partial upload situation at hand. --- cmd/erasure-multipart.go | 2 +- cmd/xl-storage.go | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/erasure-multipart.go b/cmd/erasure-multipart.go index 7389f2137..5c0106590 100644 --- a/cmd/erasure-multipart.go +++ b/cmd/erasure-multipart.go @@ -1106,7 +1106,7 @@ func (er erasureObjects) CompleteMultipartUpload(ctx context.Context, bucket str readQuorum := fi.ReadQuorum(er.defaultRQuorum()) // Read Part info for all parts - partPath := pathJoin(uploadIDPath, fi.DataDir) + "/" + partPath := pathJoin(uploadIDPath, fi.DataDir) + SlashSeparator partMetaPaths := make([]string, len(parts)) partNumbers := make([]int, len(parts)) for idx, part := range parts { diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index f46820d91..570cc7d2e 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -1097,13 +1097,13 @@ func (s *xlStorage) deleteVersions(ctx context.Context, volume, path string, fis var legacyJSON bool buf, err := xioutil.WithDeadline[[]byte](ctx, globalDriveConfig.GetMaxTimeout(), func(ctx context.Context) ([]byte, error) { - buf, err := s.readAllData(ctx, volume, volumeDir, pathJoin(volumeDir, path, xlStorageFormatFile)) + buf, _, err := s.readAllDataWithDMTime(ctx, volume, volumeDir, pathJoin(volumeDir, path, xlStorageFormatFile)) if err != nil && !errors.Is(err, errFileNotFound) { return nil, err } if errors.Is(err, errFileNotFound) && legacy { - buf, err = s.readAllData(ctx, volume, volumeDir, pathJoin(volumeDir, path, xlStorageFormatFileV1)) + buf, _, err = s.readAllDataWithDMTime(ctx, volume, volumeDir, pathJoin(volumeDir, path, xlStorageFormatFileV1)) if err != nil { return nil, err } @@ -3123,12 +3123,24 @@ func (s *xlStorage) ReadParts(ctx context.Context, volume string, partMetaPaths parts := make([]*ObjectPartInfo, len(partMetaPaths)) for idx, partMetaPath := range partMetaPaths { var partNumber int - fmt.Sscanf(pathutil.Dir(partMetaPath), "part.%d.meta", &partNumber) + fmt.Sscanf(pathutil.Base(partMetaPath), "part.%d.meta", &partNumber) if contextCanceled(ctx) { - parts[idx] = &ObjectPartInfo{Error: ctx.Err().Error(), Number: partNumber} + parts[idx] = &ObjectPartInfo{ + Error: ctx.Err().Error(), + Number: partNumber, + } continue } + + if err := Access(pathJoin(volumeDir, pathutil.Dir(partMetaPath), fmt.Sprintf("part.%d", partNumber))); err != nil { + parts[idx] = &ObjectPartInfo{ + Error: err.Error(), + Number: partNumber, + } + continue + } + data, err := s.readAllData(ctx, volume, volumeDir, pathJoin(volumeDir, partMetaPath)) if err != nil { parts[idx] = &ObjectPartInfo{ @@ -3137,11 +3149,16 @@ func (s *xlStorage) ReadParts(ctx context.Context, volume string, partMetaPaths } continue } + pinfo := &ObjectPartInfo{} if _, err = pinfo.UnmarshalMsg(data); err != nil { - parts[idx] = &ObjectPartInfo{Error: err.Error(), Number: partNumber} + parts[idx] = &ObjectPartInfo{ + Error: err.Error(), + Number: partNumber, + } continue } + parts[idx] = pinfo } diskHealthCheckOK(ctx, nil)