Skip to content

Commit 2c806ff

Browse files
*: support migrate to zilliz
Signed-off-by: huanghaoyuanhhy <haoyuan.huang@zilliz.com>
1 parent c350849 commit 2c806ff

46 files changed

Lines changed: 1040 additions & 175 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/zilliztech/milvus-backup/cmd/del"
1010
"github.com/zilliztech/milvus-backup/cmd/get"
1111
"github.com/zilliztech/milvus-backup/cmd/list"
12+
"github.com/zilliztech/milvus-backup/cmd/migrate"
1213
"github.com/zilliztech/milvus-backup/cmd/restore"
1314
"github.com/zilliztech/milvus-backup/cmd/root"
1415
"github.com/zilliztech/milvus-backup/cmd/server"
@@ -26,6 +27,7 @@ func Execute() {
2627
cmd.AddCommand(list.NewCmd(&opt))
2728
cmd.AddCommand(restore.NewCmd(&opt))
2829
cmd.AddCommand(server.NewCmd(&opt))
30+
cmd.AddCommand(migrate.NewCmd(&opt))
2931

3032
cmd.SetOut(os.Stdout)
3133
cmd.SetErr(os.Stderr)

cmd/migrate/migrate.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package migrate
2+
3+
import (
4+
"context"
5+
"errors"
6+
7+
"github.com/google/uuid"
8+
"github.com/spf13/cobra"
9+
10+
"github.com/zilliztech/milvus-backup/cmd/root"
11+
"github.com/zilliztech/milvus-backup/core/meta/taskmgr"
12+
"github.com/zilliztech/milvus-backup/core/migrate"
13+
"github.com/zilliztech/milvus-backup/core/paramtable"
14+
)
15+
16+
type options struct {
17+
backupName string
18+
clusterID string
19+
}
20+
21+
func (o *options) validate() error {
22+
if o.clusterID == "" {
23+
return errors.New("cluster id is required")
24+
}
25+
26+
if o.backupName == "" {
27+
return errors.New("backup name is required")
28+
}
29+
30+
return nil
31+
}
32+
33+
func (o *options) run(cmd *cobra.Command, params *paramtable.BackupParams) error {
34+
taskID := uuid.NewString()
35+
task, err := migrate.NewTask(taskID, o.backupName, o.clusterID, params)
36+
if err != nil {
37+
return err
38+
}
39+
40+
if err := task.Prepare(context.TODO()); err != nil {
41+
return err
42+
}
43+
44+
if err := task.Execute(context.TODO()); err != nil {
45+
return err
46+
}
47+
48+
taskStat, err := taskmgr.DefaultMgr.GetMigrateTask(taskID)
49+
if err != nil {
50+
return err
51+
}
52+
53+
cmd.Printf("Successfully triggered migration")
54+
cmd.Printf("with backup name: %s target cluster: %s", o.backupName, o.clusterID)
55+
cmd.Printf("migration job id: %s.", taskStat.MigrateJobID())
56+
cmd.Printf("You can check the progress of the migration job in Zilliz Cloud console.")
57+
58+
return nil
59+
}
60+
61+
func (o *options) addFlags(cmd *cobra.Command) {
62+
cmd.Flags().StringVarP(&o.backupName, "name", "n", "", "need to migrate backup name")
63+
cmd.Flags().StringVarP(&o.clusterID, "cluster_id", "c", "", "target cluster id")
64+
}
65+
66+
func NewCmd(opt *root.Options) *cobra.Command {
67+
var o options
68+
69+
cmd := &cobra.Command{
70+
Use: "migrate",
71+
Short: "migrate the backup data to zilliz cloud cluster",
72+
RunE: func(cmd *cobra.Command, args []string) error {
73+
var params paramtable.BackupParams
74+
params.GlobalInitWithYaml(opt.Config)
75+
params.Init()
76+
77+
if err := o.validate(); err != nil {
78+
return err
79+
}
80+
81+
err := o.run(cmd, &params)
82+
cobra.CheckErr(err)
83+
84+
return nil
85+
},
86+
}
87+
88+
o.addFlags(cmd)
89+
90+
return cmd
91+
}

cmd/migrate/migrate_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package migrate
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestOptions_Validate(t *testing.T) {
10+
t.Run("Valid", func(t *testing.T) {
11+
var o options
12+
o.backupName = "backup"
13+
o.clusterID = "cluster"
14+
err := o.validate()
15+
assert.NoError(t, err)
16+
})
17+
18+
t.Run("BackupNameEmpty", func(t *testing.T) {
19+
var o options
20+
o.clusterID = "cluster"
21+
err := o.validate()
22+
assert.Error(t, err)
23+
})
24+
25+
t.Run("ClusterIDEmpty", func(t *testing.T) {
26+
var o options
27+
o.backupName = "backup"
28+
err := o.validate()
29+
assert.Error(t, err)
30+
})
31+
}

configs/backup.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ log:
88
http:
99
simpleResponse: true
1010

11+
# Zilliz Cloud config.
12+
# If you want to migrate data to Zilliz Cloud, you need to configure the following parameters.
13+
# Otherwise, you can ignore it.
14+
cloud:
15+
address: https://api.cloud.zilliz.com
16+
apikey: <your-api-key>
17+
1118
# milvus proxy address, compatible to milvus.yaml
1219
milvus:
1320
address: localhost

core/backup/collection.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"golang.org/x/sync/semaphore"
1616
"google.golang.org/protobuf/proto"
1717

18-
"github.com/zilliztech/milvus-backup/core/client"
18+
"github.com/zilliztech/milvus-backup/core/client/milvus"
1919
"github.com/zilliztech/milvus-backup/core/meta"
2020
"github.com/zilliztech/milvus-backup/core/pbconv"
2121
"github.com/zilliztech/milvus-backup/core/proto/backuppb"
@@ -44,8 +44,8 @@ type CollectionOpt struct {
4444

4545
Meta *meta.MetaManager
4646

47-
Grpc client.Grpc
48-
Restful client.Restful
47+
Grpc milvus.Grpc
48+
Restful milvus.Restful
4949
}
5050

5151
type CollectionTask struct {
@@ -70,8 +70,8 @@ type CollectionTask struct {
7070

7171
meta *meta.MetaManager
7272

73-
grpc client.Grpc
74-
restful client.Restful
73+
grpc milvus.Grpc
74+
restful milvus.Restful
7575

7676
logger *zap.Logger
7777
}
@@ -419,7 +419,7 @@ func (ct *CollectionTask) getSegment(ctx context.Context, seg *milvuspb.Persiste
419419
return bakSeg, nil
420420
}
421421

422-
func (ct *CollectionTask) listInsertLogByAPI(ctx context.Context, binlogDir string, fieldsBinlog []client.BinlogInfo) ([]*backuppb.FieldBinlog, int64, error) {
422+
func (ct *CollectionTask) listInsertLogByAPI(ctx context.Context, binlogDir string, fieldsBinlog []milvus.BinlogInfo) ([]*backuppb.FieldBinlog, int64, error) {
423423
keys, sizes, err := storage.ListPrefixFlat(ctx, ct.milvusStorage, binlogDir, true)
424424
if err != nil {
425425
return nil, 0, fmt.Errorf("backup: list insert logs %w", err)
@@ -449,7 +449,7 @@ func (ct *CollectionTask) listInsertLogByAPI(ctx context.Context, binlogDir stri
449449
return bakFieldsBinlog, lo.Sum(sizes), nil
450450
}
451451

452-
func (ct *CollectionTask) listDeltaLogByAPI(ctx context.Context, binlogDir string, fieldsBinlog []client.BinlogInfo) ([]*backuppb.FieldBinlog, int64, error) {
452+
func (ct *CollectionTask) listDeltaLogByAPI(ctx context.Context, binlogDir string, fieldsBinlog []milvus.BinlogInfo) ([]*backuppb.FieldBinlog, int64, error) {
453453
keys, sizes, err := storage.ListPrefixFlat(ctx, ct.milvusStorage, binlogDir, true)
454454
if err != nil {
455455
return nil, 0, fmt.Errorf("backup: list insert logs %w", err)

core/backup/collection_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/stretchr/testify/mock"
1111
"go.uber.org/zap"
1212

13-
"github.com/zilliztech/milvus-backup/core/client"
13+
"github.com/zilliztech/milvus-backup/core/client/milvus"
1414
"github.com/zilliztech/milvus-backup/core/proto/backuppb"
1515
"github.com/zilliztech/milvus-backup/core/storage"
1616
"github.com/zilliztech/milvus-backup/core/storage/mpath"
@@ -135,7 +135,7 @@ func TestCollectionTask_listInsertLogByAPI(t *testing.T) {
135135
ct.milvusStorage = newMockStorage(t, dir, objs)
136136
ct.milvusRootPath = "base"
137137

138-
binlogs := []client.BinlogInfo{{FieldID: 1, LogIDs: []int64{1, 2}}, {FieldID: 2, LogIDs: []int64{1, 2}}}
138+
binlogs := []milvus.BinlogInfo{{FieldID: 1, LogIDs: []int64{1, 2}}, {FieldID: 2, LogIDs: []int64{1, 2}}}
139139
fields, size, err := ct.listInsertLogByAPI(context.Background(), dir, binlogs)
140140
assert.NoError(t, err)
141141
assert.Equal(t, int64(10), size)
@@ -165,7 +165,7 @@ func TestCollectionTask_listDeltaLogByAPI(t *testing.T) {
165165
ct.milvusStorage = newMockStorage(t, dir, objs)
166166
ct.milvusRootPath = "base"
167167

168-
binlogs := []client.BinlogInfo{{FieldID: 1, LogIDs: []int64{1, 2}}}
168+
binlogs := []milvus.BinlogInfo{{FieldID: 1, LogIDs: []int64{1, 2}}}
169169
fields, size, err := ct.listDeltaLogByAPI(context.Background(), dir, binlogs)
170170
assert.NoError(t, err)
171171
assert.Equal(t, int64(3), size)

core/backup/database.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/zilliztech/milvus-backup/core/client"
7+
"github.com/zilliztech/milvus-backup/core/client/milvus"
88
"github.com/zilliztech/milvus-backup/core/meta"
99
"github.com/zilliztech/milvus-backup/core/pbconv"
1010
"github.com/zilliztech/milvus-backup/core/proto/backuppb"
@@ -16,10 +16,10 @@ type DatabaseTask struct {
1616
dbName string
1717

1818
meta *meta.MetaManager
19-
grpc client.Grpc
19+
grpc milvus.Grpc
2020
}
2121

22-
func NewDatabaseTask(backupID, dbName string, grpc client.Grpc, meta *meta.MetaManager) *DatabaseTask {
22+
func NewDatabaseTask(backupID, dbName string, grpc milvus.Grpc, meta *meta.MetaManager) *DatabaseTask {
2323
return &DatabaseTask{backupID: backupID, dbName: dbName, meta: meta, grpc: grpc}
2424
}
2525

@@ -28,7 +28,7 @@ func (dt *DatabaseTask) Execute(ctx context.Context) error {
2828
var dbID int64
2929

3030
// if milvus does not support database, skip describe database
31-
if dt.grpc.HasFeature(client.DescribeDatabase) {
31+
if dt.grpc.HasFeature(milvus.DescribeDatabase) {
3232
resp, err := dt.grpc.DescribeDatabase(ctx, dt.dbName)
3333
if err != nil {
3434
return fmt.Errorf("backup: describe database %s: %w", dt.dbName, err)

core/backup/database_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/mock"
1111

12-
"github.com/zilliztech/milvus-backup/core/client"
12+
"github.com/zilliztech/milvus-backup/core/client/milvus"
1313
"github.com/zilliztech/milvus-backup/core/meta"
1414
"github.com/zilliztech/milvus-backup/core/namespace"
1515
"github.com/zilliztech/milvus-backup/core/proto/backuppb"
1616
)
1717

1818
func TestDatabaseTask_Execute(t *testing.T) {
1919
t.Run("SupportDescribeDatabase", func(t *testing.T) {
20-
cli := client.NewMockGrpc(t)
20+
cli := milvus.NewMockGrpc(t)
2121

22-
cli.EXPECT().HasFeature(client.DescribeDatabase).Return(true).Once()
22+
cli.EXPECT().HasFeature(milvus.DescribeDatabase).Return(true).Once()
2323
cli.EXPECT().DescribeDatabase(mock.Anything, "db1").Return(&milvuspb.DescribeDatabaseResponse{
2424
DbID: 1,
2525
Properties: []*commonpb.KeyValuePair{
@@ -41,9 +41,9 @@ func TestDatabaseTask_Execute(t *testing.T) {
4141
})
4242

4343
t.Run("NotSupportDescribeDatabase", func(t *testing.T) {
44-
cli := client.NewMockGrpc(t)
44+
cli := milvus.NewMockGrpc(t)
4545

46-
cli.EXPECT().HasFeature(client.DescribeDatabase).Return(false).Once()
46+
cli.EXPECT().HasFeature(milvus.DescribeDatabase).Return(false).Once()
4747

4848
metaMgr := meta.NewMetaManager()
4949
metaMgr.AddBackup(&backuppb.BackupInfo{Id: "backup1"})

core/backup/rbac.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/samber/lo"
99
"go.uber.org/zap"
1010

11-
"github.com/zilliztech/milvus-backup/core/client"
11+
"github.com/zilliztech/milvus-backup/core/client/milvus"
1212
"github.com/zilliztech/milvus-backup/core/meta"
1313
"github.com/zilliztech/milvus-backup/core/proto/backuppb"
1414
"github.com/zilliztech/milvus-backup/internal/log"
@@ -18,12 +18,12 @@ type RBACTask struct {
1818
backupID string
1919
meta *meta.MetaManager
2020

21-
grpcCli client.Grpc
21+
grpcCli milvus.Grpc
2222

2323
logger *zap.Logger
2424
}
2525

26-
func NewRBACTask(backupID string, meta *meta.MetaManager, grpcCli client.Grpc) *RBACTask {
26+
func NewRBACTask(backupID string, meta *meta.MetaManager, grpcCli milvus.Grpc) *RBACTask {
2727
logger := log.L().With(zap.String("backup_id", backupID))
2828
return &RBACTask{
2929
backupID: backupID,

core/backup/rpc_channel_pos.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"go.uber.org/zap"
88

9-
"github.com/zilliztech/milvus-backup/core/client"
9+
"github.com/zilliztech/milvus-backup/core/client/milvus"
1010
"github.com/zilliztech/milvus-backup/core/meta"
1111
"github.com/zilliztech/milvus-backup/internal/log"
1212
)
@@ -15,12 +15,12 @@ type RPCChannelPOSTask struct {
1515
backupID string
1616
rpcChannelName string
1717

18-
grpc client.Grpc
18+
grpc milvus.Grpc
1919
meta *meta.MetaManager
2020
logger *zap.Logger
2121
}
2222

23-
func NewRPCChannelPOSTask(backupID, rpcChannelName string, grpc client.Grpc, meta *meta.MetaManager) *RPCChannelPOSTask {
23+
func NewRPCChannelPOSTask(backupID, rpcChannelName string, grpc milvus.Grpc, meta *meta.MetaManager) *RPCChannelPOSTask {
2424
return &RPCChannelPOSTask{
2525
backupID: backupID,
2626

0 commit comments

Comments
 (0)