Skip to content

Commit

Permalink
feat: support alter index
Browse files Browse the repository at this point in the history
support to enable/disable index mmap mode by altering index

Signed-off-by: yah01 <[email protected]>
  • Loading branch information
yah01 committed Jan 5, 2024
1 parent abdee17 commit bf7ac34
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
18 changes: 9 additions & 9 deletions client/client_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1008,15 +1017,6 @@ func (m *MockServer) Upsert(ctx context.Context, req *milvuspb.UpsertRequest) (*
return &milvuspb.MutationResult{Status: s}, err
}

func (m *MockServer) AlterIndex(ctx context.Context, req *milvuspb.AlterIndexRequest) (*commonpb.Status, error) {
f := m.GetInjection(MUpsert)
if f != nil {
r, err := f(ctx, req)
return r.(*commonpb.Status), err
}
return SuccessStatus()
}

func (m *MockServer) SearchV2(ctx context.Context, req *milvuspb.SearchRequestV2) (*milvuspb.SearchResults, error) {
f := m.GetInjection(MUpsert)
if f != nil {
Expand Down
38 changes: 38 additions & 0 deletions client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ package client
import (
"context"
"fmt"
"strconv"
"time"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"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
Expand Down Expand Up @@ -58,6 +63,7 @@ type indexDef struct {
name string
fieldName string
collectionName string
params []*commonpb.KeyValuePair
MsgBase *commonpb.MsgBase
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down

0 comments on commit bf7ac34

Please sign in to comment.