diff --git a/br/pkg/restore/log_client/client.go b/br/pkg/restore/log_client/client.go index 24cb20e16b0ab..4faf59a316657 100644 --- a/br/pkg/restore/log_client/client.go +++ b/br/pkg/restore/log_client/client.go @@ -299,7 +299,7 @@ func (rc *LogClient) RestoreCompactedSstFiles( // TODO: Future enhancements may explore the feasibility of reintroducing batch restoration // while maintaining optimal performance and resource utilization. for _, i := range backupFileSets { - err := rc.sstRestoreManager.restorer.Restore(onProgress, []restore.BackupFileSet{i}) + err := rc.sstRestoreManager.restorer.GoRestore(onProgress, []restore.BackupFileSet{i}) if err != nil { return errors.Trace(err) } diff --git a/br/pkg/restore/restorer.go b/br/pkg/restore/restorer.go index ff548afe9f8eb..75a21b583eb1f 100644 --- a/br/pkg/restore/restorer.go +++ b/br/pkg/restore/restorer.go @@ -119,9 +119,9 @@ func NewFileSet(files []*backuppb.File, rules *utils.RewriteRules) BackupFileSet // and MultiTablesRestorer. SstRestorer includes FileImporter for handling raw, transactional, and compacted SSTs, // and MultiTablesRestorer for TiDB-specific backups. type SstRestorer interface { - // Restore imports the specified backup file sets into TiKV. + // GoRestore imports the specified backup file sets into TiKV asynchronously. // The onProgress function is called with progress updates as files are processed. - Restore(onProgress func(int64), batchFileSets ...BatchBackupFileSet) error + GoRestore(onProgress func(int64), batchFileSets ...BatchBackupFileSet) error // WaitUntilFinish blocks until all pending restore files have completed processing. WaitUntilFinish() error @@ -184,7 +184,7 @@ func (s *SimpleRestorer) WaitUntilFinish() error { return s.eg.Wait() } -func (s *SimpleRestorer) Restore(onProgress func(int64), batchFileSets ...BatchBackupFileSet) error { +func (s *SimpleRestorer) GoRestore(onProgress func(int64), batchFileSets ...BatchBackupFileSet) error { for _, sets := range batchFileSets { for _, set := range sets { s.workerPool.ApplyOnErrorGroup(s.eg, @@ -248,7 +248,7 @@ func (m *MultiTablesRestorer) WaitUntilFinish() error { return nil } -func (m *MultiTablesRestorer) Restore(onProgress func(int64), batchFileSets ...BatchBackupFileSet) (err error) { +func (m *MultiTablesRestorer) GoRestore(onProgress func(int64), batchFileSets ...BatchBackupFileSet) (err error) { start := time.Now() fileCount := 0 defer func() { diff --git a/br/pkg/restore/restorer_test.go b/br/pkg/restore/restorer_test.go index 6ee0c3975e4a5..b9bc1c896fbc4 100644 --- a/br/pkg/restore/restorer_test.go +++ b/br/pkg/restore/restorer_test.go @@ -52,7 +52,7 @@ func TestSimpleRestorerImportAndProgress(t *testing.T) { fileSet := restore.BatchBackupFileSet{ {SSTFiles: files}, } - err := restorer.Restore(func(progress int64) { + err := restorer.GoRestore(func(progress int64) { progressCount += progress }, fileSet) require.NoError(t, err) @@ -65,7 +65,7 @@ func TestSimpleRestorerImportAndProgress(t *testing.T) { {SSTFiles: files}, } progressCount = int64(0) - err = restorer.Restore(func(progress int64) { + err = restorer.GoRestore(func(progress int64) { progressCount += progress }, batchFileSet) require.NoError(t, err) @@ -89,7 +89,7 @@ func TestSimpleRestorerWithErrorInImport(t *testing.T) { // Run restore and expect an error progressCount := int64(0) - err := restorer.Restore(func(progress int64) {}, fileSet) + err := restorer.GoRestore(func(progress int64) {}, fileSet) require.Error(t, err) require.Contains(t, err.Error(), "import error") require.Equal(t, int64(0), progressCount) @@ -144,7 +144,8 @@ func TestMultiTablesRestorerRestoreSuccess(t *testing.T) { var progress int64 fileSets := createSampleBatchFileSets() - err := restorer.Restore(func(p int64) { progress += p }, fileSets) + restorer.GoRestore(func(p int64) { progress += p }, fileSets) + err := restorer.WaitUntilFinish() require.NoError(t, err) // Ensure progress was tracked correctly @@ -160,7 +161,7 @@ func TestMultiTablesRestorerRestoreWithImportError(t *testing.T) { restorer := restore.NewMultiTablesRestorer(ctx, importer, workerPool, nil) fileSets := createSampleBatchFileSets() - restorer.Restore(func(int64) {}, fileSets) + restorer.GoRestore(func(int64) {}, fileSets) err := restorer.WaitUntilFinish() require.Error(t, err) require.Contains(t, err.Error(), "import error") @@ -178,7 +179,7 @@ func TestMultiTablesRestorerRestoreWithContextCancel(t *testing.T) { // Cancel context before restore completes cancel() - err := restorer.Restore(func(int64) {}, fileSets) + err := restorer.GoRestore(func(int64) {}, fileSets) require.ErrorIs(t, err, context.Canceled) } diff --git a/br/pkg/restore/snap_client/tikv_sender.go b/br/pkg/restore/snap_client/tikv_sender.go index 51938650a3bcb..57f73835beda7 100644 --- a/br/pkg/restore/snap_client/tikv_sender.go +++ b/br/pkg/restore/snap_client/tikv_sender.go @@ -385,7 +385,7 @@ func (rc *SnapClient) RestoreSSTFiles( } }) - retErr = rc.restorer.Restore(onProgress, tableIDWithFilesGroup...) + retErr = rc.restorer.GoRestore(onProgress, tableIDWithFilesGroup...) if retErr != nil { return retErr } diff --git a/br/pkg/task/restore_raw.go b/br/pkg/task/restore_raw.go index 1838b72f7b22f..c6afee4db4f7f 100644 --- a/br/pkg/task/restore_raw.go +++ b/br/pkg/task/restore_raw.go @@ -163,7 +163,7 @@ func RunRestoreRaw(c context.Context, g glue.Glue, cmdName string, cfg *RestoreR defer restore.RestorePostWork(ctx, importModeSwitcher, restoreSchedulers, cfg.Online) start := time.Now() - err = client.GetRestorer().Restore(onProgress, restore.CreateUniqueFileSets(files)) + err = client.GetRestorer().GoRestore(onProgress, restore.CreateUniqueFileSets(files)) if err != nil { return errors.Trace(err) } diff --git a/br/pkg/task/restore_txn.go b/br/pkg/task/restore_txn.go index 89854d1eccc84..c3325b75fe783 100644 --- a/br/pkg/task/restore_txn.go +++ b/br/pkg/task/restore_txn.go @@ -102,7 +102,7 @@ func RunRestoreTxn(c context.Context, g glue.Glue, cmdName string, cfg *Config) } defer restore.RestorePostWork(ctx, importModeSwitcher, restoreSchedulers, false) - err = client.GetRestorer().Restore(onProgress, restore.CreateUniqueFileSets(files)) + err = client.GetRestorer().GoRestore(onProgress, restore.CreateUniqueFileSets(files)) if err != nil { return errors.Trace(err) }