@@ -451,6 +451,67 @@ func TestFlashbackWithSafeTs(t *testing.T) {
451
451
require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/changeFlashbackGetMinSafeTimeTimeout" ))
452
452
}
453
453
454
+ func TestFlashbackTSOWithSafeTs (t * testing.T ) {
455
+ store := testkit .CreateMockStore (t )
456
+ tk := testkit .NewTestKit (t , store )
457
+
458
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/mockFlashbackTest" , `return(true)` ))
459
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/changeFlashbackGetMinSafeTimeTimeout" , `return(0)` ))
460
+
461
+ timeBeforeDrop , _ , safePointSQL , resetGC := MockGC (tk )
462
+ defer resetGC ()
463
+
464
+ // Set GC safe point.
465
+ tk .MustExec (fmt .Sprintf (safePointSQL , timeBeforeDrop ))
466
+
467
+ time .Sleep (time .Second )
468
+ ts , _ := tk .Session ().GetStore ().GetOracle ().GetTimestamp (context .Background (), & oracle.Option {})
469
+ flashbackTs := oracle .GetTimeFromTS (ts )
470
+ testcases := []struct {
471
+ name string
472
+ sql string
473
+ injectSafeTS uint64
474
+ // compareWithSafeTS will be 0 if FlashbackTS==SafeTS, -1 if FlashbackTS < SafeTS, and +1 if FlashbackTS > SafeTS.
475
+ compareWithSafeTS int
476
+ }{
477
+ {
478
+ name : "5 seconds ago to now, safeTS 5 secs ago" ,
479
+ sql : fmt .Sprintf ("flashback cluster to timestamp '%d'" , ts ),
480
+ injectSafeTS : oracle .GoTimeToTS (flashbackTs ),
481
+ compareWithSafeTS : 0 ,
482
+ },
483
+ {
484
+ name : "10 seconds ago to now, safeTS 5 secs ago" ,
485
+ sql : fmt .Sprintf ("flashback cluster to timestamp '%d'" , ts ),
486
+ injectSafeTS : oracle .GoTimeToTS (flashbackTs .Add (10 * time .Second )),
487
+ compareWithSafeTS : - 1 ,
488
+ },
489
+ {
490
+ name : "5 seconds ago to now, safeTS 10 secs ago" ,
491
+ sql : fmt .Sprintf ("flashback cluster to timestamp '%d'" , ts ),
492
+ injectSafeTS : oracle .GoTimeToTS (flashbackTs .Add (- 10 * time .Second )),
493
+ compareWithSafeTS : 1 ,
494
+ },
495
+ }
496
+ for _ , testcase := range testcases {
497
+ t .Log (testcase .name )
498
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/injectSafeTS" ,
499
+ fmt .Sprintf ("return(%v)" , testcase .injectSafeTS )))
500
+ if testcase .compareWithSafeTS == 1 {
501
+ start := time .Now ()
502
+ tk .MustContainErrMsg (testcase .sql ,
503
+ "cannot set flashback timestamp after min-resolved-ts" )
504
+ // When set `flashbackGetMinSafeTimeTimeout` = 0, no retry for `getStoreGlobalMinSafeTS`.
505
+ require .Less (t , time .Since (start ), time .Second )
506
+ } else {
507
+ tk .MustExec (testcase .sql )
508
+ }
509
+ }
510
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/injectSafeTS" ))
511
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/mockFlashbackTest" ))
512
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/changeFlashbackGetMinSafeTimeTimeout" ))
513
+ }
514
+
454
515
func TestFlashbackRetryGetMinSafeTime (t * testing.T ) {
455
516
store := testkit .CreateMockStore (t )
456
517
tk := testkit .NewTestKit (t , store )
0 commit comments