Skip to content

Commit

Permalink
support auto name generation (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
WuYiFan0108 authored Sep 13, 2023
1 parent af8704d commit 6bcf899
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
25 changes: 23 additions & 2 deletions core/backup_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package core
import (
"context"
"fmt"
"math/rand"
"testing"

"github.com/stretchr/testify/assert"
"github.com/zilliztech/milvus-backup/core/paramtable"
"github.com/zilliztech/milvus-backup/core/proto/backuppb"
"github.com/zilliztech/milvus-backup/core/utils"
"github.com/zilliztech/milvus-backup/internal/log"
"go.uber.org/zap"
"math/rand"
"testing"
)

func TestCreateBackup(t *testing.T) {
Expand Down Expand Up @@ -84,6 +85,26 @@ func TestDeleteBackup(t *testing.T) {

}

func TestCreateBackupWithNoName(t *testing.T) {
var params paramtable.BackupParams
params.Init()
context := context.Background()
backup := CreateBackupContext(context, params)

randBackupName := ""

req := &backuppb.CreateBackupRequest{
BackupName: randBackupName,
}
resp := backup.CreateBackup(context, req)
assert.Equal(t, backuppb.ResponseCode_Success, resp.GetCode())

// clean
backup.DeleteBackup(context, &backuppb.DeleteBackupRequest{
BackupName: randBackupName,
})
}

func TestCreateBackupWithUnexistCollection(t *testing.T) {
var params paramtable.BackupParams
params.Init()
Expand Down
10 changes: 4 additions & 6 deletions core/backup_impl_create_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func (b *BackupContext) CreateBackup(ctx context.Context, request *backuppb.Crea
}

// backup name validate
if request.GetBackupName() == "" {
request.BackupName = "backup_" + fmt.Sprint(time.Now().UTC().Format("2006_01_02_15_04_05_")) + fmt.Sprint(time.Now().Nanosecond())
}
if request.GetBackupName() != "" {
exist, err := b.getStorageClient().Exist(b.ctx, b.backupBucketName, b.backupRootPath+SEPERATOR+request.GetBackupName())
if err != nil {
Expand All @@ -68,12 +71,7 @@ func (b *BackupContext) CreateBackup(ctx context.Context, request *backuppb.Crea
return resp
}

var name string
if request.GetBackupName() == "" {
name = "backup_" + fmt.Sprint(time.Now().Unix())
} else {
name = request.BackupName
}
var name string = request.BackupName

milvusVersion, err := b.getMilvusClient().GetVersion(b.ctx)
if err != nil {
Expand Down

0 comments on commit 6bcf899

Please sign in to comment.