@@ -74,6 +74,12 @@ const (
74
74
"You may check the metadata and continue by wait other task finish or manually delete the lock file " + truncateLockPath + " at the external storage."
75
75
)
76
76
77
+ const (
78
+ waitInfoSchemaReloadCheckInterval = 1 * time .Second
79
+ // a million tables should take a few minutes to load all DDL change, making 15 to make sure we don't exit early
80
+ waitInfoSchemaReloadTimeout = 15 * time .Minute
81
+ )
82
+
77
83
var (
78
84
StreamStart = "log start"
79
85
StreamStop = "log stop"
@@ -1445,6 +1451,21 @@ func restoreStream(
1445
1451
return errors .Annotate (err , "failed to restore kv files" )
1446
1452
}
1447
1453
1454
+ // failpoint to stop for a while after restoring kvs
1455
+ // this is to mimic the scenario that restore takes long time and the lease in schemaInfo has expired and needs refresh
1456
+ failpoint .Inject ("post-restore-kv-pending" , func (val failpoint.Value ) {
1457
+ if val .(bool ) {
1458
+ // not ideal to use sleep but not sure what's the better way right now
1459
+ log .Info ("sleep after restoring kv" )
1460
+ time .Sleep (2 * time .Second )
1461
+ }
1462
+ })
1463
+
1464
+ // make sure schema reload finishes before proceeding
1465
+ if err = waitUntilSchemaReload (ctx , client ); err != nil {
1466
+ return errors .Trace (err )
1467
+ }
1468
+
1448
1469
if err = client .CleanUpKVFiles (ctx ); err != nil {
1449
1470
return errors .Annotate (err , "failed to clean up" )
1450
1471
}
@@ -1869,3 +1890,16 @@ func checkPiTRTaskInfo(
1869
1890
1870
1891
return curTaskInfo , doFullRestore , nil
1871
1892
}
1893
+
1894
+ func waitUntilSchemaReload (ctx context.Context , client * logclient.LogClient ) error {
1895
+ log .Info ("waiting for schema info finishes reloading" )
1896
+ reloadStart := time .Now ()
1897
+ conditionFunc := func () bool {
1898
+ return ! client .GetDomain ().IsLeaseExpired ()
1899
+ }
1900
+ if err := utils .WaitUntil (ctx , conditionFunc , waitInfoSchemaReloadCheckInterval , waitInfoSchemaReloadTimeout ); err != nil {
1901
+ return errors .Annotate (err , "failed to wait until schema reload" )
1902
+ }
1903
+ log .Info ("reloading schema finished" , zap .Duration ("timeTaken" , time .Since (reloadStart )))
1904
+ return nil
1905
+ }
0 commit comments