From 3144cb97ed221cbb7e27e7e9048034e0326ce202 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 27 Dec 2021 09:16:15 -0800 Subject: [PATCH] remove retry in difference() comparator (#3903) it is potentially harmful when retrying a lot of buckets where in this might trigger a retry - continous Listing() however this retry is not needed as the callers restart as needed when --watch or --active-active are used. --- cmd/difference.go | 30 ++++-------- cmd/mirror-url.go | 4 +- cmd/retry-continous.go | 104 ----------------------------------------- go.mod | 2 +- go.sum | 4 +- 5 files changed, 15 insertions(+), 129 deletions(-) delete mode 100644 cmd/retry-continous.go diff --git a/cmd/difference.go b/cmd/difference.go index 79e9036d..2ca4f968 100644 --- a/cmd/difference.go +++ b/cmd/difference.go @@ -26,7 +26,6 @@ import ( // golang does not support flat keys for path matching, find does "github.com/minio/mc/pkg/probe" - "github.com/minio/minio-go/v7" "golang.org/x/text/unicode/norm" ) @@ -335,27 +334,18 @@ func difference(ctx context.Context, sourceClnt, targetClnt Client, sourceURL, t go func() { defer close(diffCh) - retryCtx, cancel := context.WithCancel(ctx) - defer cancel() - - for range newRetryTimerContinous(retryCtx, time.Second, time.Second*30, minio.MaxJitter) { - err := differenceInternal(retryCtx, sourceClnt, targetClnt, sourceURL, targetURL, - isMetadata, isRecursive, returnSimilar, dirOpt, diffCh) - if err != nil { - // handle this specifically for filesystem related errors. - switch err.ToGoError().(type) { - case PathNotFound, PathInsufficientPermission: - diffCh <- diffMessage{ - Error: err, - } - return + err := differenceInternal(ctx, sourceClnt, targetClnt, sourceURL, targetURL, + isMetadata, isRecursive, returnSimilar, dirOpt, diffCh) + if err != nil { + // handle this specifically for filesystem related errors. + switch err.ToGoError().(type) { + case PathNotFound, PathInsufficientPermission: + diffCh <- diffMessage{ + Error: err, } - errorIf(err, "Unable to list comparison retrying..") - } else { - // Success. - break + return } - + errorIf(err, "Unable to list comparison retrying..") } }() diff --git a/cmd/mirror-url.go b/cmd/mirror-url.go index 4f89f235..96c9fab6 100644 --- a/cmd/mirror-url.go +++ b/cmd/mirror-url.go @@ -136,13 +136,13 @@ func deltaSourceTarget(ctx context.Context, sourceURL, targetURL string, opts mi } srcSuffix := strings.TrimPrefix(diffMsg.FirstURL, sourceURL) - //Skip the source object if it matches the Exclude options provided + // Skip the source object if it matches the Exclude options provided if matchExcludeOptions(opts.excludeOptions, srcSuffix) { continue } tgtSuffix := strings.TrimPrefix(diffMsg.SecondURL, targetURL) - //Skip the target object if it matches the Exclude options provided + // Skip the target object if it matches the Exclude options provided if matchExcludeOptions(opts.excludeOptions, tgtSuffix) { continue } diff --git a/cmd/retry-continous.go b/cmd/retry-continous.go deleted file mode 100644 index 9e3182eb..00000000 --- a/cmd/retry-continous.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2015-2021 MinIO, Inc. -// -// This file is part of MinIO Object Storage stack -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -package cmd - -import ( - "context" - "math/rand" - "sync" - "time" - - "github.com/minio/minio-go/v7" -) - -// lockedRandSource provides protected rand source, implements rand.Source interface. -type lockedRandSource struct { - lk sync.Mutex - src rand.Source -} - -// Int63 returns a non-negative pseudo-random 63-bit integer as an int64. -func (r *lockedRandSource) Int63() (n int64) { - r.lk.Lock() - n = r.src.Int63() - r.lk.Unlock() - return -} - -// Seed uses the provided seed value to initialize the generator to a -// deterministic state. -func (r *lockedRandSource) Seed(seed int64) { - r.lk.Lock() - r.src.Seed(seed) - r.lk.Unlock() -} - -// Introduce a new locked random seed. -var random = rand.New(&lockedRandSource{src: rand.NewSource(time.Now().UTC().UnixNano())}) - -// newRetryTimerContinous creates a timer with exponentially increasing delays forever. -func newRetryTimerContinous(ctx context.Context, unit time.Duration, cap time.Duration, jitter float64) <-chan int { - attemptCh := make(chan int) - - // normalize jitter to the range [0, 1.0] - if jitter < minio.NoJitter { - jitter = minio.NoJitter - } - if jitter > minio.MaxJitter { - jitter = minio.MaxJitter - } - - // computes the exponential backoff duration according to - // https://www.awsarchitectureblog.com/2015/03/backoff.html - exponentialBackoffWait := func(attempt int) time.Duration { - // 1< maxAttempt { - attempt = maxAttempt - } - //sleep = random_between(0, min(cap, base * 2 ** attempt)) - sleep := unit * time.Duration(1< cap { - sleep = cap - } - if jitter != minio.NoJitter { - sleep -= time.Duration(random.Float64() * float64(sleep) * jitter) - } - return sleep - } - - go func() { - defer close(attemptCh) - var nextBackoff int - for { - select { - case attemptCh <- nextBackoff: - nextBackoff++ - case <-ctx.Done(): - return - } - - select { - case <-time.After(exponentialBackoffWait(nextBackoff)): - case <-ctx.Done(): - return - } - } - }() - return attemptCh -} diff --git a/go.mod b/go.mod index b9587b86..3e256f7f 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/minio/colorjson v1.0.1 github.com/minio/filepath v1.0.0 github.com/minio/madmin-go v1.1.17 - github.com/minio/minio-go/v7 v7.0.18 + github.com/minio/minio-go/v7 v7.0.20 github.com/minio/pkg v1.1.3 github.com/minio/selfupdate v0.3.1 github.com/minio/sha256-simd v1.0.0 diff --git a/go.sum b/go.sum index f0c088c5..b4a8f631 100644 --- a/go.sum +++ b/go.sum @@ -282,8 +282,8 @@ github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77Z github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/minio-go/v7 v7.0.11-0.20210302210017-6ae69c73ce78/go.mod h1:mTh2uJuAbEqdhMVl6CMIIZLUeiMiWtJR4JB8/5g2skw= -github.com/minio/minio-go/v7 v7.0.18 h1:fncn6iacnK+i2uYfNc5aVPG7bEqQH0nU4yAGMSunY0w= -github.com/minio/minio-go/v7 v7.0.18/go.mod h1:SyQ1IFeJuaa+eV5yEDxW7hYE1s5VVq5sgImDe27R+zg= +github.com/minio/minio-go/v7 v7.0.20 h1:0+Xt1SkCKDgcx5cmo3UxXcJ37u5Gy+/2i/+eQYqmYJw= +github.com/minio/minio-go/v7 v7.0.20/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do= github.com/minio/pkg v1.0.3/go.mod h1:obU54TZ9QlMv0TRaDgQ/JTzf11ZSXxnSfLrm4tMtBP8= github.com/minio/pkg v1.1.3 h1:J4vGnlNSxc/o9gDOQMZ3k0L3koA7ZgBQ7GRMrUpt/OY= github.com/minio/pkg v1.1.3/go.mod h1:32x/3OmGB0EOi1N+3ggnp+B5VFkSBBB9svPMVfpnf14=