Repository: matrixorigin/matrixone
Pull request #12953 (2023-11-24 07:55:16)

Revert "[bug] BR: fix bug when restore data (#12942)"
This reverts commit d40ff8323f513293a430426c1126deb623a849f9.

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #12891 

## What this PR does / why we need it:
revert pr for issue12891


Patch:
diff --git a/pkg/logservice/service_bootstrap.go b/pkg/logservice/service_bootstrap.go
index 33f0e61cb..0384c64b6 100644
--- a/pkg/logservice/service_bootstrap.go
+++ b/pkg/logservice/service_bootstrap.go
@@ -51,20 +51,15 @@ func (s *Service) BootstrapHAKeeper(ctx context.Context, cfg Config) error {
 	numOfTNShards := cfg.BootstrapConfig.NumOfTNShards
 	numOfLogReplicas := cfg.BootstrapConfig.NumOfLogShardReplicas
 
-	fs, err := fileservice.Get[fileservice.FileService](s.fileService, defines.LocalFileServiceName)
-	if err != nil {
-		return err
-	}
-
 	var nextID uint64
 	var nextIDByKey map[string]uint64
-	backup, err := s.getBackupData(ctx, fs)
+	backup, err := s.getBackupData(ctx)
 	if err != nil {
 		return err
 	}
 	if backup != nil { // We are trying to restore from a backup.
 		// If a backup has already been issued, ignore this time.
-		_, err := fs.StatFile(ctx, restoredTagFile)
+		_, err := s.fileService.StatFile(ctx, restoredTagFile)
 		if s.cfg.BootstrapConfig.Restore.Force || // force is true, we do restore whatever.
 			(err != nil && moerr.IsMoErrCode(err, moerr.ErrFileNotFound)) {
 			// Restored tag file does not exist, we can do backup.
@@ -72,7 +67,7 @@ func (s *Service) BootstrapHAKeeper(ctx context.Context, cfg Config) error {
 			nextIDByKey = backup.NextIDByKey
 
 			// After backup, create a restore file.
-			if err := fs.Write(ctx, fileservice.IOVector{
+			if err := s.fileService.Write(ctx, fileservice.IOVector{
 				FilePath: restoredTagFile,
 				Entries: []fileservice.IOEntry{
 					{
@@ -107,7 +102,11 @@ func (s *Service) BootstrapHAKeeper(ctx context.Context, cfg Config) error {
 	return nil
 }
 
-func (s *Service) getBackupData(ctx context.Context, fs fileservice.FileService) (*pb.BackupData, error) {
+func (s *Service) getBackupData(ctx context.Context) (*pb.BackupData, error) {
+	fs, err := fileservice.Get[fileservice.FileService](s.fileService, defines.LocalFileServiceName)
+	if err != nil {
+		return nil, err
+	}
 	filePath := s.cfg.BootstrapConfig.Restore.FilePath
 	if filePath == "" {
 		return nil, nil


Test patch:
diff --git a/pkg/logservice/service_bootstrap_test.go b/pkg/logservice/service_bootstrap_test.go
index 44c113f36..2608d975b 100644
--- a/pkg/logservice/service_bootstrap_test.go
+++ b/pkg/logservice/service_bootstrap_test.go
@@ -50,7 +50,7 @@ func TestGetBackupData(t *testing.T) {
 		fileService: fs,
 	}
 	// If the file do not exist, do not return error.
-	restore, err := s.getBackupData(ctx, fs)
+	restore, err := s.getBackupData(ctx)
 	assert.NoError(t, err)
 	assert.Nil(t, restore)
 
@@ -66,12 +66,12 @@ func TestGetBackupData(t *testing.T) {
 	err = fs.Write(ctx, ioVec)
 	assert.NoError(t, err)
 
-	restore, err = s.getBackupData(ctx, fs)
+	restore, err = s.getBackupData(ctx)
 	assert.NoError(t, err)
 	assert.Nil(t, restore)
 
 	s.cfg.BootstrapConfig.Restore.FilePath = path.Join(dir, name)
-	restore, err = s.getBackupData(ctx, fs)
+	restore, err = s.getBackupData(ctx)
 	assert.NoError(t, err)
 	assert.NotNil(t, restore)
 	assert.Equal(t, nextID, restore.NextID)