Skip to content

Commit

Permalink
add fail backup in ListBackups
Browse files Browse the repository at this point in the history
  • Loading branch information
wayblink committed Sep 2, 2022
1 parent c074508 commit 85a495c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 99 deletions.
15 changes: 13 additions & 2 deletions core/backup_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func (b BackupContext) ListBackups(ctx context.Context, request *backuppb.ListBa
Status: &backuppb.Status{
StatusCode: backuppb.StatusCode_UnexpectedError,
},
FailBackups: []string{},
}
if err != nil {
log.Error("Fail to list backup directory", zap.Error(err))
Expand All @@ -453,17 +454,26 @@ func (b BackupContext) ListBackups(ctx context.Context, request *backuppb.ListBa

log.Info("List Backups' path", zap.Strings("backup_paths", backupPaths))
backupInfos := make([]*backuppb.BackupInfo, 0)
failBackups := make([]string, 0)
for _, backupPath := range backupPaths {
backupResp, err := b.GetBackup(ctx, &backuppb.GetBackupRequest{
BackupName: BackupPathToName(backupPath),
})
if err != nil {
log.Warn("Fail to read backup",
zap.String("path", backupPath),
zap.Error(err))
resp.Status.Reason = err.Error()
return resp, nil
failBackups = append(failBackups, BackupPathToName(backupPath))
//return resp, nil
}
if backupResp.GetStatus().StatusCode != backuppb.StatusCode_Success {
log.Warn("Fail to read backup",
zap.String("path", backupPath),
zap.String("error", backupResp.GetStatus().GetReason()))
resp.Status.Reason = backupResp.GetStatus().GetReason()
return resp, nil
failBackups = append(failBackups, BackupPathToName(backupPath))
//return resp, nil
}

// 2, list wanted backup
Expand All @@ -487,6 +497,7 @@ func (b BackupContext) ListBackups(ctx context.Context, request *backuppb.ListBa
StatusCode: backuppb.StatusCode_Success,
},
BackupInfos: backupInfos,
FailBackups: failBackups,
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions core/backup_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestCreateBackup(t *testing.T) {
backup := CreateBackupContext(context, params)

req := &backuppb.CreateBackupRequest{
BackupName: "test_backup",
BackupName: "test_backup6",
}
backup.CreateBackup(context, req)
}
Expand All @@ -34,7 +34,7 @@ func TestListBackups(t *testing.T) {
CollectionName: "hello_milvus",
})
assert.NoError(t, err)
assert.Equal(t, len(backupListsWithCollection.BackupInfos), 1)
assert.Equal(t, 1, len(backupListsWithCollection.BackupInfos))

backupListsWithCollection2, err := backupContext.ListBackups(context, &backuppb.ListBackupsRequest{
CollectionName: "hello_milvus2",
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestDeleteBackup(t *testing.T) {
backupContext := CreateBackupContext(context, params)

backup, err := backupContext.DeleteBackup(context, &backuppb.DeleteBackupRequest{
BackupName: "test_backup",
BackupName: "test_backup6",
})
assert.NoError(t, err)
assert.Equal(t, backup.GetStatus().GetStatusCode(), backuppb.StatusCode_Success)
Expand Down
14 changes: 14 additions & 0 deletions core/milvus_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,20 @@ func TestMinIOCM(t *testing.T) {
})
}

func TestWriteAEmptyBackupFile(t *testing.T) {

Params.Init()
testBucket, err := Params.Load("minio.bucketName")
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

testCM, err := newMinIOMilvusStorage(ctx, testBucket)
err = testCM.Write("backup/test_backup6", nil)
assert.NoError(t, err)
}

func TestReadMilvusData(t *testing.T) {

Params.Init()
Expand Down
1 change: 1 addition & 0 deletions core/proto/backup.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ message ListBackupsRequest {
message ListBackupsResponse {
Status status = 1;
repeated BackupInfo backup_infos = 2;
repeated string failBackups = 3;
}

message DeleteBackupRequest {
Expand Down
Loading

0 comments on commit 85a495c

Please sign in to comment.