From ea9408ccbb34cd00dbc5c0e1212cc359eb543604 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 4 Oct 2018 04:39:24 +0100 Subject: [PATCH] worm: when enabled, avoid renaming the existing object in tmp directory (#6560) In XL PutObject & CompleteMultipartUpload, the existing object is renamed to the temporary directory before checking if worm is enabled or not. Most of the times, this doesn't cause an issue unless two uploads to the same location occurs at the same time. Since there is no locking in object handlers, both uploads will reach XL layer. The second client acquiring write lock in put object or complete upload in XL will rename the object to the temporary directory before doing the check and returning the error (wrong!). This commit fixes then the behavior: no rename to temporary directory if worm is enabled. --- cmd/xl-v1-multipart.go | 12 +++++------- cmd/xl-v1-object.go | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/xl-v1-multipart.go b/cmd/xl-v1-multipart.go index 5a94251ad..5a4369d65 100644 --- a/cmd/xl-v1-multipart.go +++ b/cmd/xl-v1-multipart.go @@ -739,6 +739,11 @@ func (xl xlObjects) CompleteMultipartUpload(ctx context.Context, bucket string, } if xl.isObject(bucket, object) { + // Deny if WORM is enabled + if globalWORMEnabled { + return ObjectInfo{}, ObjectAlreadyExists{Bucket: bucket, Object: object} + } + // Rename if an object already exists to temporary location. newUniqueID := mustGetUUID() @@ -767,13 +772,6 @@ func (xl xlObjects) CompleteMultipartUpload(ctx context.Context, bucket string, } } - // Deny if WORM is enabled - if globalWORMEnabled { - if xl.isObject(bucket, object) { - return ObjectInfo{}, ObjectAlreadyExists{Bucket: bucket, Object: object} - } - } - // Rename the multipart object to final location. if _, err = renameObject(ctx, onlineDisks, minioMetaMultipartBucket, uploadIDPath, bucket, object, writeQuorum); err != nil { return oi, toObjectErr(err, bucket, object) diff --git a/cmd/xl-v1-object.go b/cmd/xl-v1-object.go index f1de5cf76..33a6e7cf1 100644 --- a/cmd/xl-v1-object.go +++ b/cmd/xl-v1-object.go @@ -788,6 +788,11 @@ func (xl xlObjects) putObject(ctx context.Context, bucket string, object string, } if xl.isObject(bucket, object) { + // Deny if WORM is enabled + if globalWORMEnabled { + return ObjectInfo{}, ObjectAlreadyExists{Bucket: bucket, Object: object} + } + // Rename if an object already exists to temporary location. newUniqueID := mustGetUUID() @@ -816,13 +821,6 @@ func (xl xlObjects) putObject(ctx context.Context, bucket string, object string, return ObjectInfo{}, toObjectErr(err, bucket, object) } - // Deny if WORM is enabled - if globalWORMEnabled { - if xl.isObject(bucket, object) { - return ObjectInfo{}, ObjectAlreadyExists{Bucket: bucket, Object: object} - } - } - // Rename the successfully written temporary object to final location. if _, err = renameObject(ctx, onlineDisks, minioMetaTmpBucket, tempObj, bucket, object, writeQuorum); err != nil { return ObjectInfo{}, toObjectErr(err, bucket, object)