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.
This commit is contained in:
Harshavardhana
2021-12-27 09:16:15 -08:00
committed by GitHub
parent 12012eafad
commit 3144cb97ed
5 changed files with 15 additions and 129 deletions
+10 -20
View File
@@ -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..")
}
}()
+2 -2
View File
@@ -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
}
-104
View File
@@ -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 <http://www.gnu.org/licenses/>.
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<<uint(attempt) below could overflow, so limit the value of attempt
maxAttempt := 30
if attempt > maxAttempt {
attempt = maxAttempt
}
//sleep = random_between(0, min(cap, base * 2 ** attempt))
sleep := unit * time.Duration(1<<uint(attempt))
if sleep > 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
}
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=