Skip to content

Commit

Permalink
cherry pick pingcap#693 to release-5.0-rc
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
3pointer authored and ti-srebot committed Jan 14, 2021
1 parent 9adc69b commit b7fe252
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
17 changes: 17 additions & 0 deletions cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -67,6 +68,7 @@ func NewRestoreCommand() *cobra.Command {
}
utils.LogBRInfo()
task.LogArguments(c)
session.DisableStats4Test()

summary.SetUnit(summary.RestoreUnit)
return nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions tests/br_full_ddl/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}')
Expand All @@ -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)"
Expand Down

0 comments on commit b7fe252

Please sign in to comment.