Skip to content

Commit

Permalink
Merge pull request #472 from zilliztech/huwei_again
Browse files Browse the repository at this point in the history
backup & restore return error
  • Loading branch information
Thomas-HuWei authored Dec 5, 2024
2 parents 9b590de + 49baf6d commit e22a744
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
filters:
"*":
reviewers:
- wayblink
- huanghaoyuanhhy
- Thomas-HuWei
approvers:
- wayblink
- huanghaoyuanhhy
- Thomas-HuWei
2 changes: 2 additions & 0 deletions core/backup_impl_create_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,8 @@ func (b *BackupContext) executeCreateBackup(ctx context.Context, request *backup
if err != nil {
backupInfo.StateCode = backuppb.BackupTaskStateCode_BACKUP_FAIL
backupInfo.ErrorMessage = err.Error()
b.meta.UpdateBackup(backupInfo.Id, setStateCode(backuppb.BackupTaskStateCode_BACKUP_FAIL),
setErrorMessage(err.Error()))
return err
}
log.Info("finish backup all collections",
Expand Down
6 changes: 6 additions & 0 deletions core/backup_impl_restore_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,18 @@ func (b *BackupContext) executeRestoreBackupTask(ctx context.Context, backupBuck
job := func(ctx context.Context) error {
endTask, err := b.executeRestoreCollectionTask(ctx, backupBucketName, backupPath, restoreCollectionTaskClone, id)
if err != nil {
b.meta.UpdateRestoreTask(id, setRestoreStateCode(backuppb.RestoreTaskStateCode_FAIL),
setRestoreErrorMessage(endTask.ErrorMessage))
b.meta.UpdateRestoreCollectionTask(id, endTask.Id,
setRestoreCollectionStateCode(backuppb.RestoreTaskStateCode_FAIL),
setRestoreCollectionErrorMessage(endTask.ErrorMessage))
log.Error("executeRestoreCollectionTask failed",
zap.String("TargetDBName", restoreCollectionTaskClone.GetTargetDbName()),
zap.String("TargetCollectionName", restoreCollectionTaskClone.GetTargetCollectionName()),
zap.Error(err))
return err
}

restoreCollectionTaskClone.StateCode = backuppb.RestoreTaskStateCode_SUCCESS
log.Info("finish restore collection",
zap.String("db_name", restoreCollectionTaskClone.GetTargetDbName()),
Expand Down
30 changes: 30 additions & 0 deletions core/backup_meta_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,33 @@ func (meta *MetaManager) GetRestoreTask(taskID string) *backuppb.RestoreBackupTa
defer meta.mu.Unlock()
return meta.restoreTasks[taskID]
}

func (meta *MetaManager) UpdateRestoreCollectionTask(restoreID string, restoreCollectionId string, opts ...RestoreCollectionTaskOpt) {
meta.mu.Lock()
defer meta.mu.Unlock()
restoreBackup := meta.restoreTasks[restoreID]
tasks := restoreBackup.GetCollectionRestoreTasks()
for i := 0; i < len(tasks); i++ {
if tasks[i].Id == restoreCollectionId {
cBackup := proto.Clone(tasks[i]).(*backuppb.RestoreCollectionTask)
for _, opt := range opts {
opt(cBackup)
}
tasks[i] = cBackup
}
}
}

type RestoreCollectionTaskOpt func(task *backuppb.RestoreCollectionTask)

func setRestoreCollectionStateCode(stateCode backuppb.RestoreTaskStateCode) RestoreCollectionTaskOpt {
return func(task *backuppb.RestoreCollectionTask) {
task.StateCode = stateCode
}
}

func setRestoreCollectionErrorMessage(errorMessage string) RestoreCollectionTaskOpt {
return func(task *backuppb.RestoreCollectionTask) {
task.ErrorMessage = errorMessage
}
}
6 changes: 6 additions & 0 deletions core/backup_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ func (h *Handlers) handleGetRestore(c *gin.Context) (interface{}, error) {
if h.backupContext.params.HTTPCfg.SimpleResponse {
resp = SimpleRestoreResponse(resp)
}
log.Info("End to GetRestoreStateRequest",
zap.Any("code", resp.GetCode()),
zap.String("msg", resp.GetMsg()),
zap.Any("progress", resp.GetData().Progress),
zap.Any("stateCode", resp.GetData().StateCode),
)
c.JSON(http.StatusOK, resp)
return nil, nil
}
Expand Down

0 comments on commit e22a744

Please sign in to comment.