Skip to content

Commit

Permalink
cherry pick pingcap#1015 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
YuJuncen authored and ti-srebot committed Apr 16, 2021
1 parent 4014799 commit cf1d56a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pkg/logutil/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
backuppb "github.com/pingcap/kvproto/pkg/backup"
"github.com/pingcap/kvproto/pkg/import_sstpb"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/log"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -186,3 +187,24 @@ func Keys(keys [][]byte) zap.Field {
func ShortError(err error) zap.Field {
return zap.String("error", err.Error())
}
<<<<<<< HEAD
=======

var loggerToTerm, _, _ = log.InitLogger(new(log.Config), zap.AddCallerSkip(1))

// WarnTerm put a log both to terminal and to the log file.
func WarnTerm(message string, fields ...zap.Field) {
log.Warn(message, fields...)
if loggerToTerm != nil {
loggerToTerm.Warn(message, fields...)
}
}

// RedactAny constructs a redacted field that carries an interface{}.
func RedactAny(fieldKey string, key interface{}) zap.Field {
if redact.NeedRedact() {
return zap.String(fieldKey, "?")
}
return zap.Any(fieldKey, key)
}
>>>>>>> 0576f071... backup: set concurrency to 1 when ratelimit enabled (#1015)
21 changes: 21 additions & 0 deletions pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ import (
"strings"
"time"

<<<<<<< HEAD
"github.com/pingcap/br/pkg/utils"

=======
"github.com/docker/go-units"
"github.com/opentracing/opentracing-go"
>>>>>>> 0576f071... backup: set concurrency to 1 when ratelimit enabled (#1015)
"github.com/pingcap/errors"
backuppb "github.com/pingcap/kvproto/pkg/backup"
"github.com/pingcap/log"
Expand All @@ -25,6 +30,7 @@ import (
"github.com/pingcap/br/pkg/backup"
berrors "github.com/pingcap/br/pkg/errors"
"github.com/pingcap/br/pkg/glue"
"github.com/pingcap/br/pkg/logutil"
"github.com/pingcap/br/pkg/storage"
"github.com/pingcap/br/pkg/summary"
)
Expand Down Expand Up @@ -164,12 +170,27 @@ func parseCompressionFlags(flags *pflag.FlagSet) (*CompressionConfig, error) {
// so that both binary and TiDB will use same default value.
func (cfg *BackupConfig) adjustBackupConfig() {
cfg.adjust()
usingDefaultConcurrency := false
if cfg.Config.Concurrency == 0 {
cfg.Config.Concurrency = defaultBackupConcurrency
usingDefaultConcurrency = true
}
if cfg.Config.Concurrency > maxBackupConcurrency {
cfg.Config.Concurrency = maxBackupConcurrency
}
if cfg.RateLimit != unlimited {
// TiKV limits the upload rate by each backup request.
// When the backup requests are sent concurrently,
// the ratelimit couldn't work as intended.
// Degenerating to sequentially sending backup requests to avoid this.
if !usingDefaultConcurrency {
logutil.WarnTerm("setting `--ratelimit` and `--concurrency` at the same time, "+
"ignoring `--concurrency`: `--ratelimit` forces sequential (i.e. concurrency = 1) backup",
zap.String("ratelimit", units.HumanSize(float64(cfg.RateLimit))+"/s"),
zap.Uint32("concurrency-specified", cfg.Config.Concurrency))
}
cfg.Config.Concurrency = 1
}

if cfg.GCTTL == 0 {
cfg.GCTTL = utils.DefaultBRGCSafePointTTL
Expand Down
4 changes: 3 additions & 1 deletion pkg/task/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const (
defaultSwitchInterval = 5 * time.Minute
defaultGRPCKeepaliveTime = 10 * time.Second
defaultGRPCKeepaliveTimeout = 3 * time.Second

unlimited = 0
)

// TLSConfig is the common configuration for TLS connection.
Expand Down Expand Up @@ -143,7 +145,7 @@ func DefineCommonFlags(flags *pflag.FlagSet) {
flags.Uint(flagChecksumConcurrency, variable.DefChecksumTableConcurrency, "The concurrency of table checksumming")
_ = flags.MarkHidden(flagChecksumConcurrency)

flags.Uint64(flagRateLimit, 0, "The rate limit of the task, MB/s per node")
flags.Uint64(flagRateLimit, unlimited, "The rate limit of the task, MB/s per node")
flags.Bool(flagChecksum, true, "Run checksum at end of task")
flags.Bool(flagRemoveTiFlash, true,
"Remove TiFlash replicas before backup or restore, for unsupported versions of TiFlash")
Expand Down

0 comments on commit cf1d56a

Please sign in to comment.