From b7fe25299aee4bf43110395abe239acd49e54a86 Mon Sep 17 00:00:00 2001 From: 3pointer Date: Thu, 14 Jan 2021 16:43:18 +0800 Subject: [PATCH] cherry pick #693 to release-5.0-rc Signed-off-by: ti-srebot --- cmd/backup.go | 17 +++++++++++++++++ cmd/restore.go | 2 ++ pkg/task/backup.go | 6 +++++- tests/br_full_ddl/run.sh | 21 +++++++++++++++++++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/cmd/backup.go b/cmd/backup.go index 3fb8868b0..ddca70e77 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -6,6 +6,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" "github.com/pingcap/tidb/ddl" + "github.com/pingcap/tidb/session" "github.com/spf13/cobra" "go.uber.org/zap" @@ -21,7 +22,23 @@ func runBackupCommand(command *cobra.Command, cmdName string) error { command.SilenceUsage = false return errors.Trace(err) } +<<<<<<< HEAD if err := task.RunBackup(GetDefaultContext(), tidbGlue, cmdName, &cfg); err != nil { +======= + + ctx := GetDefaultContext() + if cfg.EnableOpenTracing { + var store *appdash.MemoryStore + ctx, store = trace.TracerStartSpan(ctx) + defer trace.TracerFinishSpan(ctx, store) + } + if cfg.IgnoreStats { + // Do not run stat worker in BR. + session.DisableStats4Test() + } + + if err := task.RunBackup(ctx, tidbGlue, cmdName, &cfg); err != nil { +>>>>>>> 87eb3ed... stats: disable stats by default (#693) log.Error("failed to backup", zap.Error(err)) return errors.Trace(err) } diff --git a/cmd/restore.go b/cmd/restore.go index 26aa20c59..6f17c2720 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -5,6 +5,7 @@ package cmd import ( "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/pingcap/tidb/session" "github.com/spf13/cobra" "go.uber.org/zap" @@ -67,6 +68,7 @@ func NewRestoreCommand() *cobra.Command { } utils.LogBRInfo() task.LogArguments(c) + session.DisableStats4Test() summary.SetUnit(summary.RestoreUnit) return nil diff --git a/pkg/task/backup.go b/pkg/task/backup.go index 169580b4b..89fccc635 100644 --- a/pkg/task/backup.go +++ b/pkg/task/backup.go @@ -83,7 +83,11 @@ func DefineBackupFlags(flags *pflag.FlagSet) { // This flag can impact the online cluster, so hide it in case of abuse. _ = flags.MarkHidden(flagRemoveSchedulers) - flags.Bool(flagIgnoreStats, false, + // Disable stats by default. because of + // 1. DumpStatsToJson is not stable + // 2. It increases memory usage may cause BR OOM + // TODO: we need a better way to backup/restore stats. + flags.Bool(flagIgnoreStats, true, "ignore backup stats, used for test") // This flag is used for test. we should backup stats all the time. _ = flags.MarkHidden(flagIgnoreStats) diff --git a/tests/br_full_ddl/run.sh b/tests/br_full_ddl/run.sh index 0dd2442f1..72314fffa 100755 --- a/tests/br_full_ddl/run.sh +++ b/tests/br_full_ddl/run.sh @@ -66,12 +66,12 @@ run_sql "analyze table $DB.$TABLE;" curl $TIDB_IP:10080/stats/dump/$DB/$TABLE | jq '.columns.field0' | jq 'del(.last_update_version)' > $BACKUP_STAT # backup full -echo "backup start..." +echo "backup start with stats..." # Do not log to terminal unset BR_LOG_TO_TERM cluster_index_before_backup=$(run_sql "show variables like '%cluster%';" | awk '{print $2}') -run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --ratelimit 5 --concurrency 4 --log-file $LOG || cat $LOG +run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --ratelimit 5 --concurrency 4 --log-file $LOG --ignore-stats=false || cat $LOG checksum_count=$(cat $LOG | grep "checksum success" | wc -l | xargs) if [ "${checksum_count}" != "1" ];then @@ -80,6 +80,9 @@ if [ "${checksum_count}" != "1" ];then exit 1 fi +echo "backup start without stats..." +run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/${DB}_disable_stats" --concurrency 4 + run_sql "DROP DATABASE $DB;" cluster_index_before_restore=$(run_sql "show variables like '%cluster%';" | awk '{print $2}') @@ -91,6 +94,20 @@ if [[ "${cluster_index_before_backup}" != "${cluster_index_before_restore}" ]]; exit 1 fi +echo "restore full without stats..." +run_br restore full -s "local://$TEST_DIR/${DB}_disable_stats" --pd $PD_ADDR +curl $TIDB_IP:10080/stats/dump/$DB/$TABLE | jq '.columns.field0' | jq 'del(.last_update_version)' > $RESOTRE_STAT + +# stats should not be equal because we disable stats by default. +if diff -q $BACKUP_STAT $RESOTRE_STAT > /dev/null +then + echo "TEST: [$TEST_NAME] fail due to stats are equal" + exit 1 +fi + +# clear restore environment +run_sql "DROP DATABASE $DB;" + # restore full echo "restore start..." export GO_FAILPOINTS="github.com/pingcap/br/pkg/pdutil/PDEnabledPauseConfig=return(true)"