2022-12-30 14:17:32 +08:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
2023-04-11 11:00:31 +08:00
|
|
|
"context"
|
2023-11-01 11:26:16 +08:00
|
|
|
"fmt"
|
2022-12-30 14:17:32 +08:00
|
|
|
"testing"
|
|
|
|
|
2023-08-30 14:47:00 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2022-12-30 14:17:32 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-06-25 17:20:43 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2023-09-26 09:57:25 +08:00
|
|
|
"google.golang.org/grpc"
|
2022-12-30 14:17:32 +08:00
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-09-12 10:19:17 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
|
|
|
"github.com/milvus-io/milvus/internal/mocks"
|
|
|
|
"github.com/milvus-io/milvus/internal/parser/planparserv2"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/planpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/streamrpc"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2023-04-11 11:00:31 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream"
|
2023-09-12 10:19:17 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2022-12-30 14:17:32 +08:00
|
|
|
)
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
func Test_getPrimaryKeysFromPlan(t *testing.T) {
|
2023-09-12 10:19:17 +08:00
|
|
|
schema := &schemapb.CollectionSchema{
|
|
|
|
Name: "test_delete",
|
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID,
|
|
|
|
Name: "pk",
|
|
|
|
IsPrimaryKey: true,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
2022-12-30 14:17:32 +08:00
|
|
|
},
|
2023-09-12 10:19:17 +08:00
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID + 1,
|
|
|
|
Name: "non_pk",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
t.Run("delelte with complex pk expr", func(t *testing.T) {
|
|
|
|
expr := "pk < 4"
|
|
|
|
plan, err := planparserv2.CreateRetrievePlan(schema, expr)
|
|
|
|
assert.NoError(t, err)
|
2023-12-26 19:52:48 +08:00
|
|
|
isSimple, _, _ := getPrimaryKeysFromPlan(schema, plan)
|
2023-09-12 10:19:17 +08:00
|
|
|
assert.False(t, isSimple)
|
|
|
|
})
|
2022-12-30 14:17:32 +08:00
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
t.Run("delete with no-pk field expr", func(t *testing.T) {
|
2023-12-26 19:52:48 +08:00
|
|
|
expr := "non_pk == 1"
|
2023-09-12 10:19:17 +08:00
|
|
|
plan, err := planparserv2.CreateRetrievePlan(schema, expr)
|
|
|
|
assert.NoError(t, err)
|
2023-12-26 19:52:48 +08:00
|
|
|
isSimple, _, _ := getPrimaryKeysFromPlan(schema, plan)
|
2023-09-12 10:19:17 +08:00
|
|
|
assert.False(t, isSimple)
|
|
|
|
})
|
2022-12-30 14:17:32 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
t.Run("delete with simple term expr", func(t *testing.T) {
|
2023-09-12 10:19:17 +08:00
|
|
|
expr := "pk in [1, 2, 3]"
|
|
|
|
plan, err := planparserv2.CreateRetrievePlan(schema, expr)
|
|
|
|
assert.NoError(t, err)
|
2023-12-26 19:52:48 +08:00
|
|
|
isSimple, _, rowNum := getPrimaryKeysFromPlan(schema, plan)
|
2023-09-12 10:19:17 +08:00
|
|
|
assert.True(t, isSimple)
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Equal(t, int64(3), rowNum)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete failed with simple term expr", func(t *testing.T) {
|
|
|
|
expr := "pk in [1, 2, 3]"
|
|
|
|
plan, err := planparserv2.CreateRetrievePlan(schema, expr)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
termExpr := plan.Node.(*planpb.PlanNode_Query).Query.Predicates.Expr.(*planpb.Expr_TermExpr)
|
|
|
|
termExpr.TermExpr.ColumnInfo.DataType = -1
|
|
|
|
|
|
|
|
isSimple, _, _ := getPrimaryKeysFromPlan(schema, plan)
|
|
|
|
assert.False(t, isSimple)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete with simple equal expr", func(t *testing.T) {
|
|
|
|
expr := "pk == 1"
|
|
|
|
plan, err := planparserv2.CreateRetrievePlan(schema, expr)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
isSimple, _, rowNum := getPrimaryKeysFromPlan(schema, plan)
|
|
|
|
assert.True(t, isSimple)
|
|
|
|
assert.Equal(t, int64(1), rowNum)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete failed with simple equal expr", func(t *testing.T) {
|
|
|
|
expr := "pk == 1"
|
|
|
|
plan, err := planparserv2.CreateRetrievePlan(schema, expr)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
unaryRangeExpr := plan.Node.(*planpb.PlanNode_Query).Query.Predicates.Expr.(*planpb.Expr_UnaryRangeExpr)
|
|
|
|
unaryRangeExpr.UnaryRangeExpr.ColumnInfo.DataType = -1
|
|
|
|
|
|
|
|
isSimple, _, _ := getPrimaryKeysFromPlan(schema, plan)
|
|
|
|
assert.False(t, isSimple)
|
2022-12-30 14:17:32 +08:00
|
|
|
})
|
|
|
|
}
|
2023-04-11 11:00:31 +08:00
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
func TestDeleteTask_GetChannels(t *testing.T) {
|
|
|
|
collectionID := UniqueID(0)
|
|
|
|
collectionName := "col-0"
|
|
|
|
channels := []pChan{"mock-chan-0", "mock-chan-1"}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(collectionID, nil)
|
|
|
|
globalMetaCache = cache
|
2023-09-25 10:31:26 +08:00
|
|
|
chMgr := NewMockChannelsMgr(t)
|
|
|
|
chMgr.EXPECT().getChannels(mock.Anything).Return(channels, nil)
|
2023-09-12 10:19:17 +08:00
|
|
|
dt := deleteTask{
|
|
|
|
ctx: context.Background(),
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
},
|
|
|
|
chMgr: chMgr,
|
|
|
|
}
|
|
|
|
err := dt.setChannels()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
resChannels := dt.getChannels()
|
|
|
|
assert.ElementsMatch(t, channels, resChannels)
|
|
|
|
assert.ElementsMatch(t, channels, dt.pChannels)
|
|
|
|
}
|
2023-08-30 14:47:00 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
func TestDeleteTask_Execute(t *testing.T) {
|
|
|
|
collectionName := "test_delete"
|
|
|
|
collectionID := int64(111)
|
|
|
|
partitionName := "default"
|
|
|
|
partitionID := int64(222)
|
|
|
|
channels := []string{"test_channel"}
|
|
|
|
dbName := "test_1"
|
|
|
|
pk := &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{IntId: &schemapb.LongArray{Data: []int64{1, 2}}},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("empty expr", func(t *testing.T) {
|
|
|
|
dt := deleteTask{}
|
|
|
|
assert.Error(t, dt.Execute(context.Background()))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get channel failed", func(t *testing.T) {
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
|
|
|
dt := deleteTask{
|
|
|
|
chMgr: mockMgr,
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
Expr: "pk in [1,2]",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(nil, errors.New("mock error"))
|
|
|
|
assert.Error(t, dt.Execute(context.Background()))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("alloc failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
|
|
|
allocator, err := allocator.NewIDAllocator(ctx, rc, paramtable.GetNodeID())
|
|
|
|
assert.NoError(t, err)
|
|
|
|
allocator.Close()
|
|
|
|
|
|
|
|
dt := deleteTask{
|
|
|
|
chMgr: mockMgr,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
idAllocator: allocator,
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "pk in [1,2]",
|
|
|
|
},
|
|
|
|
primaryKeys: pk,
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
|
|
|
|
|
|
|
assert.Error(t, dt.Execute(context.Background()))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("delete produce failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
|
|
|
rc.EXPECT().AllocID(mock.Anything, mock.Anything).Return(
|
|
|
|
&rootcoordpb.AllocIDResponse{
|
|
|
|
Status: merr.Success(),
|
|
|
|
ID: 0,
|
|
|
|
Count: 1,
|
|
|
|
}, nil)
|
|
|
|
allocator, err := allocator.NewIDAllocator(ctx, rc, paramtable.GetNodeID())
|
|
|
|
allocator.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dt := deleteTask{
|
|
|
|
chMgr: mockMgr,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
idAllocator: allocator,
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "pk in [1,2]",
|
|
|
|
},
|
|
|
|
primaryKeys: pk,
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
|
|
|
stream.EXPECT().Produce(mock.Anything).Return(errors.New("mock error"))
|
|
|
|
assert.Error(t, dt.Execute(context.Background()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteRunner_Init(t *testing.T) {
|
|
|
|
collectionName := "test_delete"
|
|
|
|
collectionID := int64(111)
|
|
|
|
partitionName := "default"
|
|
|
|
partitionID := int64(222)
|
|
|
|
// channels := []string{"test_channel"}
|
|
|
|
dbName := "test_1"
|
|
|
|
|
2024-01-04 17:28:46 +08:00
|
|
|
collSchema := &schemapb.CollectionSchema{
|
2023-12-26 19:52:48 +08:00
|
|
|
Name: collectionName,
|
2023-09-12 10:19:17 +08:00
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID,
|
|
|
|
Name: "pk",
|
|
|
|
IsPrimaryKey: true,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
2023-08-30 14:47:00 +08:00
|
|
|
},
|
2023-09-12 10:19:17 +08:00
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID + 1,
|
|
|
|
Name: "non_pk",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-01-04 17:28:46 +08:00
|
|
|
schema := newSchemaInfo(collSchema)
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
t.Run("empty collection name", func(t *testing.T) {
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{}
|
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
2023-08-30 14:47:00 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("fail to get collection id", func(t *testing.T) {
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
2023-09-12 10:19:17 +08:00
|
|
|
req: &milvuspb.DeleteRequest{
|
2023-12-26 19:52:48 +08:00
|
|
|
CollectionName: collectionName,
|
2023-09-21 09:45:27 +08:00
|
|
|
},
|
|
|
|
}
|
2023-08-30 14:47:00 +08:00
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(int64(0), errors.New("mock GetCollectionID err"))
|
|
|
|
globalMetaCache = cache
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
2023-08-30 14:47:00 +08:00
|
|
|
})
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
t.Run("fail get collection schema", func(t *testing.T) {
|
|
|
|
dr := deleteRunner{req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
DbName: dbName,
|
2023-08-30 14:47:00 +08:00
|
|
|
}}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
2023-12-26 19:52:48 +08:00
|
|
|
).Return(collectionID, nil)
|
2023-08-30 14:47:00 +08:00
|
|
|
cache.On("GetCollectionSchema",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(nil, errors.New("mock GetCollectionSchema err"))
|
|
|
|
|
|
|
|
globalMetaCache = cache
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
2023-08-30 14:47:00 +08:00
|
|
|
})
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
t.Run("partition key mode but delete with partition name", func(t *testing.T) {
|
|
|
|
dr := deleteRunner{req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
DbName: dbName,
|
|
|
|
PartitionName: partitionName,
|
2023-08-30 14:47:00 +08:00
|
|
|
}}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
2023-12-26 19:52:48 +08:00
|
|
|
).Return(collectionID, nil)
|
2023-08-30 14:47:00 +08:00
|
|
|
cache.On("GetCollectionSchema",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
2024-01-04 17:28:46 +08:00
|
|
|
).Return(newSchemaInfo(&schemapb.CollectionSchema{
|
2023-12-26 19:52:48 +08:00
|
|
|
Name: collectionName,
|
2023-08-30 14:47:00 +08:00
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID,
|
|
|
|
Name: "pk",
|
|
|
|
IsPrimaryKey: true,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
IsPartitionKey: true,
|
|
|
|
},
|
|
|
|
},
|
2024-01-04 17:28:46 +08:00
|
|
|
}), nil)
|
2023-08-30 14:47:00 +08:00
|
|
|
|
|
|
|
globalMetaCache = cache
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
2023-08-30 14:47:00 +08:00
|
|
|
})
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
t.Run("invalid partition name", func(t *testing.T) {
|
|
|
|
dr := deleteRunner{
|
2023-09-12 10:19:17 +08:00
|
|
|
req: &milvuspb.DeleteRequest{
|
2023-12-26 19:52:48 +08:00
|
|
|
CollectionName: collectionName,
|
|
|
|
DbName: dbName,
|
|
|
|
PartitionName: "???",
|
2023-09-12 10:19:17 +08:00
|
|
|
Expr: "non_pk in [1, 2, 3]",
|
2023-08-30 14:47:00 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(int64(10000), nil)
|
|
|
|
cache.On("GetCollectionSchema",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(schema, nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
|
|
|
|
globalMetaCache = cache
|
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get partition id failed", func(t *testing.T) {
|
|
|
|
dr := deleteRunner{
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
DbName: dbName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
Expr: "non_pk in [1, 2, 3]",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(collectionID, nil)
|
|
|
|
cache.On("GetCollectionSchema",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(schema, nil)
|
2023-08-30 14:47:00 +08:00
|
|
|
cache.On("GetPartitionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(int64(0), errors.New("mock GetPartitionID err"))
|
|
|
|
|
|
|
|
globalMetaCache = cache
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
|
|
|
})
|
2023-08-30 14:47:00 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
t.Run("get vchannel failed", func(t *testing.T) {
|
|
|
|
chMgr := NewMockChannelsMgr(t)
|
|
|
|
dr := deleteRunner{
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
DbName: dbName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
Expr: "non_pk in [1, 2, 3]",
|
|
|
|
},
|
|
|
|
chMgr: chMgr,
|
|
|
|
}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(collectionID, nil)
|
|
|
|
cache.On("GetCollectionSchema",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(schema, nil)
|
2023-08-30 14:47:00 +08:00
|
|
|
cache.On("GetPartitionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
2023-12-26 19:52:48 +08:00
|
|
|
).Return(partitionID, nil)
|
|
|
|
chMgr.On("getVChannels", mock.Anything).Return(nil, fmt.Errorf("mock error"))
|
|
|
|
|
|
|
|
globalMetaCache = cache
|
|
|
|
assert.Error(t, dr.Init(context.Background()))
|
2023-08-30 14:47:00 +08:00
|
|
|
})
|
2023-04-11 11:00:31 +08:00
|
|
|
}
|
2023-09-12 10:19:17 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
func TestDeleteRunner_Run(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
collectionName := "test_delete"
|
|
|
|
collectionID := int64(111)
|
|
|
|
partitionName := "default"
|
|
|
|
partitionID := int64(222)
|
|
|
|
channels := []string{"test_channel"}
|
|
|
|
dbName := "test_1"
|
2023-12-26 19:52:48 +08:00
|
|
|
tsoAllocator := &mockTsoAllocator{}
|
|
|
|
idAllocator := &mockIDAllocatorInterface{}
|
|
|
|
|
|
|
|
queue, err := newTaskScheduler(ctx, tsoAllocator, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
queue.Start()
|
|
|
|
defer queue.Close()
|
2023-09-12 10:19:17 +08:00
|
|
|
|
2024-01-04 17:28:46 +08:00
|
|
|
collSchema := &schemapb.CollectionSchema{
|
2023-09-12 10:19:17 +08:00
|
|
|
Name: collectionName,
|
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID,
|
|
|
|
Name: "pk",
|
|
|
|
IsPrimaryKey: true,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID + 1,
|
|
|
|
Name: "non_pk",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-01-04 17:28:46 +08:00
|
|
|
schema := newSchemaInfo(collSchema)
|
2023-09-12 10:19:17 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
metaCache := NewMockCache(t)
|
|
|
|
metaCache.EXPECT().GetCollectionID(mock.Anything, dbName, collectionName).Return(collectionID, nil).Maybe()
|
|
|
|
globalMetaCache = metaCache
|
|
|
|
defer func() {
|
|
|
|
globalMetaCache = nil
|
|
|
|
}()
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
t.Run("create plan failed", func(t *testing.T) {
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
chMgr: mockMgr,
|
2023-09-12 10:19:17 +08:00
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
Expr: "????",
|
|
|
|
},
|
2024-01-04 17:28:46 +08:00
|
|
|
schema: schema,
|
2023-09-12 10:19:17 +08:00
|
|
|
}
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Run(context.Background()))
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
t.Run("simple delete task failed", func(t *testing.T) {
|
2023-09-12 10:19:17 +08:00
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
2023-12-26 19:52:48 +08:00
|
|
|
lb := NewMockLBPolicy(t)
|
2023-09-12 10:19:17 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
chMgr: mockMgr,
|
|
|
|
schema: schema,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
idAllocator: idAllocator,
|
|
|
|
queue: queue.dmQueue,
|
|
|
|
lb: lb,
|
|
|
|
result: &milvuspb.MutationResult{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-12-26 19:52:48 +08:00
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
2023-09-12 10:19:17 +08:00
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
2023-12-26 19:52:48 +08:00
|
|
|
Expr: "pk in [1,2,3]",
|
2023-09-12 10:19:17 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
mockMgr.EXPECT().getChannels(collectionID).Return(channels, nil)
|
|
|
|
stream.EXPECT().Produce(mock.Anything).Return(fmt.Errorf("mock error"))
|
|
|
|
|
|
|
|
assert.Error(t, dr.Run(context.Background()))
|
|
|
|
assert.Equal(t, int64(0), dr.result.DeleteCnt)
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complex delete query rpc failed", func(t *testing.T) {
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
2023-09-26 09:57:25 +08:00
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
2023-09-12 10:19:17 +08:00
|
|
|
lb := NewMockLBPolicy(t)
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
idAllocator: idAllocator,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
queue: queue.dmQueue,
|
|
|
|
chMgr: mockMgr,
|
|
|
|
schema: schema,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
lb: lb,
|
2023-09-12 10:19:17 +08:00
|
|
|
result: &milvuspb.MutationResult{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "pk < 3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
lb.EXPECT().Execute(mock.Anything, mock.Anything).Call.Return(func(ctx context.Context, workload CollectionWorkLoad) error {
|
2024-01-09 11:38:48 +08:00
|
|
|
return workload.exec(ctx, 1, qn, "")
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qn.EXPECT().QueryStream(mock.Anything, mock.Anything).Return(nil, errors.New("mock error"))
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Run(context.Background()))
|
|
|
|
assert.Equal(t, int64(0), dr.result.DeleteCnt)
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complex delete query failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
2023-09-26 09:57:25 +08:00
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
2023-09-12 10:19:17 +08:00
|
|
|
lb := NewMockLBPolicy(t)
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
queue: queue.dmQueue,
|
|
|
|
chMgr: mockMgr,
|
|
|
|
schema: schema,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
idAllocator: idAllocator,
|
|
|
|
lb: lb,
|
2023-09-12 10:19:17 +08:00
|
|
|
result: &milvuspb.MutationResult{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "pk < 3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
mockMgr.EXPECT().getChannels(collectionID).Return(channels, nil)
|
|
|
|
stream.EXPECT().Produce(mock.Anything).Return(nil)
|
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
lb.EXPECT().Execute(mock.Anything, mock.Anything).Call.Return(func(ctx context.Context, workload CollectionWorkLoad) error {
|
2024-01-09 11:38:48 +08:00
|
|
|
return workload.exec(ctx, 1, qn, "")
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qn.EXPECT().QueryStream(mock.Anything, mock.Anything).Call.Return(
|
|
|
|
func(ctx context.Context, in *querypb.QueryRequest, opts ...grpc.CallOption) querypb.QueryNode_QueryStreamClient {
|
2023-09-12 10:19:17 +08:00
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{
|
|
|
|
Data: []int64{0, 1, 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
|
|
|
Status: merr.Status(errors.New("mock error")),
|
|
|
|
})
|
2023-09-26 09:57:25 +08:00
|
|
|
return client
|
|
|
|
}, nil)
|
2023-09-12 10:19:17 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Run(ctx))
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complex delete produce failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
2023-09-26 09:57:25 +08:00
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
2023-09-12 10:19:17 +08:00
|
|
|
lb := NewMockLBPolicy(t)
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
chMgr: mockMgr,
|
|
|
|
queue: queue.dmQueue,
|
|
|
|
schema: schema,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
idAllocator: idAllocator,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
lb: lb,
|
2023-09-12 10:19:17 +08:00
|
|
|
result: &milvuspb.MutationResult{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "pk < 3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
mockMgr.EXPECT().getChannels(collectionID).Return(channels, nil)
|
2023-09-12 10:19:17 +08:00
|
|
|
lb.EXPECT().Execute(mock.Anything, mock.Anything).Call.Return(func(ctx context.Context, workload CollectionWorkLoad) error {
|
2024-01-09 11:38:48 +08:00
|
|
|
return workload.exec(ctx, 1, qn, "")
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qn.EXPECT().QueryStream(mock.Anything, mock.Anything).Call.Return(
|
|
|
|
func(ctx context.Context, in *querypb.QueryRequest, opts ...grpc.CallOption) querypb.QueryNode_QueryStreamClient {
|
2023-09-12 10:19:17 +08:00
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{
|
|
|
|
Data: []int64{0, 1, 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
server.FinishSend(nil)
|
2023-09-26 09:57:25 +08:00
|
|
|
return client
|
|
|
|
}, nil)
|
2023-09-12 10:19:17 +08:00
|
|
|
stream.EXPECT().Produce(mock.Anything).Return(errors.New("mock error"))
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.Error(t, dr.Run(ctx))
|
|
|
|
assert.Equal(t, int64(0), dr.result.DeleteCnt)
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("complex delete success", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
2023-09-26 09:57:25 +08:00
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
2023-09-12 10:19:17 +08:00
|
|
|
lb := NewMockLBPolicy(t)
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
queue: queue.dmQueue,
|
|
|
|
chMgr: mockMgr,
|
|
|
|
schema: schema,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannels: channels,
|
|
|
|
idAllocator: idAllocator,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
lb: lb,
|
2023-09-12 10:19:17 +08:00
|
|
|
result: &milvuspb.MutationResult{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "pk < 3",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
mockMgr.EXPECT().getChannels(collectionID).Return(channels, nil)
|
2023-09-12 10:19:17 +08:00
|
|
|
lb.EXPECT().Execute(mock.Anything, mock.Anything).Call.Return(func(ctx context.Context, workload CollectionWorkLoad) error {
|
2024-01-09 11:38:48 +08:00
|
|
|
return workload.exec(ctx, 1, qn, "")
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qn.EXPECT().QueryStream(mock.Anything, mock.Anything).Call.Return(
|
|
|
|
func(ctx context.Context, in *querypb.QueryRequest, opts ...grpc.CallOption) querypb.QueryNode_QueryStreamClient {
|
2023-09-12 10:19:17 +08:00
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-12 10:19:17 +08:00
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{
|
|
|
|
Data: []int64{0, 1, 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
server.FinishSend(nil)
|
2023-09-26 09:57:25 +08:00
|
|
|
return client
|
|
|
|
}, nil)
|
2023-09-12 10:19:17 +08:00
|
|
|
stream.EXPECT().Produce(mock.Anything).Return(nil)
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.NoError(t, dr.Run(ctx))
|
|
|
|
assert.Equal(t, int64(3), dr.result.DeleteCnt)
|
2023-09-12 10:19:17 +08:00
|
|
|
})
|
2023-11-01 11:26:16 +08:00
|
|
|
|
|
|
|
schema.Fields[1].IsPartitionKey = true
|
|
|
|
partitionMaps := make(map[string]int64)
|
|
|
|
partitionMaps["test_0"] = 1
|
|
|
|
partitionMaps["test_1"] = 2
|
|
|
|
partitionMaps["test_2"] = 3
|
2023-12-20 10:02:43 +08:00
|
|
|
indexedPartitions := []string{"test_0", "test_1", "test_2"}
|
2023-11-01 11:26:16 +08:00
|
|
|
|
|
|
|
t.Run("complex delete with partitionKey mode success", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
mockMgr := NewMockChannelsMgr(t)
|
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
|
|
|
lb := NewMockLBPolicy(t)
|
|
|
|
|
|
|
|
mockCache := NewMockCache(t)
|
2023-12-26 19:52:48 +08:00
|
|
|
mockCache.EXPECT().GetCollectionID(mock.Anything, dbName, collectionName).Return(collectionID, nil).Maybe()
|
2023-11-01 11:26:16 +08:00
|
|
|
mockCache.EXPECT().GetPartitions(mock.Anything, mock.Anything, mock.Anything).Return(
|
|
|
|
partitionMaps, nil)
|
|
|
|
mockCache.EXPECT().GetCollectionSchema(mock.Anything, mock.Anything, mock.Anything).Return(
|
|
|
|
schema, nil)
|
2023-12-20 10:02:43 +08:00
|
|
|
mockCache.EXPECT().GetPartitionsIndex(mock.Anything, mock.Anything, mock.Anything).
|
|
|
|
Return(indexedPartitions, nil)
|
2023-11-01 11:26:16 +08:00
|
|
|
globalMetaCache = mockCache
|
2023-12-26 19:52:48 +08:00
|
|
|
defer func() { globalMetaCache = metaCache }()
|
2023-11-01 11:26:16 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
|
|
|
queue: queue.dmQueue,
|
2023-11-01 11:26:16 +08:00
|
|
|
chMgr: mockMgr,
|
|
|
|
schema: schema,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: int64(-1),
|
|
|
|
vChannels: channels,
|
2023-12-26 19:52:48 +08:00
|
|
|
idAllocator: idAllocator,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
2023-11-01 11:26:16 +08:00
|
|
|
lb: lb,
|
|
|
|
partitionKeyMode: true,
|
|
|
|
result: &milvuspb.MutationResult{
|
|
|
|
Status: merr.Success(),
|
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: "",
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "non_pk in [2, 3]",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMgr.EXPECT().getOrCreateDmlStream(mock.Anything).Return(stream, nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
mockMgr.EXPECT().getChannels(collectionID).Return(channels, nil)
|
2023-11-01 11:26:16 +08:00
|
|
|
lb.EXPECT().Execute(mock.Anything, mock.Anything).Call.Return(func(ctx context.Context, workload CollectionWorkLoad) error {
|
2024-01-09 11:38:48 +08:00
|
|
|
return workload.exec(ctx, 1, qn, "")
|
2023-11-01 11:26:16 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
qn.EXPECT().QueryStream(mock.Anything, mock.Anything).Call.Return(
|
|
|
|
func(ctx context.Context, in *querypb.QueryRequest, opts ...grpc.CallOption) querypb.QueryNode_QueryStreamClient {
|
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
assert.Greater(t, len(in.Req.PartitionIDs), 0)
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
|
|
|
Status: merr.Success(),
|
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{
|
|
|
|
Data: []int64{0, 1, 2},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
server.FinishSend(nil)
|
|
|
|
return client
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
stream.EXPECT().Produce(mock.Anything).Return(nil)
|
2023-12-26 19:52:48 +08:00
|
|
|
assert.NoError(t, dr.Run(ctx))
|
|
|
|
assert.Equal(t, int64(3), dr.result.DeleteCnt)
|
2023-11-01 11:26:16 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
func TestDeleteRunner_StreamingQueryAndDelteFunc(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2023-11-01 11:26:16 +08:00
|
|
|
collectionName := "test_delete"
|
|
|
|
collectionID := int64(111)
|
|
|
|
channels := []string{"test_channel"}
|
|
|
|
dbName := "test_1"
|
2023-12-26 19:52:48 +08:00
|
|
|
tsoAllocator := &mockTsoAllocator{}
|
|
|
|
idAllocator := &mockIDAllocatorInterface{}
|
|
|
|
|
|
|
|
queue, err := newTaskScheduler(ctx, tsoAllocator, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
queue.Start()
|
|
|
|
defer queue.Close()
|
2023-11-01 11:26:16 +08:00
|
|
|
|
2024-01-04 17:28:46 +08:00
|
|
|
collSchema := &schemapb.CollectionSchema{
|
2023-11-01 11:26:16 +08:00
|
|
|
Name: "test_delete",
|
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID,
|
|
|
|
Name: "pk",
|
|
|
|
IsPrimaryKey: true,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID + 1,
|
|
|
|
Name: "non_pk",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// test partitionKey mode
|
2024-01-04 17:28:46 +08:00
|
|
|
collSchema.Fields[1].IsPartitionKey = true
|
|
|
|
|
|
|
|
schema := newSchemaInfo(collSchema)
|
2023-11-01 11:26:16 +08:00
|
|
|
partitionMaps := make(map[string]int64)
|
|
|
|
partitionMaps["test_0"] = 1
|
|
|
|
partitionMaps["test_1"] = 2
|
|
|
|
partitionMaps["test_2"] = 3
|
2023-12-20 10:02:43 +08:00
|
|
|
indexedPartitions := []string{"test_0", "test_1", "test_2"}
|
2023-11-01 11:26:16 +08:00
|
|
|
t.Run("partitionKey mode parse plan failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
2023-11-01 11:26:16 +08:00
|
|
|
schema: schema,
|
2023-12-26 19:52:48 +08:00
|
|
|
queue: queue.dmQueue,
|
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
idAllocator: idAllocator,
|
2023-11-01 11:26:16 +08:00
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: int64(-1),
|
|
|
|
vChannels: channels,
|
|
|
|
partitionKeyMode: true,
|
|
|
|
result: &milvuspb.MutationResult{
|
|
|
|
Status: merr.Success(),
|
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: "",
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "non_pk in [2, 3]",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
2023-12-26 19:52:48 +08:00
|
|
|
// witho out plan
|
|
|
|
queryFunc := dr.getStreamingQueryAndDelteFunc(nil)
|
2024-01-09 11:38:48 +08:00
|
|
|
assert.Error(t, queryFunc(ctx, 1, qn, ""))
|
2023-11-01 11:26:16 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("partitionKey mode get meta failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
2023-11-01 11:26:16 +08:00
|
|
|
schema: schema,
|
2023-12-26 19:52:48 +08:00
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
idAllocator: idAllocator,
|
2023-11-01 11:26:16 +08:00
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: int64(-1),
|
|
|
|
vChannels: channels,
|
|
|
|
partitionKeyMode: true,
|
|
|
|
result: &milvuspb.MutationResult{
|
|
|
|
Status: merr.Success(),
|
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: "",
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "non_pk in [2, 3]",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
|
|
|
|
|
|
|
mockCache := NewMockCache(t)
|
2023-12-20 10:02:43 +08:00
|
|
|
mockCache.EXPECT().GetPartitionsIndex(mock.Anything, mock.Anything, mock.Anything).
|
|
|
|
Return(nil, fmt.Errorf("mock error"))
|
2023-11-01 11:26:16 +08:00
|
|
|
globalMetaCache = mockCache
|
|
|
|
defer func() { globalMetaCache = nil }()
|
|
|
|
|
2024-01-04 17:28:46 +08:00
|
|
|
plan, err := planparserv2.CreateRetrievePlan(dr.schema.CollectionSchema, dr.req.Expr)
|
2023-11-01 11:26:16 +08:00
|
|
|
assert.NoError(t, err)
|
2023-12-26 19:52:48 +08:00
|
|
|
queryFunc := dr.getStreamingQueryAndDelteFunc(plan)
|
2024-01-09 11:38:48 +08:00
|
|
|
assert.Error(t, queryFunc(ctx, 1, qn, ""))
|
2023-11-01 11:26:16 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("partitionKey mode get partition ID failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := deleteRunner{
|
2023-11-01 11:26:16 +08:00
|
|
|
schema: schema,
|
2023-12-26 19:52:48 +08:00
|
|
|
tsoAllocatorIns: tsoAllocator,
|
|
|
|
idAllocator: idAllocator,
|
2023-11-01 11:26:16 +08:00
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: int64(-1),
|
|
|
|
vChannels: channels,
|
|
|
|
partitionKeyMode: true,
|
|
|
|
result: &milvuspb.MutationResult{
|
|
|
|
Status: merr.Success(),
|
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
req: &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
PartitionName: "",
|
|
|
|
DbName: dbName,
|
|
|
|
Expr: "non_pk in [2, 3]",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
qn := mocks.NewMockQueryNodeClient(t)
|
|
|
|
|
|
|
|
mockCache := NewMockCache(t)
|
2023-12-20 10:02:43 +08:00
|
|
|
mockCache.EXPECT().GetPartitionsIndex(mock.Anything, mock.Anything, mock.Anything).
|
|
|
|
Return(indexedPartitions, nil)
|
2023-11-01 11:26:16 +08:00
|
|
|
mockCache.EXPECT().GetCollectionSchema(mock.Anything, mock.Anything, mock.Anything).Return(
|
|
|
|
schema, nil)
|
|
|
|
mockCache.EXPECT().GetPartitions(mock.Anything, mock.Anything, mock.Anything).Return(
|
|
|
|
nil, fmt.Errorf("mock error"))
|
|
|
|
globalMetaCache = mockCache
|
|
|
|
defer func() { globalMetaCache = nil }()
|
|
|
|
|
2024-01-04 17:28:46 +08:00
|
|
|
plan, err := planparserv2.CreateRetrievePlan(dr.schema.CollectionSchema, dr.req.Expr)
|
2023-11-01 11:26:16 +08:00
|
|
|
assert.NoError(t, err)
|
2023-12-26 19:52:48 +08:00
|
|
|
queryFunc := dr.getStreamingQueryAndDelteFunc(plan)
|
2024-01-09 11:38:48 +08:00
|
|
|
assert.Error(t, queryFunc(ctx, 1, qn, ""))
|
2023-11-01 11:26:16 +08:00
|
|
|
})
|
2023-09-12 10:19:17 +08:00
|
|
|
}
|