Skip to content

Commit

Permalink
follow comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Feb 7, 2023
1 parent 18149f6 commit d9898f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 7 additions & 4 deletions ddl/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ var pdScheduleKey = []string{
"merge-schedule-limit",
}

// FlashbackGetMinSafeTimeTimeout only for test, don't change it.
var FlashbackGetMinSafeTimeTimeout = time.Minute // 1min

const (
flashbackMaxBackoff = 1800000 // 1800s
flashbackTimeout = 3 * time.Minute // 3min
Expand Down Expand Up @@ -128,12 +125,18 @@ func ValidateFlashbackTS(ctx context.Context, sctx sessionctx.Context, flashBack
return errors.Errorf("cannot set flashback timestamp to future time")
}

flashbackGetMinSafeTimeTimeout := time.Minute
failpoint.Inject("changeFlashbackGetMinSafeTimeTimeout", func(val failpoint.Value) {
t := val.(int)
flashbackGetMinSafeTimeTimeout = time.Duration(t)
})

start := time.Now()
minSafeTime := getStoreGlobalMinSafeTS(sctx.GetStore())
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
for oracleFlashbackTS.After(minSafeTime) {
if time.Since(start) >= FlashbackGetMinSafeTimeTimeout {
if time.Since(start) >= flashbackGetMinSafeTimeTimeout {
return errors.Errorf("cannot set flashback timestamp after min-resolved-ts(%s)", minSafeTime)
}
select {
Expand Down
11 changes: 3 additions & 8 deletions executor/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl"
ddlutil "github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -353,13 +352,8 @@ func TestFlashbackWithSafeTs(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

originTimeout := ddl.FlashbackGetMinSafeTimeTimeout
ddl.FlashbackGetMinSafeTimeTimeout = 0
defer func() {
ddl.FlashbackGetMinSafeTimeTimeout = originTimeout
}()

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/ddl/mockFlashbackTest", `return(true)`))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/ddl/changeFlashbackGetMinSafeTimeTimeout", `return(0)`))

timeBeforeDrop, _, safePointSQL, resetGC := MockGC(tk)
defer resetGC()
Expand Down Expand Up @@ -404,14 +398,15 @@ func TestFlashbackWithSafeTs(t *testing.T) {
start := time.Now()
tk.MustContainErrMsg(testcase.sql,
"cannot set flashback timestamp after min-resolved-ts")
// When set `FlashbackGetMinSafeTimeTimeout` = 0, no retry for `getStoreGlobalMinSafeTS`.
// When set `flashbackGetMinSafeTimeTimeout` = 0, no retry for `getStoreGlobalMinSafeTS`.
require.Less(t, time.Since(start), time.Second)
} else {
tk.MustExec(testcase.sql)
}
}
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/injectSafeTS"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockFlashbackTest"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/changeFlashbackGetMinSafeTimeTimeout"))
}

func TestFlashbackRetryGetMinSafeTime(t *testing.T) {
Expand Down

0 comments on commit d9898f9

Please sign in to comment.