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

add log for cmd arguments and duration for checksum #55

Merged
merged 2 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions cmd/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewMetaCommand() *cobra.Command {
return err
}
utils.LogBRInfo()
utils.LogArguments(c)
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewBackupCommand() *cobra.Command {
return err
}
utils.LogBRInfo()
utils.LogArguments(c)
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func NewRestoreCommand() *cobra.Command {
return err
}
utils.LogBRInfo()
utils.LogArguments(c)
return nil
},
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"os/signal"
"syscall"

"github.com/pingcap/br/cmd"
"github.com/pingcap/errors"
"github.com/spf13/cobra"

"github.com/pingcap/br/cmd"
)

func main() {
Expand Down
6 changes: 5 additions & 1 deletion pkg/raw/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ type tableChecksum struct {
checksum uint64
totalKvs uint64
totalBytes uint64
duration time.Duration
}

func getChecksumFromTiDB(
Expand All @@ -767,6 +768,7 @@ func getChecksumFromTiDB(
dbName string,
tableName string,
) (*tableChecksum, error) {
start := time.Now()
var recordSets []sqlexec.RecordSet
recordSets, err := dbSession.Execute(ctx, fmt.Sprintf(
"ADMIN CHECKSUM TABLE %s.%s", utils.EncloseName(dbName), utils.EncloseName(tableName)))
Expand Down Expand Up @@ -795,6 +797,7 @@ func getChecksumFromTiDB(
checksum: checksum,
totalKvs: totalKvs,
totalBytes: totalBytes,
duration: time.Since(start),
}, nil
}

Expand Down Expand Up @@ -846,7 +849,8 @@ func (bs *backupSchemas) finishTableChecksum() ([]*backup.Schema, error) {
zap.String("table", checksum.name),
zap.Uint64("Crc64Xor", checksum.checksum),
zap.Uint64("TotalKvs", checksum.totalKvs),
zap.Uint64("TotalBytes", checksum.totalBytes))
zap.Uint64("TotalBytes", checksum.totalBytes),
zap.Duration("take", checksum.duration))
s := bs.meta[checksum.name]
s.Crc64Xor = checksum.checksum
s.TotalKvs = checksum.totalKvs
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"

"github.com/pingcap/log"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -31,3 +33,12 @@ func PrintBRInfo() {
fmt.Println("Git Branch:", BRGitBranch)
fmt.Println("UTC Build Time: ", BRBuildTS)
}

// LogArguments prints origin command arguments
func LogArguments(cmd *cobra.Command) {
var fields []zap.Field
cmd.Flags().VisitAll(func(f *pflag.Flag) {
fields = append(fields, zap.Stringer(f.Name, f.Value))
})
log.Info("arguments", fields...)
}