From c58148a421d254012f98c49e02ec6cd903a12b51 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 25 Aug 2020 10:50:40 -0700 Subject: [PATCH] avoid calling get bucket object lock config for same bucket (#3378) --- cmd/client-s3.go | 6 +----- cmd/cp-main.go | 17 +++++++++++++---- cmd/mirror-main.go | 12 +++++++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cmd/client-s3.go b/cmd/client-s3.go index e1d5577c..3f589cde 100644 --- a/cmd/client-s3.go +++ b/cmd/client-s3.go @@ -1004,11 +1004,7 @@ func (c *S3Client) Put(ctx context.Context, reader io.Reader, size int64, metada opts.LegalHold = minio.LegalHoldStatus(strings.ToUpper(lh)) opts.SendContentMd5 = true } - if opts.LegalHold == "" && opts.Mode == "" { - if _, _, _, err := c.api.GetBucketObjectLockConfig(ctx, bucket); err == nil { - opts.SendContentMd5 = true - } - } + ui, e := c.api.PutObject(ctx, bucket, object, reader, size, opts) if e != nil { errResponse := minio.ToErrorResponse(e) diff --git a/cmd/cp-main.go b/cmd/cp-main.go index 8356ebfb..21b8c7d9 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -370,6 +370,18 @@ func doCopySession(ctx context.Context, cancelCopy context.CancelFunc, cli *cli. pg = newAccounter(totalBytes) } + sourceURLs := cli.Args()[:len(cli.Args())-1] + targetURL := cli.Args()[len(cli.Args())-1] // Last one is target + + tgtClnt, err := newClient(targetURL) + fatalIf(err, "Unable to initialize `"+targetURL+"`.") + + // Check if the target bucket has object locking enabled + var withLock bool + if _, _, _, err = tgtClnt.GetObjectLockConfig(ctx); err == nil { + withLock = true + } + if session != nil { // isCopied returns true if an object has been already copied // or not. This is useful when we resume from a session. @@ -403,9 +415,6 @@ func doCopySession(ctx context.Context, cancelCopy context.CancelFunc, cli *cli. }() } else { - sourceURLs := cli.Args()[:len(cli.Args())-1] - targetURL := cli.Args()[len(cli.Args())-1] // Last one is target - // Access recursive flag inside the session header. isRecursive := cli.Bool("recursive") olderThan := cli.String("older-than") @@ -517,7 +526,7 @@ func doCopySession(ctx context.Context, cancelCopy context.CancelFunc, cli *cli. } } - cpURLs.MD5 = cli.Bool("md5") + cpURLs.MD5 = cli.Bool("md5") || withLock cpURLs.DisableMultipart = cli.Bool("disable-multipart") // Verify if previously copied, notify progress bar. diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index db3d0d88..113b2ead 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -807,8 +807,15 @@ func runMirror(ctx context.Context, cancelMirror context.CancelFunc, srcURL, dst } // object lock configuration set on bucket if mode != "" { - errorIf(newDstClt.SetObjectLockConfig(ctx, mode, validity, unit), + err = newDstClt.SetObjectLockConfig(ctx, mode, validity, unit) + errorIf(err, "Unable to set object lock config in `"+newTgtURL+"`.") + if err != nil && mj.opts.activeActive { + return true + } + if err == nil { + mj.opts.md5 = true + } } errorIf(copyBucketPolicies(ctx, newSrcClt, newDstClt, isOverwrite), "Unable to copy bucket policies to `"+newDstClt.GetURL().String()+"`.") @@ -853,6 +860,9 @@ func runMirror(ctx context.Context, cancelMirror context.CancelFunc, srcURL, dst if err != nil && mj.opts.activeActive { return true } + if err == nil { + mj.opts.md5 = true + } } err = copyBucketPolicies(ctx, srcClt, dstClt, isOverwrite)