Skip to content

Commit

Permalink
fix backup stage order
Browse files Browse the repository at this point in the history
  • Loading branch information
liubog2008 committed Apr 12, 2021
1 parent 697fd25 commit 19a37c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
20 changes: 10 additions & 10 deletions cmd/backup-manager/app/backup/manager.go
Expand Up @@ -142,13 +142,6 @@ func (bm *Manager) performBackup(ctx context.Context, backup *v1alpha1.Backup, d
started := time.Now()

var errs []error
err := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Type: v1alpha1.BackupRunning,
Status: corev1.ConditionTrue,
}, nil)
if err != nil {
return err
}

backupFullPath, err := util.GetStoragePath(backup)
if err != nil {
Expand All @@ -166,11 +159,10 @@ func (bm *Manager) performBackup(ctx context.Context, backup *v1alpha1.Backup, d
updatePathStatus := &controller.BackupUpdateStatus{
BackupPath: &backupFullPath,
}
err = bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
if err := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Type: v1alpha1.BackupPrepare,
Status: corev1.ConditionTrue,
}, updatePathStatus)
if err != nil {
}, updatePathStatus); err != nil {
return err
}

Expand Down Expand Up @@ -260,6 +252,14 @@ func (bm *Manager) performBackup(ctx context.Context, backup *v1alpha1.Backup, d
}
}

// change Prepare to Running before real backup process start
if err := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Type: v1alpha1.BackupRunning,
Status: corev1.ConditionTrue,
}, nil); err != nil {
return err
}

// run br binary to do the real job
backupErr := bm.backupData(ctx, backup)

Expand Down
8 changes: 4 additions & 4 deletions cmd/backup-manager/app/export/export.go
Expand Up @@ -59,11 +59,11 @@ func (bo *Options) getDestBucketURI(remotePath string) string {
return fmt.Sprintf("%s://%s", bo.StorageType, remotePath)
}

func (bo *Options) dumpTidbClusterData(ctx context.Context, backup *v1alpha1.Backup) (string, error) {
func (bo *Options) dumpTidbClusterData(ctx context.Context, backup *v1alpha1.Backup) error {
bfPath := bo.getBackupFullPath()
err := backupUtil.EnsureDirectoryExist(bfPath)
if err != nil {
return "", err
return err
}
args := []string{
fmt.Sprintf("--output=%s", bfPath),
Expand All @@ -88,9 +88,9 @@ func (bo *Options) dumpTidbClusterData(ctx context.Context, backup *v1alpha1.Bac

output, err := exec.CommandContext(ctx, binPath, args...).CombinedOutput()
if err != nil {
return bfPath, fmt.Errorf("cluster %s, execute dumpling command %v failed, output: %s, err: %v", bo, args, string(output), err)
return fmt.Errorf("cluster %s, execute dumpling command %v failed, output: %s, err: %v", bo, args, string(output), err)
}
return bfPath, nil
return nil
}

func (bo *Options) backupDataToRemote(ctx context.Context, source, bucketURI string, opts []string) error {
Expand Down
35 changes: 18 additions & 17 deletions cmd/backup-manager/app/export/manager.go
Expand Up @@ -154,7 +154,7 @@ func (bm *BackupManager) performBackup(ctx context.Context, backup *v1alpha1.Bac
started := time.Now()

err := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Type: v1alpha1.BackupRunning,
Type: v1alpha1.BackupPrepare,
Status: corev1.ConditionTrue,
}, nil)
if err != nil {
Expand Down Expand Up @@ -242,7 +242,23 @@ func (bm *BackupManager) performBackup(ctx context.Context, backup *v1alpha1.Bac
klog.Infof("set cluster %s %s to %s success", bm, constants.TikvGCVariable, constants.TikvGCLifeTime)
}

backupFullPath, backupErr := bm.dumpTidbClusterData(ctx, backup)
backupFullPath := bm.getBackupFullPath()
// TODO: Concurrent get file size and upload backup data to speed up processing time
archiveBackupPath := backupFullPath + constants.DefaultArchiveExtention
remotePath := strings.TrimPrefix(archiveBackupPath, constants.BackupRootPath+"/")
bucketURI := bm.getDestBucketURI(remotePath)
updatePathStatus := &controller.BackupUpdateStatus{
BackupPath: &bucketURI,
}
err = bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Type: v1alpha1.BackupRunning,
Status: corev1.ConditionTrue,
}, updatePathStatus)
if err != nil {
return err
}

backupErr := bm.dumpTidbClusterData(ctx, backup)
if oldTikvGCTimeDuration < tikvGCTimeDuration {
// use another context to revert `tikv_gc_life_time` back.
// `DefaultTerminationGracePeriodSeconds` for a pod is 30, so we use a smaller timeout value here.
Expand Down Expand Up @@ -296,8 +312,6 @@ func (bm *BackupManager) performBackup(ctx context.Context, backup *v1alpha1.Bac
}
klog.Infof("get cluster %s commitTs %s success", bm, commitTs)

// TODO: Concurrent get file size and upload backup data to speed up processing time
archiveBackupPath := backupFullPath + constants.DefaultArchiveExtention
err = archiveBackupData(backupFullPath, archiveBackupPath)
if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -332,19 +346,6 @@ func (bm *BackupManager) performBackup(ctx context.Context, backup *v1alpha1.Bac
// archive backup data successfully, origin dir can be deleted safely
os.RemoveAll(backupFullPath)

remotePath := strings.TrimPrefix(archiveBackupPath, constants.BackupRootPath+"/")
bucketURI := bm.getDestBucketURI(remotePath)
updatePathStatus := &controller.BackupUpdateStatus{
BackupPath: &bucketURI,
}
err = bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{
Type: v1alpha1.BackupPrepare,
Status: corev1.ConditionTrue,
}, updatePathStatus)
if err != nil {
return err
}

err = bm.backupDataToRemote(ctx, archiveBackupPath, bucketURI, opts)
if err != nil {
errs = append(errs, err)
Expand Down

0 comments on commit 19a37c8

Please sign in to comment.