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

*: refline logs #189

Merged
merged 16 commits into from
Mar 20, 2020
4 changes: 2 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func AddFlags(cmd *cobra.Command) {

cmd.PersistentFlags().StringP(FlagLogLevel, "L", "info",
"Set the log level")
cmd.PersistentFlags().String(FlagLogFile, "",
"Set the log file path. If not set, logs will output to stdout")
cmd.PersistentFlags().String(FlagLogFile, "/tmp/br.log",
TennyZhuang marked this conversation as resolved.
Show resolved Hide resolved
"Set the log file path. If not set, logs will output to /tmp/br.log")
cmd.PersistentFlags().String(FlagStatusAddr, "",
"Set the HTTP listening address for the status report service. Set to empty string to disable")
task.DefineCommonFlags(cmd.PersistentFlags())
Expand Down
10 changes: 9 additions & 1 deletion pkg/summary/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ type LogCollector interface {

type logFunc func(msg string, fields ...zap.Field)

var collector = newLogCollector(log.Info)
var collector = func() LogCollector {
conf := new(log.Config)
// Always output summary to stdout.
logger, _, err := log.InitLogger(conf)
if err != nil {
logger = log.L()
}
return newLogCollector(logger.Info)
TennyZhuang marked this conversation as resolved.
Show resolved Hide resolved
}()

type logCollector struct {
mu sync.Mutex
Expand Down
1 change: 1 addition & 0 deletions pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig

err = client.SaveBackupMeta(ctx, ddlJobs)
if err != nil {
log.Error("save backup meta failed", zap.Reflect("meta", ddlJobs))
Copy link
Collaborator

@IANTHEREAL IANTHEREAL Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of ddl jobs may be particularly large, especially as the system runs longer and longer,

it is recommended to

  • print lastSchemaVersion into pkg/backup.GetBackupDDLJobs
  • print client.backupMeta if backup failed (you may need to add a PrintMetaData function for backup client)

return err
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/task/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/backup"
"github.com/pingcap/log"
pd "github.com/pingcap/pd/v4/client"
"github.com/pingcap/tidb-tools/pkg/filter"
"github.com/pingcap/tidb/store/tikv"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.etcd.io/etcd/pkg/transport"
"go.uber.org/zap"

"github.com/pingcap/br/pkg/conn"
"github.com/pingcap/br/pkg/glue"
Expand Down Expand Up @@ -268,6 +270,7 @@ func ReadBackupMeta(
}
backupMeta := &backup.BackupMeta{}
if err = proto.Unmarshal(metaData, backupMeta); err != nil {
log.Error("parse backupmeta failed", zap.Error(err), zap.Binary("meta", metaData))
TennyZhuang marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil, nil, errors.Annotate(err, "parse backupmeta failed")
}
return u, s, backupMeta, nil
Expand Down
9 changes: 8 additions & 1 deletion pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (cfg *RestoreConfig) ParseFromFlags(flags *pflag.FlagSet) error {
}

// RunRestore starts a restore task inside the current goroutine.
func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConfig) error {
func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConfig) (err error) {
ctx, cancel := context.WithCancel(c)
defer cancel()

Expand Down Expand Up @@ -103,6 +103,13 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
if err != nil {
return err
}

defer func() {
if err != nil {
log.Error("restore failed", zap.Error(err), zap.Reflect("meta", backupMeta))
TennyZhuang marked this conversation as resolved.
Show resolved Hide resolved
}
}()

if err = client.InitBackupMeta(backupMeta, u); err != nil {
return err
}
Expand Down