Skip to content

Commit 54ecce6

Browse files
move readLock on uploadId at EOF in PutObjectPart (minio#258)
we do not need to hold the read locks at the higher layer instead before reading the body, instead hold the read locks properly at the time of renamePart() for protection from racy part overwrites to compete with concurrent completeMultipart().
1 parent 2b008c5 commit 54ecce6

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

cmd/erasure-multipart.go

+9
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,15 @@ func (er erasureObjects) PutObjectPart(ctx context.Context, bucket, object, uplo
744744
ctx = plkctx.Context()
745745
defer partIDLock.Unlock(plkctx)
746746

747+
// Read lock for upload id, only held while reading the upload metadata.
748+
uploadIDRLock := er.NewNSLock(bucket, pathJoin(object, uploadID))
749+
rlkctx, err := uploadIDRLock.GetRLock(ctx, globalOperationTimeout)
750+
if err != nil {
751+
return PartInfo{}, err
752+
}
753+
ctx = rlkctx.Context()
754+
defer uploadIDRLock.RUnlock(rlkctx)
755+
747756
onlineDisks, err = er.renamePart(ctx, onlineDisks, minioMetaTmpBucket, tmpPartPath, minioMetaMultipartBucket, partPath, partFI, writeQuorum)
748757
if err != nil {
749758
if errors.Is(err, errFileNotFound) {

cmd/erasure-server-pool.go

-10
Original file line numberDiff line numberDiff line change
@@ -1858,16 +1858,6 @@ func (z *erasureServerPools) PutObjectPart(ctx context.Context, bucket, object,
18581858
return PartInfo{}, err
18591859
}
18601860

1861-
// Read lock for upload id.
1862-
// Only held while reading the upload metadata.
1863-
uploadIDRLock := z.NewNSLock(bucket, pathJoin(object, uploadID))
1864-
rlkctx, err := uploadIDRLock.GetRLock(ctx, globalOperationTimeout)
1865-
if err != nil {
1866-
return PartInfo{}, err
1867-
}
1868-
ctx = rlkctx.Context()
1869-
defer uploadIDRLock.RUnlock(rlkctx)
1870-
18711861
if z.SinglePool() {
18721862
return z.serverPools[0].PutObjectPart(ctx, bucket, object, uploadID, partID, data, opts)
18731863
}

0 commit comments

Comments
 (0)