2022-09-05 13:29:11 +08:00
|
|
|
package rootcoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
2022-10-22 15:19:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
2022-09-05 13:29:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
|
2022-09-05 13:29:11 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_dropPartitionTask_Prepare(t *testing.T) {
|
|
|
|
t.Run("invalid msg type", func(t *testing.T) {
|
|
|
|
task := &dropPartitionTask{
|
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropCollection},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("drop default partition", func(t *testing.T) {
|
|
|
|
task := &dropPartitionTask{
|
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
2022-12-07 18:01:19 +08:00
|
|
|
PartitionName: Params.CommonCfg.DefaultPartitionName.GetValue(),
|
2022-09-05 13:29:11 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to get collection meta", func(t *testing.T) {
|
|
|
|
core := newTestCore(withInvalidMeta())
|
|
|
|
task := &dropPartitionTask{
|
2022-09-24 12:42:51 +08:00
|
|
|
baseTask: baseTask{core: core},
|
2022-09-05 13:29:11 +08:00
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
Params.InitOnce()
|
|
|
|
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName}
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.GetCollectionByNameFunc = func(ctx context.Context, collectionName string, ts Timestamp) (*model.Collection, error) {
|
|
|
|
return coll.Clone(), nil
|
|
|
|
}
|
|
|
|
core := newTestCore(withMeta(meta))
|
|
|
|
task := &dropPartitionTask{
|
2022-09-24 12:42:51 +08:00
|
|
|
baseTask: baseTask{core: core},
|
2022-09-05 13:29:11 +08:00
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
|
|
|
CollectionName: collectionName,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err := task.Prepare(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, coll.Equal(*task.collMeta))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_dropPartitionTask_Execute(t *testing.T) {
|
|
|
|
t.Run("drop non-existent partition", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{}}
|
|
|
|
task := &dropPartitionTask{
|
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
},
|
|
|
|
collMeta: coll.Clone(),
|
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to expire cache", func(t *testing.T) {
|
2022-10-28 13:25:34 +08:00
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{{PartitionName: partitionName}}}
|
|
|
|
core := newTestCore(withInvalidProxyManager())
|
|
|
|
task := &dropPartitionTask{
|
|
|
|
baseTask: baseTask{core: core},
|
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
},
|
|
|
|
collMeta: coll.Clone(),
|
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.Error(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to change partition state", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{{PartitionName: partitionName}}}
|
|
|
|
core := newTestCore(withValidProxyManager(), withInvalidMeta())
|
|
|
|
task := &dropPartitionTask{
|
2022-09-24 12:42:51 +08:00
|
|
|
baseTask: baseTask{core: core},
|
2022-09-05 13:29:11 +08:00
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
},
|
|
|
|
collMeta: coll.Clone(),
|
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
collectionName := funcutil.GenRandomStr()
|
|
|
|
partitionName := funcutil.GenRandomStr()
|
|
|
|
coll := &model.Collection{Name: collectionName, Partitions: []*model.Partition{{PartitionName: partitionName}}}
|
|
|
|
removePartitionMetaCalled := false
|
|
|
|
removePartitionMetaChan := make(chan struct{}, 1)
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.ChangePartitionStateFunc = func(ctx context.Context, collectionID UniqueID, partitionID UniqueID, state etcdpb.PartitionState, ts Timestamp) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta.RemovePartitionFunc = func(ctx context.Context, collectionID UniqueID, partitionID UniqueID, ts Timestamp) error {
|
|
|
|
removePartitionMetaCalled = true
|
|
|
|
removePartitionMetaChan <- struct{}{}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
gc := newMockGarbageCollector()
|
|
|
|
deletePartitionCalled := false
|
|
|
|
deletePartitionChan := make(chan struct{}, 1)
|
2022-09-21 15:46:51 +08:00
|
|
|
gc.GcPartitionDataFunc = func(ctx context.Context, pChannels []string, coll *model.Partition) (Timestamp, error) {
|
2022-09-05 13:29:11 +08:00
|
|
|
deletePartitionChan <- struct{}{}
|
|
|
|
deletePartitionCalled = true
|
2022-09-21 15:46:51 +08:00
|
|
|
return 0, nil
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
|
|
|
|
2022-09-23 09:36:51 +08:00
|
|
|
core := newTestCore(withValidProxyManager(), withMeta(meta), withGarbageCollector(gc), withDropIndex())
|
2022-09-05 13:29:11 +08:00
|
|
|
|
|
|
|
task := &dropPartitionTask{
|
2022-09-24 12:42:51 +08:00
|
|
|
baseTask: baseTask{core: core},
|
2022-09-05 13:29:11 +08:00
|
|
|
Req: &milvuspb.DropPartitionRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropPartition},
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
},
|
|
|
|
collMeta: coll.Clone(),
|
|
|
|
}
|
|
|
|
err := task.Execute(context.Background())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
// check if redo worked.
|
|
|
|
<-removePartitionMetaChan
|
|
|
|
assert.True(t, removePartitionMetaCalled)
|
|
|
|
<-deletePartitionChan
|
|
|
|
assert.True(t, deletePartitionCalled)
|
|
|
|
})
|
|
|
|
}
|