Skip to content

Commit

Permalink
enhance: [2.4]alterindex & altercollection supports altering properti…
Browse files Browse the repository at this point in the history
…es (#38111)

enhance :

alterindex delete properties
We have introduced a new parameter deleteKeys to the alterindex
functionality, which allows for the deletion of properties within an
index. This enhancement provides users with the flexibility to manage
index properties more effectively by removing specific keys as needed.
altercollection delete properties
We have introduced a new parameter deleteKeys to the altercollection
functionality, which allows for the deletion of properties within an
collection. This enhancement provides users with the flexibility to
manage collection properties more effectively by removing specific keys
as needed.
3.support altercollectionfield
We currently support modifying the fieldparams of a field in a
collection using altercollectionfield, which only allows changes to the
max-length attribute.
Key Points:

New Parameter - deleteKeys: This new parameter enables the deletion of
specified properties from an index. By passing a list of keys to
deleteKeys, users can remove the corresponding properties from the
index.

Mutual Exclusivity: The deleteKeys parameter cannot be used in
conjunction with the extraParams parameter. Users must choose one
parameter to pass based on their requirement. If deleteKeys is provided,
it indicates an intent to delete properties; if extraParams is provided,
it signifies the addition or update of properties.

issue: #37436
pr: #37437

---------

Signed-off-by: Xianhui.Lin <[email protected]>
  • Loading branch information
JsDove authored Dec 6, 2024
1 parent 51eb254 commit a516475
Show file tree
Hide file tree
Showing 25 changed files with 821 additions and 60 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/klauspost/compress v1.17.9
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.18-0.20241129073142-d8e5b9597772
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.18-0.20241204065031-4466aae60fc2
github.com/minio/minio-go/v7 v7.0.73
github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81
github.com/prometheus/client_golang v1.14.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ github.com/milvus-io/cgosymbolizer v0.0.0-20240722103217-b7dee0e50119 h1:9VXijWu
github.com/milvus-io/cgosymbolizer v0.0.0-20240722103217-b7dee0e50119/go.mod h1:DvXTE/K/RtHehxU8/GtDs4vFtfw64jJ3PaCnFri8CRg=
github.com/milvus-io/gorocksdb v0.0.0-20220624081344-8c5f4212846b h1:TfeY0NxYxZzUfIfYe5qYDBzt4ZYRqzUjTR6CvUzjat8=
github.com/milvus-io/gorocksdb v0.0.0-20220624081344-8c5f4212846b/go.mod h1:iwW+9cWfIzzDseEBCCeDSN5SD16Tidvy8cwQ7ZY8Qj4=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.18-0.20241129073142-d8e5b9597772 h1:HN66VyfkOxDp4AZXMTPxX8c3LkV4RV7srsffZXk3DMs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.18-0.20241129073142-d8e5b9597772/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.18-0.20241204065031-4466aae60fc2 h1:I3lqktgaXm87Lbsj1UmjSttq+APd+b6IdB2GamPB9cg=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.18-0.20241204065031-4466aae60fc2/go.mod h1:/6UT4zZl6awVeXLeE7UGDWZvXj3IWkRsh3mqsn0DiAs=
github.com/milvus-io/milvus-storage/go v0.0.0-20231227072638-ebd0b8e56d70 h1:Z+sp64fmAOxAG7mU0dfVOXvAXlwRB0c8a96rIM5HevI=
github.com/milvus-io/milvus-storage/go v0.0.0-20231227072638-ebd0b8e56d70/go.mod h1:GPETMcTZq1gLY1WA6Na5kiNAKnq8SEMMiVKUZrM3sho=
github.com/milvus-io/pulsar-client-go v0.6.10 h1:eqpJjU+/QX0iIhEo3nhOqMNXL+TyInAs1IAHZCrCM/A=
Expand Down
75 changes: 59 additions & 16 deletions internal/datacoord/index_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,33 @@ func UpdateParams(index *model.Index, from []*commonpb.KeyValuePair, updates []*
})
}

func DeleteParams(index *model.Index, from []*commonpb.KeyValuePair, deletes []string) []*commonpb.KeyValuePair {
params := make(map[string]string)
for _, param := range from {
params[param.GetKey()] = param.GetValue()
}

// delete the params
for _, key := range deletes {
delete(params, key)
}

return lo.MapToSlice(params, func(k string, v string) *commonpb.KeyValuePair {
return &commonpb.KeyValuePair{
Key: k,
Value: v,
}
})
}

func (s *Server) AlterIndex(ctx context.Context, req *indexpb.AlterIndexRequest) (*commonpb.Status, error) {
log := log.Ctx(ctx).With(
zap.Int64("collectionID", req.GetCollectionID()),
zap.String("indexName", req.GetIndexName()),
)
log.Info("received AlterIndex request", zap.Any("params", req.GetParams()))
log.Info("received AlterIndex request",
zap.Any("params", req.GetParams()),
zap.Any("deletekeys", req.GetDeleteKeys()))

if req.IndexName == "" {
return merr.Status(merr.WrapErrParameterInvalidMsg("index name is empty")), nil
Expand All @@ -323,22 +344,44 @@ func (s *Server) AlterIndex(ctx context.Context, req *indexpb.AlterIndexRequest)
return merr.Status(err), nil
}

if len(req.GetDeleteKeys()) > 0 && len(req.GetParams()) > 0 {
return merr.Status(merr.WrapErrParameterInvalidMsg("cannot provide both DeleteKeys and ExtraParams")), nil
}

for _, index := range indexes {
// update user index params
newUserIndexParams := UpdateParams(index, index.UserIndexParams, req.GetParams())
log.Info("alter index user index params",
zap.String("indexName", index.IndexName),
zap.Any("params", newUserIndexParams),
)
index.UserIndexParams = newUserIndexParams

// update index params
newIndexParams := UpdateParams(index, index.IndexParams, req.GetParams())
log.Info("alter index user index params",
zap.String("indexName", index.IndexName),
zap.Any("params", newIndexParams),
)
index.IndexParams = newIndexParams
if len(req.GetParams()) > 0 {
// update user index params
newUserIndexParams := UpdateParams(index, index.UserIndexParams, req.GetParams())
log.Info("alter index user index params",
zap.String("indexName", index.IndexName),
zap.Any("params", newUserIndexParams),
)
index.UserIndexParams = newUserIndexParams

// update index params
newIndexParams := UpdateParams(index, index.IndexParams, req.GetParams())
log.Info("alter index index params",
zap.String("indexName", index.IndexName),
zap.Any("params", newIndexParams),
)
index.IndexParams = newIndexParams
} else if len(req.GetDeleteKeys()) > 0 {
// delete user index params
newUserIndexParams := DeleteParams(index, index.UserIndexParams, req.GetDeleteKeys())
log.Info("alter index user deletekeys",
zap.String("indexName", index.IndexName),
zap.Any("params", newUserIndexParams),
)
index.UserIndexParams = newUserIndexParams

// delete index params
newIndexParams := DeleteParams(index, index.IndexParams, req.GetDeleteKeys())
log.Info("alter index index deletekeys",
zap.String("indexName", index.IndexName),
zap.Any("params", newIndexParams),
)
index.IndexParams = newIndexParams
}

if err := ValidateIndexParams(index); err != nil {
return merr.Status(err), nil
Expand Down
35 changes: 35 additions & 0 deletions internal/datacoord/index_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,41 @@ func TestServer_AlterIndex(t *testing.T) {
req.Params[0].Value = "true"
})

t.Run("delete_params", func(t *testing.T) {
deleteReq := &indexpb.AlterIndexRequest{
CollectionID: collID,
IndexName: indexName,
DeleteKeys: []string{common.MmapEnabledKey},
}
resp, err := s.AlterIndex(ctx, deleteReq)
assert.NoError(t, merr.CheckRPCCall(resp, err))

describeResp, err := s.DescribeIndex(ctx, &indexpb.DescribeIndexRequest{
CollectionID: collID,
IndexName: indexName,
Timestamp: createTS,
})
assert.NoError(t, merr.CheckRPCCall(describeResp, err))
for _, param := range describeResp.IndexInfos[0].GetUserIndexParams() {
assert.NotEqual(t, common.MmapEnabledKey, param.GetKey())
}
})
t.Run("update_and_delete_params", func(t *testing.T) {
updateAndDeleteReq := &indexpb.AlterIndexRequest{
CollectionID: collID,
IndexName: indexName,
Params: []*commonpb.KeyValuePair{
{
Key: common.MmapEnabledKey,
Value: "true",
},
},
DeleteKeys: []string{common.MmapEnabledKey},
}
resp, err := s.AlterIndex(ctx, updateAndDeleteReq)
assert.ErrorIs(t, merr.CheckRPCCall(resp, err), merr.ErrParameterInvalid)
})

t.Run("success", func(t *testing.T) {
resp, err := s.AlterIndex(ctx, req)
assert.NoError(t, merr.CheckRPCCall(resp, err))
Expand Down
4 changes: 4 additions & 0 deletions internal/datacoord/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ func (m *mockRootCoordClient) AlterCollection(ctx context.Context, request *milv
panic("not implemented") // TODO: Implement
}

func (m *mockRootCoordClient) AlterCollectionField(ctx context.Context, request *milvuspb.AlterCollectionFieldRequest, opts ...grpc.CallOption) (*commonpb.Status, error) {
panic("not implemented") // TODO: Implement
}

func (m *mockRootCoordClient) CreatePartition(ctx context.Context, req *milvuspb.CreatePartitionRequest, opts ...grpc.CallOption) (*commonpb.Status, error) {
panic("not implemented") // TODO: Implement
}
Expand Down
4 changes: 4 additions & 0 deletions internal/distributed/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,10 @@ func (s *Server) AlterCollection(ctx context.Context, request *milvuspb.AlterCol
return s.proxy.AlterCollection(ctx, request)
}

func (s *Server) AlterCollectionField(ctx context.Context, request *milvuspb.AlterCollectionFieldRequest) (*commonpb.Status, error) {
return s.proxy.AlterCollectionField(ctx, request)
}

// CreatePartition notifies Proxy to create a partition
func (s *Server) CreatePartition(ctx context.Context, request *milvuspb.CreatePartitionRequest) (*commonpb.Status, error) {
return s.proxy.CreatePartition(ctx, request)
Expand Down
11 changes: 11 additions & 0 deletions internal/distributed/rootcoord/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ func (c *Client) AlterCollection(ctx context.Context, request *milvuspb.AlterCol
})
}

func (c *Client) AlterCollectionField(ctx context.Context, request *milvuspb.AlterCollectionFieldRequest, opts ...grpc.CallOption) (*commonpb.Status, error) {
request = typeutil.Clone(request)
commonpbutil.UpdateMsgBase(
request.GetBase(),
commonpbutil.FillMsgBaseFromClient(paramtable.GetNodeID(), commonpbutil.WithTargetID(c.grpcClient.GetNodeID())),
)
return wrapGrpcCall(ctx, c, func(client rootcoordpb.RootCoordClient) (*commonpb.Status, error) {
return client.AlterCollectionField(ctx, request)
})
}

// CreatePartition create partition
func (c *Client) CreatePartition(ctx context.Context, in *milvuspb.CreatePartitionRequest, opts ...grpc.CallOption) (*commonpb.Status, error) {
in = typeutil.Clone(in)
Expand Down
4 changes: 4 additions & 0 deletions internal/distributed/rootcoord/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ func (s *Server) AlterCollection(ctx context.Context, request *milvuspb.AlterCol
return s.rootCoord.AlterCollection(ctx, request)
}

func (s *Server) AlterCollectionField(ctx context.Context, request *milvuspb.AlterCollectionFieldRequest) (*commonpb.Status, error) {
return s.rootCoord.AlterCollectionField(ctx, request)
}

func (s *Server) RenameCollection(ctx context.Context, request *milvuspb.RenameCollectionRequest) (*commonpb.Status, error) {
return s.rootCoord.RenameCollection(ctx, request)
}
Expand Down
55 changes: 55 additions & 0 deletions internal/mocks/mock_proxy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions internal/mocks/mock_rootcoord.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a516475

Please sign in to comment.