From 80c0ae3519ab50271d2a3a9fe1e37c2bf10d4bdb Mon Sep 17 00:00:00 2001 From: Patrick Weizhi Xu Date: Mon, 22 Jul 2024 11:29:59 +0800 Subject: [PATCH] feat: [restful v2] add partition key isolation prop (#34710) issue: https://github.com/milvus-io/milvus/issues/34332 Signed-off-by: Patrick Weizhi Xu --- internal/distributed/proxy/httpserver/handler_v2.go | 6 ++++++ .../distributed/proxy/httpserver/handler_v2_test.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/distributed/proxy/httpserver/handler_v2.go b/internal/distributed/proxy/httpserver/handler_v2.go index 9184f322ca..f7a23a1f81 100644 --- a/internal/distributed/proxy/httpserver/handler_v2.go +++ b/internal/distributed/proxy/httpserver/handler_v2.go @@ -1246,6 +1246,12 @@ func (h *HandlersV2) createCollection(ctx context.Context, c *gin.Context, anyRe Value: fmt.Sprintf("%v", httpReq.Params["ttlSeconds"]), }) } + if _, ok := httpReq.Params["partitionKeyIsolation"]; ok { + req.Properties = append(req.Properties, &commonpb.KeyValuePair{ + Key: common.PartitionKeyIsolationKey, + Value: fmt.Sprintf("%v", httpReq.Params["partitionKeyIsolation"]), + }) + } resp, err := wrapperProxy(ctx, c, req, h.checkAuth, false, "/milvus.proto.milvus.MilvusService/CreateCollection", func(reqCtx context.Context, req any) (interface{}, error) { return h.proxy.CreateCollection(reqCtx, req.(*milvuspb.CreateCollectionRequest)) }) diff --git a/internal/distributed/proxy/httpserver/handler_v2_test.go b/internal/distributed/proxy/httpserver/handler_v2_test.go index 710c66424f..1a97ebe7ff 100644 --- a/internal/distributed/proxy/httpserver/handler_v2_test.go +++ b/internal/distributed/proxy/httpserver/handler_v2_test.go @@ -471,7 +471,7 @@ func TestDatabaseWrapper(t *testing.T) { func TestCreateCollection(t *testing.T) { postTestCases := []requestBodyTestCase{} mp := mocks.NewMockProxy(t) - mp.EXPECT().CreateCollection(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(12) + mp.EXPECT().CreateCollection(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(13) mp.EXPECT().CreateIndex(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(6) mp.EXPECT().LoadCollection(mock.Anything, mock.Anything).Return(commonSuccessStatus, nil).Times(6) mp.EXPECT().CreateIndex(mock.Anything, mock.Anything).Return(commonErrorStatus, nil).Twice() @@ -600,6 +600,15 @@ func TestCreateCollection(t *testing.T) { errMsg: "missing required parameters, error: `book_xxx` hasn't defined in schema", errCode: 1802, }) + postTestCases = append(postTestCases, requestBodyTestCase{ + path: path, + requestBody: []byte(`{"collectionName": "` + DefaultCollectionName + `", "schema": { + "fields": [ + {"fieldName": "book_id", "dataType": "Int64", "isPrimary": true, "isPartitionKey": true, "elementTypeParams": {}}, + {"fieldName": "book_intro", "dataType": "FloatVector", "elementTypeParams": {"dim": 2}} + ] + }, "params": {"partitionKeyIsolation": "true"}}`), + }) postTestCases = append(postTestCases, requestBodyTestCase{ path: path, requestBody: []byte(`{"collectionName": "` + DefaultCollectionName + `", "dimension": 2, "metricType": "L2"}`),