enhance: expose DescribeDatabase api in proxy (#32732)

issue: #32707

---------

Signed-off-by: Wei Liu <wei.liu@zilliz.com>
pull/32917/head
wei liu 2024-05-09 22:51:30 +08:00 committed by GitHub
parent efa58ae423
commit c35797c399
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 407 additions and 102 deletions

2
go.mod
View File

@ -26,7 +26,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/klauspost/compress v1.17.7 github.com/klauspost/compress v1.17.7
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.2 github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430035521-259ae1d10016
github.com/minio/minio-go/v7 v7.0.61 github.com/minio/minio-go/v7 v7.0.61
github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81 github.com/pingcap/log v1.1.1-0.20221015072633-39906604fb81
github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_golang v1.14.0

4
go.sum
View File

@ -587,8 +587,8 @@ github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/le
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/milvus-io/gorocksdb v0.0.0-20220624081344-8c5f4212846b h1:TfeY0NxYxZzUfIfYe5qYDBzt4ZYRqzUjTR6CvUzjat8= 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/gorocksdb v0.0.0-20220624081344-8c5f4212846b/go.mod h1:iwW+9cWfIzzDseEBCCeDSN5SD16Tidvy8cwQ7ZY8Qj4=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.2 h1:jgXBS8x8DTriF2pEI0RH/A+eJ8NI1f51iJcdiYEZOBg= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430035521-259ae1d10016 h1:8WV4maXLeGEyJCCYIc1DmZ18H+VFAjMrwXJg5iI2nX4=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.2/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430035521-259ae1d10016/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek=
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 h1:Z+sp64fmAOxAG7mU0dfVOXvAXlwRB0c8a96rIM5HevI=
github.com/milvus-io/milvus-storage/go v0.0.0-20231227072638-ebd0b8e56d70/go.mod h1:GPETMcTZq1gLY1WA6Na5kiNAKnq8SEMMiVKUZrM3sho= 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= github.com/milvus-io/pulsar-client-go v0.6.10 h1:eqpJjU+/QX0iIhEo3nhOqMNXL+TyInAs1IAHZCrCM/A=

View File

@ -1233,3 +1233,7 @@ func (s *Server) AlterDatabase(ctx context.Context, req *milvuspb.AlterDatabaseR
func (s *Server) InvalidateShardLeaderCache(ctx context.Context, req *proxypb.InvalidateShardLeaderCacheRequest) (*commonpb.Status, error) { func (s *Server) InvalidateShardLeaderCache(ctx context.Context, req *proxypb.InvalidateShardLeaderCacheRequest) (*commonpb.Status, error) {
return s.proxy.InvalidateShardLeaderCache(ctx, req) return s.proxy.InvalidateShardLeaderCache(ctx, req)
} }
func (s *Server) DescribeDatabase(ctx context.Context, req *milvuspb.DescribeDatabaseRequest) (*milvuspb.DescribeDatabaseResponse, error) {
return s.proxy.DescribeDatabase(ctx, req)
}

View File

@ -669,6 +669,12 @@ func Test_NewServer(t *testing.T) {
assert.Nil(t, err) assert.Nil(t, err)
}) })
t.Run("DescribeDatabase", func(t *testing.T) {
mockProxy.EXPECT().DescribeDatabase(mock.Anything, mock.Anything).Return(nil, nil)
_, err := server.DescribeDatabase(ctx, nil)
assert.Nil(t, err)
})
t.Run("AllocTimestamp", func(t *testing.T) { t.Run("AllocTimestamp", func(t *testing.T) {
mockProxy.EXPECT().AllocTimestamp(mock.Anything, mock.Anything).Return(nil, nil) mockProxy.EXPECT().AllocTimestamp(mock.Anything, mock.Anything).Return(nil, nil)
_, err := server.AllocTimestamp(ctx, nil) _, err := server.AllocTimestamp(ctx, nil)

View File

@ -1134,6 +1134,61 @@ func (_c *MockProxy_DescribeCollection_Call) RunAndReturn(run func(context.Conte
return _c return _c
} }
// DescribeDatabase provides a mock function with given fields: _a0, _a1
func (_m *MockProxy) DescribeDatabase(_a0 context.Context, _a1 *milvuspb.DescribeDatabaseRequest) (*milvuspb.DescribeDatabaseResponse, error) {
ret := _m.Called(_a0, _a1)
var r0 *milvuspb.DescribeDatabaseResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *milvuspb.DescribeDatabaseRequest) (*milvuspb.DescribeDatabaseResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, *milvuspb.DescribeDatabaseRequest) *milvuspb.DescribeDatabaseResponse); ok {
r0 = rf(_a0, _a1)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*milvuspb.DescribeDatabaseResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *milvuspb.DescribeDatabaseRequest) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// MockProxy_DescribeDatabase_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DescribeDatabase'
type MockProxy_DescribeDatabase_Call struct {
*mock.Call
}
// DescribeDatabase is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 *milvuspb.DescribeDatabaseRequest
func (_e *MockProxy_Expecter) DescribeDatabase(_a0 interface{}, _a1 interface{}) *MockProxy_DescribeDatabase_Call {
return &MockProxy_DescribeDatabase_Call{Call: _e.mock.On("DescribeDatabase", _a0, _a1)}
}
func (_c *MockProxy_DescribeDatabase_Call) Run(run func(_a0 context.Context, _a1 *milvuspb.DescribeDatabaseRequest)) *MockProxy_DescribeDatabase_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(*milvuspb.DescribeDatabaseRequest))
})
return _c
}
func (_c *MockProxy_DescribeDatabase_Call) Return(_a0 *milvuspb.DescribeDatabaseResponse, _a1 error) *MockProxy_DescribeDatabase_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *MockProxy_DescribeDatabase_Call) RunAndReturn(run func(context.Context, *milvuspb.DescribeDatabaseRequest) (*milvuspb.DescribeDatabaseResponse, error)) *MockProxy_DescribeDatabase_Call {
_c.Call.Return(run)
return _c
}
// DescribeIndex provides a mock function with given fields: _a0, _a1 // DescribeIndex provides a mock function with given fields: _a0, _a1
func (_m *MockProxy) DescribeIndex(_a0 context.Context, _a1 *milvuspb.DescribeIndexRequest) (*milvuspb.DescribeIndexResponse, error) { func (_m *MockProxy) DescribeIndex(_a0 context.Context, _a1 *milvuspb.DescribeIndexRequest) (*milvuspb.DescribeIndexResponse, error) {
ret := _m.Called(_a0, _a1) ret := _m.Called(_a0, _a1)

View File

@ -218,6 +218,7 @@ message DescribeDatabaseResponse {
string db_name = 2; string db_name = 2;
int64 dbID = 3; int64 dbID = 3;
uint64 created_timestamp = 4; uint64 created_timestamp = 4;
repeated common.KeyValuePair properties = 5;
} }
message AlterDatabaseRequest { message AlterDatabaseRequest {

View File

@ -460,6 +460,66 @@ func (node *Proxy) AlterDatabase(ctx context.Context, request *milvuspb.AlterDat
return act.result, nil return act.result, nil
} }
func (node *Proxy) DescribeDatabase(ctx context.Context, request *milvuspb.DescribeDatabaseRequest) (*milvuspb.DescribeDatabaseResponse, error) {
resp := &milvuspb.DescribeDatabaseResponse{}
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
resp.Status = merr.Status(err)
return resp, nil
}
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DescribeDatabase")
defer sp.End()
method := "DescribeDatabase"
tr := timerecord.NewTimeRecorder(method)
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel, request.GetDbName(), "").Inc()
act := &describeDatabaseTask{
ctx: ctx,
Condition: NewTaskCondition(ctx),
DescribeDatabaseRequest: request,
rootCoord: node.rootCoord,
}
log := log.Ctx(ctx).With(
zap.String("role", typeutil.ProxyRole),
zap.String("db", request.DbName))
log.Debug(rpcReceived(method))
if err := node.sched.ddQueue.Enqueue(act); err != nil {
log.Warn(rpcFailedToEnqueue(method), zap.Error(err))
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel, request.GetDbName(), "").Inc()
resp.Status = merr.Status(err)
return resp, nil
}
log.Debug(rpcEnqueued(method),
zap.Uint64("BeginTs", act.BeginTs()),
zap.Uint64("EndTs", act.EndTs()),
zap.Uint64("timestamp", request.Base.Timestamp))
if err := act.WaitToFinish(); err != nil {
log.Warn(rpcFailedToWaitToFinish(method),
zap.Error(err),
zap.Uint64("BeginTs", act.BeginTs()),
zap.Uint64("EndTs", act.EndTs()))
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel, request.GetDbName(), "").Inc()
resp.Status = merr.Status(err)
return resp, nil
}
log.Debug(rpcDone(method),
zap.Uint64("BeginTs", act.BeginTs()),
zap.Uint64("EndTs", act.EndTs()))
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel, request.GetDbName(), "").Inc()
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
return act.result, nil
}
// CreateCollection create a collection by the schema. // CreateCollection create a collection by the schema.
// TODO(dragondriver): add more detailed ut for ConsistencyLevel, should we support multiple consistency level in Proxy? // TODO(dragondriver): add more detailed ut for ConsistencyLevel, should we support multiple consistency level in Proxy?
func (node *Proxy) CreateCollection(ctx context.Context, request *milvuspb.CreateCollectionRequest) (*commonpb.Status, error) { func (node *Proxy) CreateCollection(ctx context.Context, request *milvuspb.CreateCollectionRequest) (*commonpb.Status, error) {

View File

@ -1144,6 +1144,58 @@ func TestProxyAlterDatabase(t *testing.T) {
}) })
} }
func TestProxyDescribeDatabase(t *testing.T) {
paramtable.Init()
t.Run("not healthy", func(t *testing.T) {
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
node.UpdateStateCode(commonpb.StateCode_Abnormal)
ctx := context.Background()
resp, err := node.DescribeDatabase(ctx, &milvuspb.DescribeDatabaseRequest{})
assert.NoError(t, err)
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrServiceNotReady)
})
factory := dependency.NewDefaultFactory(true)
ctx := context.Background()
node, err := NewProxy(ctx, factory)
assert.NoError(t, err)
node.tsoAllocator = &timestampAllocator{
tso: newMockTimestampAllocatorInterface(),
}
node.simpleLimiter = NewSimpleLimiter()
node.UpdateStateCode(commonpb.StateCode_Healthy)
node.sched, err = newTaskScheduler(ctx, node.tsoAllocator, node.factory)
node.sched.ddQueue.setMaxTaskNum(10)
assert.NoError(t, err)
err = node.sched.Start()
assert.NoError(t, err)
defer node.sched.Close()
t.Run("describe database fail", func(t *testing.T) {
rc := mocks.NewMockRootCoordClient(t)
rc.On("DescribeDatabase", mock.Anything, mock.Anything).Return(nil, errors.New("fail"))
node.rootCoord = rc
ctx := context.Background()
resp, err := node.DescribeDatabase(ctx, &milvuspb.DescribeDatabaseRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetStatus().GetErrorCode())
})
t.Run("describe database ok", func(t *testing.T) {
rc := mocks.NewMockRootCoordClient(t)
rc.On("DescribeDatabase", mock.Anything, mock.Anything).Return(&rootcoordpb.DescribeDatabaseResponse{Status: merr.Success()}, nil)
node.rootCoord = rc
node.UpdateStateCode(commonpb.StateCode_Healthy)
ctx := context.Background()
resp, err := node.DescribeDatabase(ctx, &milvuspb.DescribeDatabaseRequest{})
assert.NoError(t, err)
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
})
}
func TestProxy_AllocTimestamp(t *testing.T) { func TestProxy_AllocTimestamp(t *testing.T) {
t.Run("proxy unhealthy", func(t *testing.T) { t.Run("proxy unhealthy", func(t *testing.T) {
node := &Proxy{} node := &Proxy{}

View File

@ -32,7 +32,6 @@ import (
"github.com/milvus-io/milvus/internal/proto/datapb" "github.com/milvus-io/milvus/internal/proto/datapb"
"github.com/milvus-io/milvus/internal/proto/indexpb" "github.com/milvus-io/milvus/internal/proto/indexpb"
"github.com/milvus-io/milvus/internal/proto/querypb" "github.com/milvus-io/milvus/internal/proto/querypb"
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
"github.com/milvus-io/milvus/internal/types" "github.com/milvus-io/milvus/internal/types"
"github.com/milvus-io/milvus/pkg/common" "github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/log" "github.com/milvus-io/milvus/pkg/log"
@ -92,6 +91,7 @@ const (
DropDatabaseTaskName = "DropDatabaseTaskName" DropDatabaseTaskName = "DropDatabaseTaskName"
ListDatabaseTaskName = "ListDatabaseTaskName" ListDatabaseTaskName = "ListDatabaseTaskName"
AlterDatabaseTaskName = "AlterDatabaseTaskName" AlterDatabaseTaskName = "AlterDatabaseTaskName"
DescribeDatabaseTaskName = "DescribeDatabaseTaskName"
// minFloat32 minimum float. // minFloat32 minimum float.
minFloat32 = -1 * float32(math.MaxFloat32) minFloat32 = -1 * float32(math.MaxFloat32)
@ -2512,75 +2512,3 @@ func (t *ListResourceGroupsTask) Execute(ctx context.Context) error {
func (t *ListResourceGroupsTask) PostExecute(ctx context.Context) error { func (t *ListResourceGroupsTask) PostExecute(ctx context.Context) error {
return nil return nil
} }
type alterDatabaseTask struct {
baseTask
Condition
*milvuspb.AlterDatabaseRequest
ctx context.Context
rootCoord types.RootCoordClient
result *commonpb.Status
}
func (t *alterDatabaseTask) TraceCtx() context.Context {
return t.ctx
}
func (t *alterDatabaseTask) ID() UniqueID {
return t.Base.MsgID
}
func (t *alterDatabaseTask) SetID(uid UniqueID) {
t.Base.MsgID = uid
}
func (t *alterDatabaseTask) Name() string {
return AlterDatabaseTaskName
}
func (t *alterDatabaseTask) Type() commonpb.MsgType {
return t.Base.MsgType
}
func (t *alterDatabaseTask) BeginTs() Timestamp {
return t.Base.Timestamp
}
func (t *alterDatabaseTask) EndTs() Timestamp {
return t.Base.Timestamp
}
func (t *alterDatabaseTask) SetTs(ts Timestamp) {
t.Base.Timestamp = ts
}
func (t *alterDatabaseTask) OnEnqueue() error {
if t.Base == nil {
t.Base = commonpbutil.NewMsgBase()
}
return nil
}
func (t *alterDatabaseTask) PreExecute(ctx context.Context) error {
t.Base.MsgType = commonpb.MsgType_AlterCollection
t.Base.SourceID = paramtable.GetNodeID()
return nil
}
func (t *alterDatabaseTask) Execute(ctx context.Context) error {
var err error
req := &rootcoordpb.AlterDatabaseRequest{
Base: t.AlterDatabaseRequest.GetBase(),
DbName: t.AlterDatabaseRequest.GetDbName(),
DbId: t.AlterDatabaseRequest.GetDbId(),
Properties: t.AlterDatabaseRequest.GetProperties(),
}
t.result, err = t.rootCoord.AlterDatabase(ctx, req)
return err
}
func (t *alterDatabaseTask) PostExecute(ctx context.Context) error {
return nil
}

View File

@ -3,11 +3,16 @@ package proxy
import ( import (
"context" "context"
"go.uber.org/zap"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "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-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
"github.com/milvus-io/milvus/internal/types" "github.com/milvus-io/milvus/internal/types"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/mq/msgstream" "github.com/milvus-io/milvus/pkg/mq/msgstream"
"github.com/milvus-io/milvus/pkg/util/commonpbutil" "github.com/milvus-io/milvus/pkg/util/commonpbutil"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable" "github.com/milvus-io/milvus/pkg/util/paramtable"
) )
@ -213,3 +218,173 @@ func (ldt *listDatabaseTask) Execute(ctx context.Context) error {
func (ldt *listDatabaseTask) PostExecute(ctx context.Context) error { func (ldt *listDatabaseTask) PostExecute(ctx context.Context) error {
return nil return nil
} }
type alterDatabaseTask struct {
baseTask
Condition
*milvuspb.AlterDatabaseRequest
ctx context.Context
rootCoord types.RootCoordClient
result *commonpb.Status
}
func (t *alterDatabaseTask) TraceCtx() context.Context {
return t.ctx
}
func (t *alterDatabaseTask) ID() UniqueID {
return t.Base.MsgID
}
func (t *alterDatabaseTask) SetID(uid UniqueID) {
t.Base.MsgID = uid
}
func (t *alterDatabaseTask) Name() string {
return AlterDatabaseTaskName
}
func (t *alterDatabaseTask) Type() commonpb.MsgType {
return t.Base.MsgType
}
func (t *alterDatabaseTask) BeginTs() Timestamp {
return t.Base.Timestamp
}
func (t *alterDatabaseTask) EndTs() Timestamp {
return t.Base.Timestamp
}
func (t *alterDatabaseTask) SetTs(ts Timestamp) {
t.Base.Timestamp = ts
}
func (t *alterDatabaseTask) OnEnqueue() error {
if t.Base == nil {
t.Base = commonpbutil.NewMsgBase()
}
return nil
}
func (t *alterDatabaseTask) PreExecute(ctx context.Context) error {
t.Base.MsgType = commonpb.MsgType_AlterDatabase
t.Base.SourceID = paramtable.GetNodeID()
return nil
}
func (t *alterDatabaseTask) Execute(ctx context.Context) error {
var err error
req := &rootcoordpb.AlterDatabaseRequest{
Base: t.AlterDatabaseRequest.GetBase(),
DbName: t.AlterDatabaseRequest.GetDbName(),
DbId: t.AlterDatabaseRequest.GetDbId(),
Properties: t.AlterDatabaseRequest.GetProperties(),
}
ret, err := t.rootCoord.AlterDatabase(ctx, req)
if err != nil {
log.Warn("AlterDatabase failed", zap.Error(err))
return err
}
if err := merr.CheckRPCCall(t.result, err); err != nil {
log.Warn("AlterDatabase failed", zap.Error(err))
return err
}
t.result = ret
return err
}
func (t *alterDatabaseTask) PostExecute(ctx context.Context) error {
return nil
}
type describeDatabaseTask struct {
baseTask
Condition
*milvuspb.DescribeDatabaseRequest
ctx context.Context
rootCoord types.RootCoordClient
result *milvuspb.DescribeDatabaseResponse
}
func (t *describeDatabaseTask) TraceCtx() context.Context {
return t.ctx
}
func (t *describeDatabaseTask) ID() UniqueID {
return t.Base.MsgID
}
func (t *describeDatabaseTask) SetID(uid UniqueID) {
t.Base.MsgID = uid
}
func (t *describeDatabaseTask) Name() string {
return AlterDatabaseTaskName
}
func (t *describeDatabaseTask) Type() commonpb.MsgType {
return t.Base.MsgType
}
func (t *describeDatabaseTask) BeginTs() Timestamp {
return t.Base.Timestamp
}
func (t *describeDatabaseTask) EndTs() Timestamp {
return t.Base.Timestamp
}
func (t *describeDatabaseTask) SetTs(ts Timestamp) {
t.Base.Timestamp = ts
}
func (t *describeDatabaseTask) OnEnqueue() error {
if t.Base == nil {
t.Base = commonpbutil.NewMsgBase()
}
return nil
}
func (t *describeDatabaseTask) PreExecute(ctx context.Context) error {
t.Base.MsgType = commonpb.MsgType_AlterCollection
t.Base.SourceID = paramtable.GetNodeID()
return nil
}
func (t *describeDatabaseTask) Execute(ctx context.Context) error {
req := &rootcoordpb.DescribeDatabaseRequest{
Base: t.DescribeDatabaseRequest.GetBase(),
DbName: t.DescribeDatabaseRequest.GetDbName(),
}
ret, err := t.rootCoord.DescribeDatabase(ctx, req)
if err != nil {
log.Warn("DescribeDatabase failed", zap.Error(err))
return err
}
if err := merr.CheckRPCCall(ret, err); err != nil {
log.Warn("DescribeDatabase failed", zap.Error(err))
return err
}
t.result = &milvuspb.DescribeDatabaseResponse{
Status: ret.GetStatus(),
DbName: ret.GetDbName(),
DbID: ret.GetDbID(),
CreatedTimestamp: ret.GetCreatedTimestamp(),
Properties: ret.GetProperties(),
}
return nil
}
func (t *describeDatabaseTask) PostExecute(ctx context.Context) error {
return nil
}

View File

@ -11,8 +11,12 @@ import (
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb" "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-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus/internal/mocks"
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/util" "github.com/milvus-io/milvus/pkg/util"
"github.com/milvus-io/milvus/pkg/util/crypto" "github.com/milvus-io/milvus/pkg/util/crypto"
"github.com/milvus-io/milvus/pkg/util/merr"
"github.com/milvus-io/milvus/pkg/util/paramtable" "github.com/milvus-io/milvus/pkg/util/paramtable"
) )
@ -163,3 +167,41 @@ func TestListDatabaseTask(t *testing.T) {
assert.Equal(t, expectAuth, authorization[0]) assert.Equal(t, expectAuth, authorization[0])
}) })
} }
func TestAlterDatabase(t *testing.T) {
rc := mocks.NewMockRootCoordClient(t)
rc.EXPECT().AlterDatabase(mock.Anything, mock.Anything).Return(merr.Success(), nil)
task := &alterDatabaseTask{
AlterDatabaseRequest: &milvuspb.AlterDatabaseRequest{
Base: &commonpb.MsgBase{},
DbName: "test_alter_database",
Properties: []*commonpb.KeyValuePair{{Key: common.MmapEnabledKey, Value: "true"}},
},
rootCoord: rc,
}
err := task.PreExecute(context.Background())
assert.Nil(t, err)
err = task.Execute(context.Background())
assert.Nil(t, err)
}
func TestDescribeDatabase(t *testing.T) {
rc := mocks.NewMockRootCoordClient(t)
rc.EXPECT().DescribeDatabase(mock.Anything, mock.Anything).Return(&rootcoordpb.DescribeDatabaseResponse{}, nil)
task := &describeDatabaseTask{
DescribeDatabaseRequest: &milvuspb.DescribeDatabaseRequest{
Base: &commonpb.MsgBase{},
DbName: "test_describe_database",
},
rootCoord: rc,
}
err := task.PreExecute(context.Background())
assert.Nil(t, err)
err = task.Execute(context.Background())
assert.Nil(t, err)
}

View File

@ -3662,22 +3662,3 @@ func TestAlterCollectionCheckLoaded(t *testing.T) {
err = task.PreExecute(context.Background()) err = task.PreExecute(context.Background())
assert.Equal(t, merr.Code(merr.ErrCollectionLoaded), merr.Code(err)) assert.Equal(t, merr.Code(merr.ErrCollectionLoaded), merr.Code(err))
} }
func TestAlterDatabase(t *testing.T) {
rc := mocks.NewMockRootCoordClient(t)
rc.EXPECT().AlterDatabase(mock.Anything, mock.Anything).Return(merr.Success(), nil)
task := &alterDatabaseTask{
AlterDatabaseRequest: &milvuspb.AlterDatabaseRequest{
Base: &commonpb.MsgBase{},
DbName: "test_alter_database",
Properties: []*commonpb.KeyValuePair{{Key: common.MmapEnabledKey, Value: "true"}},
},
rootCoord: rc,
}
err := task.PreExecute(context.Background())
assert.Nil(t, err)
err = task.Execute(context.Background())
assert.Nil(t, err)
}

View File

@ -51,6 +51,7 @@ func (t *describeDBTask) Execute(ctx context.Context) (err error) {
DbID: db.ID, DbID: db.ID,
DbName: db.Name, DbName: db.Name,
CreatedTimestamp: db.CreatedTime, CreatedTimestamp: db.CreatedTime,
Properties: db.Properties,
} }
return nil return nil
} }

View File

@ -14,7 +14,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/klauspost/compress v1.17.7 github.com/klauspost/compress v1.17.7
github.com/lingdor/stackerror v0.0.0-20191119040541-976d8885ed76 github.com/lingdor/stackerror v0.0.0-20191119040541-976d8885ed76
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.2 github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430035521-259ae1d10016
github.com/nats-io/nats-server/v2 v2.10.12 github.com/nats-io/nats-server/v2 v2.10.12
github.com/nats-io/nats.go v1.34.1 github.com/nats-io/nats.go v1.34.1
github.com/panjf2000/ants/v2 v2.7.2 github.com/panjf2000/ants/v2 v2.7.2

View File

@ -486,8 +486,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfr
github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= 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/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.2 h1:jgXBS8x8DTriF2pEI0RH/A+eJ8NI1f51iJcdiYEZOBg= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430035521-259ae1d10016 h1:8WV4maXLeGEyJCCYIc1DmZ18H+VFAjMrwXJg5iI2nX4=
github.com/milvus-io/milvus-proto/go-api/v2 v2.4.2/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek= github.com/milvus-io/milvus-proto/go-api/v2 v2.3.4-0.20240430035521-259ae1d10016/go.mod h1:1OIl0v5PQeNxIJhCvY+K55CBUOYDZevw9g9380u1Wek=
github.com/milvus-io/pulsar-client-go v0.6.10 h1:eqpJjU+/QX0iIhEo3nhOqMNXL+TyInAs1IAHZCrCM/A= github.com/milvus-io/pulsar-client-go v0.6.10 h1:eqpJjU+/QX0iIhEo3nhOqMNXL+TyInAs1IAHZCrCM/A=
github.com/milvus-io/pulsar-client-go v0.6.10/go.mod h1:lQqCkgwDF8YFYjKA+zOheTk1tev2B+bKj5j7+nm8M1w= github.com/milvus-io/pulsar-client-go v0.6.10/go.mod h1:lQqCkgwDF8YFYjKA+zOheTk1tev2B+bKj5j7+nm8M1w=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=