Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

*: reduce unnecessary error stack trace #610

Merged
merged 3 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.uber.org/zap"

berrors "github.com/pingcap/br/pkg/errors"
"github.com/pingcap/br/pkg/logutil"
"github.com/pingcap/br/pkg/restore"
"github.com/pingcap/br/pkg/rtree"
"github.com/pingcap/br/pkg/task"
Expand Down Expand Up @@ -106,8 +107,8 @@ func newCheckSumCommand() *cobra.Command {
zap.Uint64("totalBytes", file.GetTotalBytes()),
zap.Uint64("startVersion", file.GetStartVersion()),
zap.Uint64("endVersion", file.GetEndVersion()),
zap.Stringer("startKey", utils.WrapKey(file.GetStartKey())),
zap.Stringer("endKey", utils.WrapKey(file.GetEndKey())),
zap.Stringer("startKey", logutil.WrapKey(file.GetStartKey())),
zap.Stringer("endKey", logutil.WrapKey(file.GetEndKey())),
)

var data []byte
Expand Down Expand Up @@ -186,7 +187,7 @@ func newBackupMetaCommand() *cobra.Command {
log.Error(
"file ranges overlapped",
zap.Stringer("out", out),
utils.ZapFile(file),
logutil.File(file),
)
}
}
Expand Down
62 changes: 28 additions & 34 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ version: '3.2'

services:
control:
image: control:latest
image: control:nightly
build:
context: .
dockerfile: ./docker/Dockerfile
volumes:
- ./docker/data:/data
- ./docker/logs:/tmp
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/tmp
- /tmp/br/docker/logs:/logs
- ./bin:/go/src/github.com/pingcap/br/bin
command: -c "/usr/bin/tail -f /dev/null"
depends_on:
- "tidb"
Expand All @@ -19,13 +21,13 @@ services:
- ./docker/minio.env

pd0:
image: pingcap/pd:latest
image: pingcap/pd:nightly
ports:
- "2379"
volumes:
- ./docker/config/pd.toml:/pd.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/logs
command:
- --name=pd0
- --client-urls=http://0.0.0.0:2379
Expand All @@ -45,11 +47,11 @@ services:
restart: on-failure

tikv0:
image: pingcap/tikv:latest
image: pingcap/tikv:nightly
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv0:20160
Expand All @@ -70,11 +72,11 @@ services:
- ./docker/minio.env

tikv1:
image: pingcap/tikv:latest
image: pingcap/tikv:nightly
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv1:20160
Expand All @@ -95,11 +97,11 @@ services:
- ./docker/minio.env

tikv2:
image: pingcap/tikv:latest
image: pingcap/tikv:nightly
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv2:20160
Expand All @@ -120,11 +122,11 @@ services:
- ./docker/minio.env

tikv3:
image: pingcap/tikv:latest
image: pingcap/tikv:nightly
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv3:20160
Expand All @@ -145,11 +147,11 @@ services:
- ./docker/minio.env

tikv4:
image: pingcap/tikv:latest
image: pingcap/tikv:nightly
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
- /tmp/br/docker/data:/data
- /tmp/br/docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv4:20160
Expand All @@ -170,13 +172,13 @@ services:
- ./docker/minio.env

tidb:
image: pingcap/tidb:latest
image: pingcap/tidb:nightly
ports:
- "4000:4000"
- "10080:10080"
- "4000"
- "10080"
volumes:
- ./docker/config/tidb.toml:/tidb.toml:ro
- ./docker/logs:/logs
- /tmp/br/docker/logs:/logs
command:
- --store=tikv
- --path=pd0:2379
Expand All @@ -202,15 +204,7 @@ services:
ports:
- 24927:24927
volumes:
- ./docker/data/s3:/data/s3
- /tmp/br/docker/data/s3:/data/s3
command: server --address=:24927 /data/s3
env_file:
- ./docker/minio.env

tidb-vision:
image: pingcap/tidb-vision:latest
environment:
PD_ENDPOINT: pd0:2379
ports:
- "8010:8010"
restart: on-failure
27 changes: 14 additions & 13 deletions pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/pingcap/br/pkg/conn"
berrors "github.com/pingcap/br/pkg/errors"
"github.com/pingcap/br/pkg/glue"
"github.com/pingcap/br/pkg/logutil"
"github.com/pingcap/br/pkg/rtree"
"github.com/pingcap/br/pkg/storage"
"github.com/pingcap/br/pkg/summary"
Expand Down Expand Up @@ -482,8 +483,8 @@ func (bc *Client) BackupRange(
}
}()
log.Info("backup started",
zap.Stringer("StartKey", utils.WrapKey(startKey)),
zap.Stringer("EndKey", utils.WrapKey(endKey)),
zap.Stringer("StartKey", logutil.WrapKey(startKey)),
zap.Stringer("EndKey", logutil.WrapKey(endKey)),
zap.Uint64("RateLimit", req.RateLimit),
zap.Uint32("Concurrency", req.Concurrency))

Expand Down Expand Up @@ -518,8 +519,8 @@ func (bc *Client) BackupRange(

if req.IsRawKv {
log.Info("backup raw ranges",
zap.Stringer("startKey", utils.WrapKey(startKey)),
zap.Stringer("endKey", utils.WrapKey(endKey)),
zap.Stringer("startKey", logutil.WrapKey(startKey)),
zap.Stringer("endKey", logutil.WrapKey(endKey)),
zap.String("cf", req.Cf))
} else {
log.Info("backup time range",
Expand Down Expand Up @@ -554,14 +555,14 @@ func (bc *Client) findRegionLeader(ctx context.Context, key []byte) (*metapb.Pee
}
if region.Leader != nil {
log.Info("find leader",
zap.Reflect("Leader", region.Leader), zap.Stringer("Key", utils.WrapKey(key)))
zap.Reflect("Leader", region.Leader), zap.Stringer("Key", logutil.WrapKey(key)))
return region.Leader, nil
}
log.Warn("no region found", zap.Stringer("Key", utils.WrapKey(key)))
log.Warn("no region found", zap.Stringer("Key", logutil.WrapKey(key)))
time.Sleep(time.Millisecond * time.Duration(100*i))
continue
}
return nil, errors.Annotatef(berrors.ErrBackupNoLeader, "can not find leader for key %s", utils.WrapKey(key))
return nil, errors.Annotatef(berrors.ErrBackupNoLeader, "can not find leader for key %s", logutil.WrapKey(key))
}

func (bc *Client) fineGrainedBackup(
Expand Down Expand Up @@ -644,8 +645,8 @@ func (bc *Client) fineGrainedBackup(
zap.Reflect("error", resp.Error))
}
log.Info("put fine grained range",
zap.Stringer("StartKey", utils.WrapKey(resp.StartKey)),
zap.Stringer("EndKey", utils.WrapKey(resp.EndKey)),
zap.Stringer("StartKey", logutil.WrapKey(resp.StartKey)),
zap.Stringer("EndKey", logutil.WrapKey(resp.EndKey)),
)
rangeTree.Put(resp.StartKey, resp.EndKey, resp.Files)

Expand Down Expand Up @@ -806,8 +807,8 @@ func SendBackup(
backupLoop:
for retry := 0; retry < backupRetryTimes; retry++ {
log.Info("try backup",
zap.Stringer("StartKey", utils.WrapKey(req.StartKey)),
zap.Stringer("EndKey", utils.WrapKey(req.EndKey)),
zap.Stringer("StartKey", logutil.WrapKey(req.StartKey)),
zap.Stringer("EndKey", logutil.WrapKey(req.EndKey)),
zap.Uint64("storeID", storeID),
zap.Int("retry time", retry),
)
Expand Down Expand Up @@ -856,8 +857,8 @@ backupLoop:
}
// TODO: handle errors in the resp.
log.Info("range backuped",
zap.Stringer("StartKey", utils.WrapKey(resp.GetStartKey())),
zap.Stringer("EndKey", utils.WrapKey(resp.GetEndKey())))
zap.Stringer("StartKey", logutil.WrapKey(resp.GetStartKey())),
zap.Stringer("EndKey", logutil.WrapKey(resp.GetEndKey())))
err = respFn(resp)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

berrors "github.com/pingcap/br/pkg/errors"
"github.com/pingcap/br/pkg/glue"
"github.com/pingcap/br/pkg/logutil"
"github.com/pingcap/br/pkg/pdutil"
"github.com/pingcap/br/pkg/utils"
)
Expand Down Expand Up @@ -237,7 +238,7 @@ func (mgr *Mgr) ResetBackupClient(ctx context.Context, storeID uint64) (backup.B
conn, err = mgr.getGrpcConnLocked(ctx, storeID)
if err != nil {
log.Warn("failed to reset grpc connection, retry it",
zap.Int("retry time", retry), zap.Error(err))
zap.Int("retry time", retry), logutil.ShortError(err))
time.Sleep(time.Duration(retry+3) * time.Second)
continue
}
Expand Down
27 changes: 16 additions & 11 deletions pkg/utils/logging.go → pkg/logutil/logging.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.

package utils
package logutil

import (
"encoding/hex"
Expand Down Expand Up @@ -110,27 +110,32 @@ func WrapKeys(keys [][]byte) zapcore.ArrayMarshaler {
return zapArrayMarshalKeysMixIn(keys)
}

// ZapRewriteRule make the zap fields for a rewrite rule.
func ZapRewriteRule(rewriteRule *import_sstpb.RewriteRule) zapcore.Field {
// RewriteRule make the zap fields for a rewrite rule.
func RewriteRule(rewriteRule *import_sstpb.RewriteRule) zapcore.Field {
return zap.Object("rewriteRule", zapMarshalRewriteRuleMixIn{rewriteRule})
}

// ZapRegion make the zap fields for a region.
func ZapRegion(region *metapb.Region) zapcore.Field {
// Region make the zap fields for a region.
func Region(region *metapb.Region) zapcore.Field {
return zap.Object("region", zapMarshalRegionMixIn{region})
}

// ZapFile make the zap fields for a file.
func ZapFile(file *backup.File) zapcore.Field {
// File make the zap fields for a file.
func File(file *backup.File) zapcore.Field {
return zap.Object("file", zapMarshalFileMixIn{file})
}

// ZapSSTMeta make the zap fields for a SST meta.
func ZapSSTMeta(sstMeta *import_sstpb.SSTMeta) zapcore.Field {
// SSTMeta make the zap fields for a SST meta.
func SSTMeta(sstMeta *import_sstpb.SSTMeta) zapcore.Field {
return zap.Object("sstMeta", zapMarshalSSTMetaMixIn{sstMeta})
}

// ZapFiles make the zap field for a set of file.
func ZapFiles(fs []*backup.File) zapcore.Field {
// Files make the zap field for a set of file.
func Files(fs []*backup.File) zapcore.Field {
return zap.Object("fs", files(fs))
}

// ShortError make the zap field to display error.
overvenus marked this conversation as resolved.
Show resolved Hide resolved
func ShortError(err error) zapcore.Field {
return zap.String("error", err.Error())
}
5 changes: 3 additions & 2 deletions pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/pingcap/br/pkg/conn"
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"
"github.com/pingcap/br/pkg/utils"
Expand Down Expand Up @@ -517,7 +518,7 @@ func (rc *Client) RestoreFiles(
if err == nil {
log.Info("Restore files",
zap.Duration("take", elapsed),
utils.ZapFiles(files))
logutil.Files(files))
summary.CollectSuccessUnit("files", len(files), elapsed)
}
}()
Expand All @@ -537,7 +538,7 @@ func (rc *Client) RestoreFiles(
func() error {
fileStart := time.Now()
defer func() {
log.Info("import file done", utils.ZapFile(fileReplica),
log.Info("import file done", logutil.File(fileReplica),
zap.Duration("take", time.Since(fileStart)))
updateCh.Inc()
}()
Expand Down
Loading