Skip to content

Commit

Permalink
enhance: [2.3] Remove HasCollection & HasPartition grpc call (#651)
Browse files Browse the repository at this point in the history
See also: #650

---------

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia committed Jan 16, 2024
1 parent 9e1483c commit 66ba4c6
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 365 deletions.
32 changes: 0 additions & 32 deletions client/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ func (c *GrpcClient) DropCollection(ctx context.Context, collName string, opts .
if c.Service == nil {
return ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}

req := &milvuspb.DropCollectionRequest{
CollectionName: collName,
Expand Down Expand Up @@ -337,10 +334,6 @@ func (c *GrpcClient) GetCollectionStatistics(ctx context.Context, collName strin
return nil, ErrClientNotReady
}

if err := c.checkCollectionExists(ctx, collName); err != nil {
return nil, err
}

req := &milvuspb.GetCollectionStatisticsRequest{
CollectionName: collName,
}
Expand All @@ -359,10 +352,6 @@ func (c *GrpcClient) ShowCollection(ctx context.Context, collName string) (*enti
if c.Service == nil {
return nil, ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return nil, err
}

req := &milvuspb.ShowCollectionsRequest{
Type: milvuspb.ShowType_InMemory,
CollectionNames: []string{collName},
Expand Down Expand Up @@ -391,10 +380,6 @@ func (c *GrpcClient) RenameCollection(ctx context.Context, collName, newName str
return ErrClientNotReady
}

if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}

req := &milvuspb.RenameCollectionRequest{
OldName: collName,
NewName: newName,
Expand All @@ -412,10 +397,6 @@ func (c *GrpcClient) LoadCollection(ctx context.Context, collName string, async
return ErrClientNotReady
}

if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}

req := &milvuspb.LoadCollectionRequest{
CollectionName: collName,
ReplicaNumber: 1, // default replica number
Expand Down Expand Up @@ -459,9 +440,6 @@ func (c *GrpcClient) ReleaseCollection(ctx context.Context, collName string, opt
if c.Service == nil {
return ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}

req := &milvuspb.ReleaseCollectionRequest{
DbName: "", // reserved
Expand Down Expand Up @@ -525,9 +503,6 @@ func (c *GrpcClient) GetLoadingProgress(ctx context.Context, collName string, pa
if c.Service == nil {
return 0, ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return 0, err
}

req := &milvuspb.GetLoadingProgressRequest{
CollectionName: collName,
Expand All @@ -546,10 +521,6 @@ func (c *GrpcClient) GetLoadState(ctx context.Context, collName string, partitio
if c.Service == nil {
return 0, ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return 0, err
}

req := &milvuspb.GetLoadStateRequest{
CollectionName: collName,
PartitionNames: partitionNames,
Expand All @@ -567,9 +538,6 @@ func (c *GrpcClient) AlterCollection(ctx context.Context, collName string, attrs
if c.Service == nil {
return ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}

if len(attrs) == 0 {
return errors.New("no collection attribute provided")
Expand Down
49 changes: 0 additions & 49 deletions client/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,6 @@ func (s *CollectionSuite) TestRenameCollection() {
s.NoError(err)
})

s.Run("coll_not_exist", func() {
defer s.resetMock()

newCollName := fmt.Sprintf("new_%s", randStr(6))

s.mock.EXPECT().HasCollection(mock.Anything, &milvuspb.HasCollectionRequest{CollectionName: testCollectionName}).Return(&milvuspb.BoolResponse{Status: &commonpb.Status{}, Value: false}, nil)

err := c.RenameCollection(ctx, testCollectionName, newCollName)
s.Error(err)
})

s.Run("rename_failed", func() {
defer s.resetMock()

Expand Down Expand Up @@ -451,19 +440,6 @@ func (s *CollectionSuite) TestAlterCollection() {
s.NoError(err)
})

s.Run("collection_not_exist", func() {
defer s.resetMock()

s.mock.EXPECT().HasCollection(mock.Anything, mock.AnythingOfType("*milvuspb.HasCollectionRequest")).
Return(&milvuspb.BoolResponse{
Status: &commonpb.Status{},
Value: false,
}, nil)

err := c.AlterCollection(ctx, testCollectionName, entity.CollectionTTL(100000))
s.Error(err)
})

s.Run("no_attributes", func() {
defer s.resetMock()

Expand Down Expand Up @@ -562,26 +538,6 @@ func (s *CollectionSuite) TestLoadCollection() {
s.NoError(err)
})

s.Run("has_collection_failure", func() {
s.Run("return_false", func() {
defer s.resetMock()
s.mock.EXPECT().HasCollection(mock.Anything, &milvuspb.HasCollectionRequest{CollectionName: testCollectionName}).
Return(&milvuspb.BoolResponse{Status: &commonpb.Status{}, Value: false}, nil)

err := c.LoadCollection(ctx, testCollectionName, true)
s.Error(err)
})

s.Run("return_error", func() {
defer s.resetMock()
s.mock.EXPECT().HasCollection(mock.Anything, &milvuspb.HasCollectionRequest{CollectionName: testCollectionName}).
Return(nil, errors.New("mock error"))

err := c.LoadCollection(ctx, testCollectionName, true)
s.Error(err)
})
})

s.Run("load_collection_failure", func() {
s.Run("failure_status", func() {
defer s.resetMock()
Expand Down Expand Up @@ -874,11 +830,6 @@ func TestGrpcClientGetReplicas(t *testing.T) {
assert.Equal(t, 2, len(groups[0].ShardReplicas))
})

t.Run("get replicas invalid name", func(t *testing.T) {
_, err := c.GetReplicas(ctx, "invalid name")
assert.Error(t, err)
})

t.Run("get replicas grpc error", func(t *testing.T) {
mockServer.SetInjection(MGetReplicas, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &milvuspb.GetReplicasResponse{}, errors.New("mockServer.d grpc error")
Expand Down
9 changes: 0 additions & 9 deletions client/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,6 @@ func (c *GrpcClient) CalcDistance(ctx context.Context, collName string, partitio
return nil, errors.New("operators cannot be nil")
}

// check meta
if err := c.checkCollectionExists(ctx, collName); err != nil {
return nil, err
}
for _, partition := range partitions {
if err := c.checkPartitionExists(ctx, collName, partition); err != nil {
return nil, err
}
}
if err := c.checkCollField(ctx, collName, opLeft.Name(), isVectorField); err != nil {
return nil, err
}
Expand Down
23 changes: 1 addition & 22 deletions client/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,8 @@ func TestGrpcDeleteByPks(t *testing.T) {
mockServer.SetInjection(MHasPartition, hasPartitionInjection(t, testCollectionName, false, partName))
defer mockServer.DelInjection(MHasPartition)

// non-exist collection
err := c.DeleteByPks(ctx, "non-exists-collection", "", entity.NewColumnInt64("pk", []int64{}))
assert.Error(t, err)

// non-exist parition
err = c.DeleteByPks(ctx, testCollectionName, "non-exists-part", entity.NewColumnInt64("pk", []int64{}))
assert.Error(t, err)

// zero length pk
err = c.DeleteByPks(ctx, testCollectionName, "", entity.NewColumnInt64(testPrimaryField, []int64{}))
err := c.DeleteByPks(ctx, testCollectionName, "", entity.NewColumnInt64(testPrimaryField, []int64{}))
assert.Error(t, err)

// string pk field
Expand Down Expand Up @@ -299,19 +291,6 @@ func TestGrpcDelete(t *testing.T) {
assert.NoError(t, err)
})

t.Run("Bad request deletes", func(t *testing.T) {
partName := "testPart"
mockServer.SetInjection(MHasPartition, hasPartitionInjection(t, testCollectionName, false, partName))
defer mockServer.DelInjection(MHasPartition)

// non-exist collection
err := c.Delete(ctx, "non-exists-collection", "", "")
assert.Error(t, err)

// non-exist parition
err = c.Delete(ctx, testCollectionName, "non-exists-part", "")
assert.Error(t, err)
})
t.Run("delete services fail", func(t *testing.T) {
mockServer.SetInjection(MDelete, func(_ context.Context, raw proto.Message) (proto.Message, error) {
resp := &milvuspb.MutationResult{}
Expand Down
53 changes: 4 additions & 49 deletions client/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ func (c *GrpcClient) Insert(ctx context.Context, collName string, partitionName
if c.Service == nil {
return nil, ErrClientNotReady
}
// 1. validation for all input params
// collection
if err := c.checkCollectionExists(ctx, collName); err != nil {
return nil, err
}
if partitionName != "" {
err := c.checkPartitionExists(ctx, collName, partitionName)
if err != nil {
return nil, err
}
}

// fields
var rowSize int
coll, err := c.DescribeCollection(ctx, collName)
Expand Down Expand Up @@ -201,9 +191,7 @@ func (c *GrpcClient) FlushV2(ctx context.Context, collName string, async bool, o
if c.Service == nil {
return nil, nil, 0, ErrClientNotReady
}
if err := c.checkCollectionExists(ctx, collName); err != nil {
return nil, nil, 0, err
}

req := &milvuspb.FlushRequest{
DbName: "", // reserved,
CollectionNames: []string{collName},
Expand Down Expand Up @@ -252,21 +240,11 @@ func (c *GrpcClient) DeleteByPks(ctx context.Context, collName string, partition
return ErrClientNotReady
}

// check collection name
if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}
coll, err := c.DescribeCollection(ctx, collName)
if err != nil {
return err
}
// check partition name
if partitionName != "" {
err := c.checkPartitionExists(ctx, collName, partitionName)
if err != nil {
return err
}
}

// check primary keys
if ids.Len() == 0 {
return errors.New("ids len must not be zero")
Expand Down Expand Up @@ -308,19 +286,6 @@ func (c *GrpcClient) Delete(ctx context.Context, collName string, partitionName
return ErrClientNotReady
}

// check collection name
if err := c.checkCollectionExists(ctx, collName); err != nil {
return err
}

// check partition name
if partitionName != "" {
err := c.checkPartitionExists(ctx, collName, partitionName)
if err != nil {
return err
}
}

req := &milvuspb.DeleteRequest{
DbName: "",
CollectionName: collName,
Expand Down Expand Up @@ -348,17 +313,7 @@ func (c *GrpcClient) Upsert(ctx context.Context, collName string, partitionName
if c.Service == nil {
return nil, ErrClientNotReady
}
// 1. validation for all input params
// collection
if err := c.checkCollectionExists(ctx, collName); err != nil {
return nil, err
}
if partitionName != "" {
err := c.checkPartitionExists(ctx, collName, partitionName)
if err != nil {
return nil, err
}
}

// fields
var rowSize int
coll, err := c.DescribeCollection(ctx, collName)
Expand Down
16 changes: 0 additions & 16 deletions client/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ func (s *InsertSuite) TestInsertFail() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

s.Run("collection_not_exist", func() {
defer s.resetMock()
s.setupHasCollection()
_, err := c.Insert(ctx, testCollectionName, "")
s.Error(err)
})

s.Run("partition_not_exist", func() {
defer s.resetMock()
s.setupHasCollection(testCollectionName)
s.setupHasPartition(testCollectionName)

_, err := c.Insert(ctx, testCollectionName, "partition_name")
s.Error(err)
})

s.Run("field_not_exist", func() {
defer s.resetMock()
s.setupHasCollection(testCollectionName)
Expand Down
Loading

0 comments on commit 66ba4c6

Please sign in to comment.