From 20b22800cdb2c994e72d071ef78612d53f3cb410 Mon Sep 17 00:00:00 2001 From: yah01 Date: Wed, 6 Dec 2023 11:57:46 +0800 Subject: [PATCH] feat: support alter index support to enable/disable index mmap mode by altering index Signed-off-by: yah01 --- client/client_mock_test.go | 9 +++++++++ client/index.go | 38 ++++++++++++++++++++++++++++++++++++++ go.mod | 1 - go.sum | 6 ------ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/client/client_mock_test.go b/client/client_mock_test.go index f2a71e97c..2d6947987 100644 --- a/client/client_mock_test.go +++ b/client/client_mock_test.go @@ -554,6 +554,15 @@ func (m *MockServer) CreateIndex(ctx context.Context, req *milvuspb.CreateIndexR return SuccessStatus() } +func (m *MockServer) AlterIndex(ctx context.Context, req *milvuspb.AlterIndexRequest) (*commonpb.Status, error) { + f := m.GetInjection(MAlterIndex) + if f != nil { + r, err := f(ctx, req) + return r.(*commonpb.Status), err + } + return SuccessStatus() +} + func (m *MockServer) DescribeIndex(ctx context.Context, req *milvuspb.DescribeIndexRequest) (*milvuspb.DescribeIndexResponse, error) { f := m.GetInjection(MDescribeIndex) if f != nil { diff --git a/client/index.go b/client/index.go index e6bbe6587..780cb6550 100644 --- a/client/index.go +++ b/client/index.go @@ -14,6 +14,7 @@ package client import ( "context" "fmt" + "strconv" "time" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -21,6 +22,10 @@ import ( "github.com/milvus-io/milvus-sdk-go/v2/entity" ) +const ( + mmapKey = "mmap.enabled" +) + func (c *GrpcClient) checkCollField(ctx context.Context, collName string, fieldName string, filters ...func(string, string, *entity.Field) error) error { if err := c.checkCollectionExists(ctx, collName); err != nil { return err @@ -58,6 +63,7 @@ type indexDef struct { name string fieldName string collectionName string + params []*commonpb.KeyValuePair MsgBase *commonpb.MsgBase } @@ -78,6 +84,15 @@ func WithIndexMsgBase(msgBase *commonpb.MsgBase) IndexOption { } } +func WithMmap(enabled bool) IndexOption { + return func(id *indexDef) { + id.params = append(id.params, &commonpb.KeyValuePair{ + Key: mmapKey, + Value: strconv.FormatBool(enabled), + }) + } +} + func getIndexDef(opts ...IndexOption) indexDef { idxDef := indexDef{} for _, opt := range opts { @@ -138,6 +153,29 @@ func (c *GrpcClient) CreateIndex(ctx context.Context, collName string, fieldName return nil } +// AlterIndex modifies the index params +func (c *GrpcClient) AlterIndex(ctx context.Context, collName string, indexName string, opts ...IndexOption) error { + if c.Service == nil { + return ErrClientNotReady + } + + idxDef := getIndexDef(opts...) + + req := &milvuspb.AlterIndexRequest{ + Base: idxDef.MsgBase, + DbName: "", // reserved + CollectionName: collName, + IndexName: indexName, + ExtraParams: idxDef.params, + } + + resp, err := c.Service.AlterIndex(ctx, req) + if err != nil { + return err + } + return handleRespStatus(resp) +} + // DescribeIndex describe index func (c *GrpcClient) DescribeIndex(ctx context.Context, collName string, fieldName string, opts ...IndexOption) ([]entity.Index, error) { if c.Service == nil { diff --git a/go.mod b/go.mod index d46866cde..c540c693c 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/getsentry/sentry-go v0.12.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/klauspost/compress v1.16.7 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index d6c075f29..fa3e7ab3f 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,6 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= -github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -159,10 +157,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= -github.com/milvus-io/milvus-proto/go-api/v2 v2.3.2 h1:tBcKiEUcX6i3MaFYvMJO1F7R6fIoeLFkg1kSGE1Tvpk= -github.com/milvus-io/milvus-proto/go-api/v2 v2.3.2/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= -github.com/milvus-io/milvus-proto/go-api/v2 v2.3.3 h1:j6Ru7Lq421Ukp+XH8I+ny7dsVF2rLDLLoWpuFgoDZLM= -github.com/milvus-io/milvus-proto/go-api/v2 v2.3.3/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4 h1:HtNGcUb52ojnl+zDAZMmbHyVaTdBjzuCnnBHpb675TU= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=