2021-11-10 23:56:41 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
2021-04-19 10:09:43 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-10 23:56:41 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 10:09:43 +08:00
|
|
|
//
|
2021-11-10 23:56:41 +08:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2021-04-19 10:09:43 +08:00
|
|
|
|
2021-06-22 14:40:07 +08:00
|
|
|
package proxy
|
2021-01-22 09:36:18 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-20 14:26:09 +08:00
|
|
|
"encoding/base64"
|
2021-03-30 20:19:30 +08:00
|
|
|
"fmt"
|
2021-03-27 11:56:57 +08:00
|
|
|
"os"
|
2021-01-22 09:36:18 +08:00
|
|
|
"strconv"
|
2022-10-18 13:39:26 +08:00
|
|
|
"sync"
|
2023-04-14 15:30:29 +08:00
|
|
|
"time"
|
2022-10-18 13:39:26 +08:00
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-01-19 14:13:43 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2023-09-06 10:35:48 +08:00
|
|
|
"github.com/samber/lo"
|
2023-01-12 16:09:39 +08:00
|
|
|
"go.opentelemetry.io/otel"
|
2023-01-19 14:13:43 +08:00
|
|
|
"go.uber.org/zap"
|
2022-10-18 13:39:26 +08:00
|
|
|
"golang.org/x/sync/errgroup"
|
2021-01-22 09:36:18 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/federpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/proxypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2023-12-05 16:50:47 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proxy/connection"
|
2022-10-20 12:15:27 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/importutil"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/metrics"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/crypto"
|
2023-08-03 15:53:07 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/logutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/timerecord"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/tsoutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2021-01-22 09:36:18 +08:00
|
|
|
)
|
|
|
|
|
2021-12-17 19:07:39 +08:00
|
|
|
const moduleName = "Proxy"
|
2023-06-25 17:20:43 +08:00
|
|
|
|
2023-04-14 15:30:29 +08:00
|
|
|
const SlowReadSpan = time.Second * 5
|
2021-12-17 19:07:39 +08:00
|
|
|
|
2023-09-09 20:13:16 +08:00
|
|
|
// GetComponentStates gets the state of Proxy.
|
2023-09-26 09:57:25 +08:00
|
|
|
func (node *Proxy) GetComponentStates(ctx context.Context, req *milvuspb.GetComponentStatesRequest) (*milvuspb.ComponentStates, error) {
|
2022-10-10 15:55:22 +08:00
|
|
|
stats := &milvuspb.ComponentStates{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2021-03-12 14:22:09 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
code := node.GetStateCode()
|
2023-11-22 09:12:22 +08:00
|
|
|
log.Debug("Proxy current state", zap.String("StateCode", code.String()))
|
2021-11-19 13:57:12 +08:00
|
|
|
nodeID := common.NotRegisteredID
|
|
|
|
if node.session != nil && node.session.Registered() {
|
|
|
|
nodeID = node.session.ServerID
|
|
|
|
}
|
2022-10-10 15:55:22 +08:00
|
|
|
info := &milvuspb.ComponentInfo{
|
2021-11-19 13:57:12 +08:00
|
|
|
// NodeID: Params.ProxyID, // will race with Proxy.Register()
|
|
|
|
NodeID: nodeID,
|
2021-06-22 14:40:07 +08:00
|
|
|
Role: typeutil.ProxyRole,
|
2021-03-12 14:22:09 +08:00
|
|
|
StateCode: code,
|
|
|
|
}
|
|
|
|
stats.State = info
|
|
|
|
return stats, nil
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:57:36 +08:00
|
|
|
// GetStatisticsChannel gets statistics channel of Proxy.
|
2023-09-26 09:57:25 +08:00
|
|
|
func (node *Proxy) GetStatisticsChannel(ctx context.Context, req *internalpb.GetStatisticsChannelRequest) (*milvuspb.StringResponse, error) {
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.StringResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-04 09:57:09 +08:00
|
|
|
Value: "",
|
2021-03-12 14:22:09 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-11-04 19:08:30 +08:00
|
|
|
// InvalidateCollectionMetaCache invalidate the meta cache of specific collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) InvalidateCollectionMetaCache(ctx context.Context, request *proxypb.InvalidateCollMetaCacheRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-11-07 16:55:01 +08:00
|
|
|
}
|
2021-12-17 19:07:39 +08:00
|
|
|
ctx = logutil.WithModule(ctx, moduleName)
|
2023-01-12 16:09:39 +08:00
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-InvalidateCollectionMetaCache")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.String("db", request.DbName),
|
2022-05-19 10:13:56 +08:00
|
|
|
zap.String("collectionName", request.CollectionName),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Int64("collectionID", request.CollectionID),
|
2024-01-30 16:45:02 +08:00
|
|
|
zap.String("msgType", request.GetBase().GetMsgType().String()),
|
|
|
|
zap.String("partitionName", request.GetPartitionName()),
|
2023-10-16 15:34:08 +08:00
|
|
|
)
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Info("received request to invalidate collection meta cache")
|
|
|
|
|
2021-01-30 10:40:22 +08:00
|
|
|
collectionName := request.CollectionName
|
2022-05-19 10:13:56 +08:00
|
|
|
collectionID := request.CollectionID
|
2022-10-21 10:13:28 +08:00
|
|
|
var aliasName []string
|
2024-01-30 16:45:02 +08:00
|
|
|
|
2021-06-22 14:04:08 +08:00
|
|
|
if globalMetaCache != nil {
|
2024-01-30 16:45:02 +08:00
|
|
|
switch request.GetBase().GetMsgType() {
|
|
|
|
case commonpb.MsgType_DropCollection, commonpb.MsgType_RenameCollection, commonpb.MsgType_DropAlias, commonpb.MsgType_AlterAlias:
|
|
|
|
if collectionName != "" {
|
|
|
|
globalMetaCache.RemoveCollection(ctx, request.GetDbName(), collectionName) // no need to return error, though collection may be not cached
|
|
|
|
}
|
|
|
|
if request.CollectionID != UniqueID(0) {
|
|
|
|
aliasName = globalMetaCache.RemoveCollectionsByID(ctx, collectionID)
|
|
|
|
}
|
|
|
|
log.Info("complete to invalidate collection meta cache with collection name", zap.String("collectionName", collectionName))
|
|
|
|
case commonpb.MsgType_DropPartition:
|
|
|
|
if globalMetaCache != nil {
|
|
|
|
if collectionName != "" && request.GetPartitionName() != "" {
|
|
|
|
globalMetaCache.RemovePartition(ctx, request.GetDbName(), request.GetCollectionName(), request.GetPartitionName())
|
|
|
|
} else {
|
|
|
|
log.Warn("invalidate collection meta cache failed. collectionName or partitionName is empty",
|
|
|
|
zap.String("collectionName", collectionName),
|
|
|
|
zap.String("partitionName", request.GetPartitionName()))
|
|
|
|
return merr.Status(merr.WrapErrPartitionNotFound(request.GetPartitionName(), "partition name not specified")), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Warn("receive unexpected msgType of invalidate collection meta cache", zap.String("msgType", request.GetBase().GetMsgType().String()))
|
|
|
|
|
|
|
|
if collectionName != "" {
|
|
|
|
globalMetaCache.RemoveCollection(ctx, request.GetDbName(), collectionName) // no need to return error, though collection may be not cached
|
|
|
|
}
|
|
|
|
if request.CollectionID != UniqueID(0) {
|
|
|
|
aliasName = globalMetaCache.RemoveCollectionsByID(ctx, collectionID)
|
|
|
|
}
|
2022-05-19 10:13:56 +08:00
|
|
|
}
|
2021-06-22 14:04:08 +08:00
|
|
|
}
|
2024-01-30 16:45:02 +08:00
|
|
|
|
2022-09-27 19:18:54 +08:00
|
|
|
if request.GetBase().GetMsgType() == commonpb.MsgType_DropCollection {
|
|
|
|
// no need to handle error, since this Proxy may not create dml stream for the collection.
|
2022-10-18 19:17:27 +08:00
|
|
|
node.chMgr.removeDMLStream(request.GetCollectionID())
|
|
|
|
// clean up collection level metrics
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.CleanupCollectionMetrics(paramtable.GetNodeID(), collectionName)
|
2022-10-21 10:13:28 +08:00
|
|
|
for _, alias := range aliasName {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.CleanupCollectionMetrics(paramtable.GetNodeID(), alias)
|
2022-10-21 10:13:28 +08:00
|
|
|
}
|
2022-09-27 19:18:54 +08:00
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Info("complete to invalidate collection meta cache")
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
func (node *Proxy) CreateDatabase(ctx context.Context, request *milvuspb.CreateDatabaseRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateDatabase")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
method := "CreateDatabase"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
cct := &createDatabaseTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
CreateDatabaseRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
2023-10-20 14:26:09 +08:00
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log := log.With(
|
|
|
|
zap.String("traceID", sp.SpanContext().TraceID().String()),
|
2023-06-25 17:20:43 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.String("dbName", request.DbName),
|
|
|
|
)
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
log.Info(rpcReceived(method))
|
|
|
|
if err := node.sched.ddQueue.Enqueue(cct); err != nil {
|
|
|
|
log.Warn(rpcFailedToEnqueue(method), zap.Error(err))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(rpcEnqueued(method))
|
|
|
|
if err := cct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(rpcFailedToWaitToFinish(method), zap.Error(err))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(rpcDone(method))
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
return cct.result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) DropDatabase(ctx context.Context, request *milvuspb.DropDatabaseRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropDatabase")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
method := "DropDatabase"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
dct := &dropDatabaseTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DropDatabaseRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
2023-10-20 14:26:09 +08:00
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log := log.With(
|
|
|
|
zap.String("traceID", sp.SpanContext().TraceID().String()),
|
2023-06-25 17:20:43 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.String("dbName", request.DbName),
|
|
|
|
)
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
log.Info(rpcReceived(method))
|
|
|
|
if err := node.sched.ddQueue.Enqueue(dct); err != nil {
|
|
|
|
log.Warn(rpcFailedToEnqueue(method), zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(rpcEnqueued(method))
|
|
|
|
if err := dct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(rpcFailedToWaitToFinish(method), zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2023-06-25 17:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(rpcDone(method))
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
return dct.result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) ListDatabases(ctx context.Context, request *milvuspb.ListDatabasesRequest) (*milvuspb.ListDatabasesResponse, error) {
|
|
|
|
resp := &milvuspb.ListDatabasesResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-06-25 17:20:43 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ListDatabases")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
method := "ListDatabases"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
dct := &listDatabaseTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ListDatabasesRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log := log.With(
|
|
|
|
zap.String("traceID", sp.SpanContext().TraceID().String()),
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
log.Info(rpcReceived(method))
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(dct); err != nil {
|
|
|
|
log.Warn(rpcFailedToEnqueue(method), zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-06-25 17:20:43 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(rpcEnqueued(method))
|
|
|
|
if err := dct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(rpcFailedToWaitToFinish(method), zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-06-25 17:20:43 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(rpcDone(method), zap.Int("num of db", len(dct.result.DbNames)))
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
return dct.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-05 19:46:19 +08:00
|
|
|
// CreateCollection create a collection by the schema.
|
2022-04-20 16:15:41 +08:00
|
|
|
// TODO(dragondriver): add more detailed ut for ConsistencyLevel, should we support multiple consistency level in Proxy?
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) CreateCollection(ctx context.Context, request *milvuspb.CreateCollectionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-11-30 20:05:40 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateCollection")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "CreateCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2021-11-30 20:05:40 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
cct := &createCollectionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
CreateCollectionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 20:05:40 +08:00
|
|
|
// avoid data race
|
|
|
|
lenOfSchema := len(request.Schema)
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
2021-11-30 20:05:40 +08:00
|
|
|
zap.Int("len(schema)", lenOfSchema),
|
2021-12-21 19:49:02 +08:00
|
|
|
zap.Int32("shards_num", request.ShardsNum),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.String("consistency_level", request.ConsistencyLevel.String()),
|
|
|
|
)
|
2021-11-30 20:05:40 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-15 22:43:10 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(cct); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-11-30 20:05:40 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 22:43:10 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
2021-11-30 20:05:40 +08:00
|
|
|
zap.Uint64("BeginTs", cct.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", cct.EndTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("timestamp", request.Base.Timestamp),
|
|
|
|
)
|
2021-11-30 20:05:40 +08:00
|
|
|
|
2021-12-15 22:43:10 +08:00
|
|
|
if err := cct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-11-30 20:05:40 +08:00
|
|
|
zap.Uint64("BeginTs", cct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cct.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 22:43:10 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
2021-11-30 20:05:40 +08:00
|
|
|
zap.Uint64("BeginTs", cct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTs", cct.EndTs()),
|
|
|
|
)
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-30 20:05:40 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return cct.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-05 19:50:22 +08:00
|
|
|
// DropCollection drop a collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) DropCollection(ctx context.Context, request *milvuspb.DropCollectionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-01 15:23:52 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropCollection")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "DropCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2021-12-01 15:23:52 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
dct := &dropCollectionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DropCollectionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-05-27 17:09:50 +08:00
|
|
|
chMgr: node.chMgr,
|
2021-06-08 19:25:37 +08:00
|
|
|
chTicker: node.chTicker,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
)
|
2021-12-01 15:23:52 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("DropCollection received")
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-01 15:23:52 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(dct); err != nil {
|
|
|
|
log.Warn("DropCollection failed to enqueue",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-01 15:23:52 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log.Debug(
|
|
|
|
"DropCollection enqueued",
|
2021-12-01 15:23:52 +08:00
|
|
|
zap.Uint64("BeginTs", dct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTs", dct.EndTs()),
|
|
|
|
)
|
2021-12-01 15:23:52 +08:00
|
|
|
|
|
|
|
if err := dct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("DropCollection failed to WaitToFinish",
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-01 15:23:52 +08:00
|
|
|
zap.Uint64("BeginTs", dct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dct.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2023-10-16 15:34:08 +08:00
|
|
|
"DropCollection done",
|
2021-12-01 15:23:52 +08:00
|
|
|
zap.Uint64("BeginTs", dct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTs", dct.EndTs()),
|
|
|
|
)
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-12-01 15:23:52 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return dct.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-05 19:52:07 +08:00
|
|
|
// HasCollection check if the specific collection exists in Milvus.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) HasCollection(ctx context.Context, request *milvuspb.HasCollectionRequest) (*milvuspb.BoolResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-01 15:43:44 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-HasCollection")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "HasCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2021-12-01 15:43:44 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-12-01 15:43:44 +08:00
|
|
|
zap.String("db", request.DbName),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
)
|
2021-12-01 15:43:44 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("HasCollection received")
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
hct := &hasCollectionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
HasCollectionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-01 15:43:44 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(hct); err != nil {
|
|
|
|
log.Warn("HasCollection failed to enqueue",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-01 15:43:44 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log.Debug(
|
|
|
|
"HasCollection enqueued",
|
2021-12-01 15:43:44 +08:00
|
|
|
zap.Uint64("BeginTS", hct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTS", hct.EndTs()),
|
|
|
|
)
|
2021-12-01 15:43:44 +08:00
|
|
|
|
|
|
|
if err := hct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("HasCollection failed to WaitToFinish",
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-01 15:43:44 +08:00
|
|
|
zap.Uint64("BeginTS", hct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", hct.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log.Debug(
|
|
|
|
"HasCollection done",
|
2021-12-01 15:43:44 +08:00
|
|
|
zap.Uint64("BeginTS", hct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTS", hct.EndTs()),
|
|
|
|
)
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-12-01 15:43:44 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return hct.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-08 20:31:53 +08:00
|
|
|
// LoadCollection load a collection into query nodes.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) LoadCollection(ctx context.Context, request *milvuspb.LoadCollectionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-07 20:55:03 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-LoadCollection")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "LoadCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
lct := &loadCollectionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-02-04 17:47:19 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
LoadCollectionRequest: request,
|
2021-06-22 16:44:09 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2023-01-04 19:37:36 +08:00
|
|
|
datacoord: node.dataCoord,
|
2023-10-20 14:26:09 +08:00
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
2023-02-02 19:29:51 +08:00
|
|
|
zap.String("collection", request.CollectionName),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Bool("refreshMode", request.Refresh),
|
|
|
|
)
|
2021-12-07 20:55:03 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("LoadCollection received")
|
|
|
|
|
2021-12-07 20:55:03 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(lct); err != nil {
|
|
|
|
log.Warn("LoadCollection failed to enqueue",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-07 20:55:03 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log.Debug(
|
|
|
|
"LoadCollection enqueued",
|
2021-12-07 20:55:03 +08:00
|
|
|
zap.Uint64("BeginTS", lct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTS", lct.EndTs()),
|
|
|
|
)
|
2021-12-07 20:55:03 +08:00
|
|
|
|
|
|
|
if err := lct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("LoadCollection failed to WaitToFinish",
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-07 20:55:03 +08:00
|
|
|
zap.Uint64("BeginTS", lct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", lct.EndTs()))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
log.Debug(
|
|
|
|
"LoadCollection done",
|
2021-12-07 20:55:03 +08:00
|
|
|
zap.Uint64("BeginTS", lct.BeginTs()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("EndTS", lct.EndTs()),
|
|
|
|
)
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-12-07 20:55:03 +08:00
|
|
|
|
2021-02-04 17:47:19 +08:00
|
|
|
return lct.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-08 20:34:16 +08:00
|
|
|
// ReleaseCollection remove the loaded collection from query nodes.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) ReleaseCollection(ctx context.Context, request *milvuspb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-07 21:03:03 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ReleaseCollection")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "ReleaseCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-09-09 19:02:08 +08:00
|
|
|
rct := &releaseCollectionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-02-04 17:47:19 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ReleaseCollectionRequest: request,
|
2021-06-22 16:44:09 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2023-10-20 14:26:09 +08:00
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName))
|
2021-12-07 21:03:03 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-07 21:03:03 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(rct); err != nil {
|
2021-12-15 22:13:10 +08:00
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-07 21:03:03 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 22:13:10 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
2021-12-07 21:03:03 +08:00
|
|
|
zap.Uint64("BeginTS", rct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", rct.EndTs()))
|
2021-12-07 21:03:03 +08:00
|
|
|
|
|
|
|
if err := rct.WaitToFinish(); err != nil {
|
2021-12-15 22:13:10 +08:00
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-07 21:03:03 +08:00
|
|
|
zap.Uint64("BeginTS", rct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", rct.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 22:13:10 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
2021-12-07 21:03:03 +08:00
|
|
|
zap.Uint64("BeginTS", rct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", rct.EndTs()))
|
2021-12-07 21:03:03 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-04 17:47:19 +08:00
|
|
|
return rct.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-08 20:36:04 +08:00
|
|
|
// DescribeCollection get the meta information of specific collection, such as schema, created timestamp and etc.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) DescribeCollection(ctx context.Context, request *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-07 21:05:15 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DescribeCollection")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "DescribeCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-12-07 21:05:15 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
dct := &describeCollectionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DescribeCollectionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName))
|
2021-12-07 21:05:15 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("DescribeCollection received")
|
|
|
|
|
2021-12-07 21:05:15 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(dct); err != nil {
|
|
|
|
log.Warn("DescribeCollection failed to enqueue",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-07 21:05:15 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-07 21:05:15 +08:00
|
|
|
log.Debug("DescribeCollection enqueued",
|
|
|
|
zap.Uint64("BeginTS", dct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", dct.EndTs()))
|
2021-12-07 21:05:15 +08:00
|
|
|
|
|
|
|
if err := dct.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("DescribeCollection failed to WaitToFinish",
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-07 21:05:15 +08:00
|
|
|
zap.Uint64("BeginTS", dct.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", dct.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-07 21:05:15 +08:00
|
|
|
log.Debug("DescribeCollection done",
|
|
|
|
zap.Uint64("BeginTS", dct.BeginTs()),
|
2023-06-25 17:20:43 +08:00
|
|
|
zap.Uint64("EndTS", dct.EndTs()),
|
|
|
|
zap.String("db", request.DbName),
|
2023-09-04 09:57:09 +08:00
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
)
|
2021-12-07 21:05:15 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return dct.result, nil
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:58:28 +08:00
|
|
|
// GetStatistics get the statistics, such as `num_rows`.
|
|
|
|
// WARNING: It is an experimental API
|
|
|
|
func (node *Proxy) GetStatistics(ctx context.Context, request *milvuspb.GetStatisticsRequest) (*milvuspb.GetStatisticsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2022-07-18 09:58:28 +08:00
|
|
|
return &milvuspb.GetStatisticsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2022-07-18 09:58:28 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetStatistics")
|
|
|
|
defer sp.End()
|
2022-07-18 09:58:28 +08:00
|
|
|
method := "GetStatistics"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-07-18 09:58:28 +08:00
|
|
|
g := &getStatisticsTask{
|
|
|
|
request: request,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
tr: tr,
|
|
|
|
dc: node.dataCoord,
|
|
|
|
qc: node.queryCoord,
|
2023-06-13 10:20:37 +08:00
|
|
|
lb: node.lbPolicy,
|
2022-07-18 09:58:28 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2022-07-18 09:58:28 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("collection", request.CollectionName))
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcReceived(method),
|
2022-07-18 09:58:28 +08:00
|
|
|
zap.Strings("partitions", request.PartitionNames))
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(g); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Strings("partitions", request.PartitionNames))
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-07-18 09:58:28 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.GetStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-07-18 09:58:28 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", g.EndTs()),
|
|
|
|
zap.Strings("partitions", request.PartitionNames))
|
|
|
|
|
|
|
|
if err := g.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", g.EndTs()),
|
|
|
|
zap.Strings("partitions", request.PartitionNames))
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-07-18 09:58:28 +08:00
|
|
|
metrics.FailLabel).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.GetStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-07-18 09:58:28 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2022-07-18 09:58:28 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-07-18 09:58:28 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-07-18 09:58:28 +08:00
|
|
|
return g.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-09 19:58:10 +08:00
|
|
|
// GetCollectionStatistics get the collection statistics, such as `num_rows`.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetCollectionStatistics(ctx context.Context, request *milvuspb.GetCollectionStatisticsRequest) (*milvuspb.GetCollectionStatisticsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.GetCollectionStatisticsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-07 21:09:12 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetCollectionStatistics")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "GetCollectionStatistics"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-09-09 19:02:08 +08:00
|
|
|
g := &getCollectionStatisticsTask{
|
2021-03-12 14:22:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
GetCollectionStatisticsRequest: request,
|
2021-06-21 18:22:13 +08:00
|
|
|
dataCoord: node.dataCoord,
|
2021-02-02 19:54:31 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName))
|
2021-12-07 21:09:12 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-07 21:09:12 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(g); err != nil {
|
2022-07-18 09:58:28 +08:00
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-07 21:09:12 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.GetCollectionStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-02-02 19:54:31 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:58:28 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
2021-12-07 21:09:12 +08:00
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2021-12-07 21:09:12 +08:00
|
|
|
|
|
|
|
if err := g.WaitToFinish(); err != nil {
|
2022-07-18 09:58:28 +08:00
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-07 21:09:12 +08:00
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.GetCollectionStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-02-02 19:54:31 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-07-18 09:58:28 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
2021-12-07 21:09:12 +08:00
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2021-12-07 21:09:12 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-02 19:54:31 +08:00
|
|
|
return g.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-09 20:00:17 +08:00
|
|
|
// ShowCollections list all collections in Milvus.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) ShowCollections(ctx context.Context, request *milvuspb.ShowCollectionsRequest) (*milvuspb.ShowCollectionsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.ShowCollectionsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ShowCollections")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "ShowCollections"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
sct := &showCollectionsTask{
|
2021-03-12 14:22:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ShowCollectionsRequest: request,
|
2021-06-22 16:44:09 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-11-29 14:27:24 +08:00
|
|
|
zap.String("DbName", request.DbName),
|
|
|
|
zap.Uint64("TimeStamp", request.TimeStamp),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("ShowType", request.Type.String()))
|
|
|
|
|
|
|
|
log.Debug("ShowCollections received",
|
|
|
|
zap.Any("CollectionNames", request.CollectionNames))
|
2021-11-29 14:27:24 +08:00
|
|
|
|
2021-09-06 20:49:04 +08:00
|
|
|
err := node.sched.ddQueue.Enqueue(sct)
|
2021-01-22 09:36:18 +08:00
|
|
|
if err != nil {
|
2021-11-29 14:27:24 +08:00
|
|
|
log.Warn("ShowCollections failed to enqueue",
|
|
|
|
zap.Error(err),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Any("CollectionNames", request.CollectionNames))
|
2021-11-29 14:27:24 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowCollectionsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-11-29 14:27:24 +08:00
|
|
|
log.Debug("ShowCollections enqueued",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Any("CollectionNames", request.CollectionNames))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
err = sct.WaitToFinish()
|
|
|
|
if err != nil {
|
2021-11-29 14:27:24 +08:00
|
|
|
log.Warn("ShowCollections failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Any("CollectionNames", request.CollectionNames))
|
2021-11-29 14:27:24 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowCollectionsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-11-29 14:27:24 +08:00
|
|
|
log.Debug("ShowCollections Done",
|
2022-03-28 21:47:27 +08:00
|
|
|
zap.Int("len(CollectionNames)", len(request.CollectionNames)),
|
|
|
|
zap.Int("num_collections", len(sct.result.CollectionNames)))
|
2021-11-29 14:27:24 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return sct.result, nil
|
|
|
|
}
|
|
|
|
|
2022-10-10 20:31:22 +08:00
|
|
|
func (node *Proxy) AlterCollection(ctx context.Context, request *milvuspb.AlterCollectionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-10-10 20:31:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-AlterCollection")
|
|
|
|
defer sp.End()
|
2022-10-10 20:31:22 +08:00
|
|
|
method := "AlterCollection"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2022-10-10 20:31:22 +08:00
|
|
|
|
|
|
|
act := &alterCollectionTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
AlterCollectionRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2022-10-10 20:31:22 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2022-11-14 15:29:06 +08:00
|
|
|
rpcReceived(method))
|
|
|
|
|
2022-10-10 20:31:22 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(act); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2022-10-10 20:31:22 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-10-10 20:31:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", act.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", act.EndTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("timestamp", request.Base.Timestamp))
|
2022-10-10 20:31:22 +08:00
|
|
|
|
|
|
|
if err := act.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTs", act.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", act.EndTs()))
|
2022-10-10 20:31:22 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-10-10 20:31:22 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2022-10-10 20:31:22 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", act.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", act.EndTs()))
|
2022-10-10 20:31:22 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-10-10 20:31:22 +08:00
|
|
|
return act.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-09 20:02:14 +08:00
|
|
|
// CreatePartition create a partition in specific collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) CreatePartition(ctx context.Context, request *milvuspb.CreatePartitionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-06 15:13:35 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreatePartition")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "CreatePartition"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2021-12-06 15:13:35 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
cpt := &createPartitionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
CreatePartitionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
result: nil,
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName))
|
2021-12-06 15:13:35 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-06 15:13:35 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(cpt); err != nil {
|
|
|
|
log.Warn(
|
2023-06-06 10:24:34 +08:00
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-06 15:13:35 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2021-12-06 15:13:35 +08:00
|
|
|
log.Debug(
|
2023-06-06 10:24:34 +08:00
|
|
|
rpcEnqueued(method),
|
2021-12-06 15:13:35 +08:00
|
|
|
zap.Uint64("BeginTS", cpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", cpt.EndTs()))
|
2021-12-06 15:13:35 +08:00
|
|
|
|
|
|
|
if err := cpt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
2023-06-06 10:24:34 +08:00
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-06 15:13:35 +08:00
|
|
|
zap.Uint64("BeginTS", cpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", cpt.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-12-06 15:13:35 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2023-06-06 10:24:34 +08:00
|
|
|
rpcDone(method),
|
2021-12-06 15:13:35 +08:00
|
|
|
zap.Uint64("BeginTS", cpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", cpt.EndTs()))
|
2021-12-06 15:13:35 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return cpt.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-10 19:54:09 +08:00
|
|
|
// DropPartition drop a partition in specific collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) DropPartition(ctx context.Context, request *milvuspb.DropPartitionRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-07 21:11:04 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropPartition")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "DropPartition"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2021-12-07 21:11:04 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
dpt := &dropPartitionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DropPartitionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2022-10-21 14:41:28 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
result: nil,
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName))
|
2021-12-07 21:11:04 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-07 21:11:04 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(dpt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-07 21:11:04 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2021-12-07 21:11:04 +08:00
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", dpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", dpt.EndTs()))
|
2021-12-07 21:11:04 +08:00
|
|
|
|
|
|
|
if err := dpt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-07 21:11:04 +08:00
|
|
|
zap.Uint64("BeginTS", dpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", dpt.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-12-07 21:11:04 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2021-12-07 21:11:04 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", dpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", dpt.EndTs()))
|
2021-12-07 21:11:04 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return dpt.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-10 19:56:05 +08:00
|
|
|
// HasPartition check if partition exist.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) HasPartition(ctx context.Context, request *milvuspb.HasPartitionRequest) (*milvuspb.BoolResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-08 14:31:05 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-HasPartition")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "HasPartition"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-09-21 09:45:27 +08:00
|
|
|
// TODO: use collectionID instead of collectionName
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-12-08 14:31:05 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
hpt := &hasPartitionTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
HasPartitionRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
result: nil,
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName))
|
2021-12-08 14:31:05 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-08 14:31:05 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(hpt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-08 14:31:05 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
|
|
|
Value: false,
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2021-12-08 14:31:05 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", hpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", hpt.EndTs()))
|
2021-12-08 14:31:05 +08:00
|
|
|
|
|
|
|
if err := hpt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-08 14:31:05 +08:00
|
|
|
zap.Uint64("BeginTS", hpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", hpt.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
|
|
|
Value: false,
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-08 14:31:05 +08:00
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", hpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", hpt.EndTs()))
|
2021-12-08 14:31:05 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return hpt.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-10 19:57:59 +08:00
|
|
|
// LoadPartitions load specific partitions into query nodes.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) LoadPartitions(ctx context.Context, request *milvuspb.LoadPartitionsRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-08 14:35:02 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-LoadPartitions")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "LoadPartitions"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-09-09 19:02:08 +08:00
|
|
|
lpt := &loadPartitionsTask{
|
2021-03-12 14:22:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
LoadPartitionsRequest: request,
|
2021-06-22 16:44:09 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2023-01-04 19:37:36 +08:00
|
|
|
datacoord: node.dataCoord,
|
2023-11-23 15:38:24 +08:00
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
2023-02-02 19:29:51 +08:00
|
|
|
zap.Strings("partitions", request.PartitionNames),
|
|
|
|
zap.Bool("refreshMode", request.Refresh))
|
2021-12-08 14:35:02 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-08 14:35:02 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(lpt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-08 14:35:02 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:35:02 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", lpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", lpt.EndTs()))
|
2021-12-08 14:35:02 +08:00
|
|
|
|
|
|
|
if err := lpt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-08 14:35:02 +08:00
|
|
|
zap.Uint64("BeginTS", lpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", lpt.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:35:02 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", lpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", lpt.EndTs()))
|
2021-12-08 14:35:02 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-04 17:47:19 +08:00
|
|
|
return lpt.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-11 21:07:14 +08:00
|
|
|
// ReleasePartitions release specific partitions from query nodes.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) ReleasePartitions(ctx context.Context, request *milvuspb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-08 14:55:23 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ReleasePartitions")
|
|
|
|
defer sp.End()
|
2021-12-08 14:55:23 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
rpt := &releasePartitionsTask{
|
2021-03-12 14:22:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ReleasePartitionsRequest: request,
|
2021-06-22 16:44:09 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2023-11-23 15:38:24 +08:00
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:55:23 +08:00
|
|
|
method := "ReleasePartitions"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.Any("partitions", request.PartitionNames))
|
2021-12-08 14:55:23 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-08 14:55:23 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(rpt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-08 14:55:23 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:55:23 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", rpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", rpt.EndTs()))
|
2021-12-08 14:55:23 +08:00
|
|
|
|
|
|
|
if err := rpt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-08 14:55:23 +08:00
|
|
|
zap.Uint64("BeginTS", rpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", rpt.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-04 17:47:19 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:55:23 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", rpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", rpt.EndTs()))
|
2021-12-08 14:55:23 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-04 17:47:19 +08:00
|
|
|
return rpt.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-11 21:09:06 +08:00
|
|
|
// GetPartitionStatistics get the statistics of partition, such as num_rows.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetPartitionStatistics(ctx context.Context, request *milvuspb.GetPartitionStatisticsRequest) (*milvuspb.GetPartitionStatisticsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.GetPartitionStatisticsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-08 23:05:07 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetPartitionStatistics")
|
|
|
|
defer sp.End()
|
2022-07-18 09:58:28 +08:00
|
|
|
method := "GetPartitionStatistics"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-12-08 23:05:07 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
g := &getPartitionStatisticsTask{
|
2021-05-10 17:39:08 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
GetPartitionStatisticsRequest: request,
|
2021-06-21 18:22:13 +08:00
|
|
|
dataCoord: node.dataCoord,
|
2021-05-10 17:39:08 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName))
|
2021-12-08 23:05:07 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-08 23:05:07 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(g); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-08 23:05:07 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-05-10 17:39:08 +08:00
|
|
|
return &milvuspb.GetPartitionStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-05-10 17:39:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-08 23:05:07 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2021-12-08 23:05:07 +08:00
|
|
|
|
|
|
|
if err := g.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-05-10 17:39:08 +08:00
|
|
|
zap.Error(err),
|
2021-12-08 23:05:07 +08:00
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2021-05-10 17:39:08 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-05-10 17:39:08 +08:00
|
|
|
return &milvuspb.GetPartitionStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-05-10 17:39:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-08 23:05:07 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", g.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTS", g.EndTs()))
|
2021-12-08 23:05:07 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-05-10 17:39:08 +08:00
|
|
|
return g.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-11 23:14:44 +08:00
|
|
|
// ShowPartitions list all partitions in the specific collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) ShowPartitions(ctx context.Context, request *milvuspb.ShowPartitionsRequest) (*milvuspb.ShowPartitionsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-08 14:57:48 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ShowPartitions")
|
|
|
|
defer sp.End()
|
2021-12-08 14:57:48 +08:00
|
|
|
|
2021-09-09 19:02:08 +08:00
|
|
|
spt := &showPartitionsTask{
|
2021-03-12 14:22:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ShowPartitionsRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-08-02 22:39:25 +08:00
|
|
|
queryCoord: node.queryCoord,
|
2021-03-12 14:22:09 +08:00
|
|
|
result: nil,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-08 14:57:48 +08:00
|
|
|
method := "ShowPartitions"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-09-21 09:45:27 +08:00
|
|
|
// TODO: use collectionID instead of collectionName
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-12-08 14:57:48 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(zap.String("role", typeutil.ProxyRole))
|
|
|
|
|
2021-12-08 14:57:48 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcReceived(method),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.Any("request", request))
|
2021-12-08 14:57:48 +08:00
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(spt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Any("request", request))
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-08 14:57:48 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTS", spt.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", spt.EndTs()),
|
2021-09-09 19:02:08 +08:00
|
|
|
zap.String("db", spt.ShowPartitionsRequest.DbName),
|
|
|
|
zap.String("collection", spt.ShowPartitionsRequest.CollectionName),
|
2021-12-08 14:57:48 +08:00
|
|
|
zap.Any("partitions", spt.ShowPartitionsRequest.PartitionNames))
|
|
|
|
|
|
|
|
if err := spt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-08 14:57:48 +08:00
|
|
|
zap.Uint64("BeginTS", spt.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", spt.EndTs()),
|
|
|
|
zap.String("db", spt.ShowPartitionsRequest.DbName),
|
|
|
|
zap.String("collection", spt.ShowPartitionsRequest.CollectionName),
|
|
|
|
zap.Any("partitions", spt.ShowPartitionsRequest.PartitionNames))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-08 14:57:48 +08:00
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTS", spt.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", spt.EndTs()),
|
|
|
|
zap.String("db", spt.ShowPartitionsRequest.DbName),
|
|
|
|
zap.String("collection", spt.ShowPartitionsRequest.CollectionName),
|
|
|
|
zap.Any("partitions", spt.ShowPartitionsRequest.PartitionNames))
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return spt.result, nil
|
|
|
|
}
|
|
|
|
|
2022-10-01 09:02:55 +08:00
|
|
|
func (node *Proxy) GetLoadingProgress(ctx context.Context, request *milvuspb.GetLoadingProgressRequest) (*milvuspb.GetLoadingProgressResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.GetLoadingProgressResponse{Status: merr.Status(err)}, nil
|
2022-10-01 09:02:55 +08:00
|
|
|
}
|
|
|
|
method := "GetLoadingProgress"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetLoadingProgress")
|
|
|
|
defer sp.End()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug(
|
2022-10-01 09:02:55 +08:00
|
|
|
rpcReceived(method),
|
|
|
|
zap.Any("request", request))
|
|
|
|
|
|
|
|
getErrResponse := func(err error) *milvuspb.GetLoadingProgressResponse {
|
2022-11-30 14:11:15 +08:00
|
|
|
log.Warn("fail to get loading progress",
|
2023-09-30 10:31:28 +08:00
|
|
|
zap.String("collectionName", request.CollectionName),
|
|
|
|
zap.Strings("partitionName", request.PartitionNames),
|
2022-12-16 14:39:24 +08:00
|
|
|
zap.Error(err))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-30 10:31:28 +08:00
|
|
|
if errors.Is(err, merr.ErrServiceMemoryLimitExceeded) {
|
2023-01-10 20:35:39 +08:00
|
|
|
return &milvuspb.GetLoadingProgressResponse{
|
2023-09-30 10:31:28 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-10 20:35:39 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-01 09:02:55 +08:00
|
|
|
return &milvuspb.GetLoadingProgressResponse{
|
2023-03-24 15:27:58 +08:00
|
|
|
Status: merr.Status(err),
|
2022-10-01 09:02:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := validateCollectionName(request.CollectionName); err != nil {
|
|
|
|
return getErrResponse(err), nil
|
|
|
|
}
|
2023-06-25 17:20:43 +08:00
|
|
|
collectionID, err := globalMetaCache.GetCollectionID(ctx, request.GetDbName(), request.CollectionName)
|
2022-10-01 09:02:55 +08:00
|
|
|
if err != nil {
|
|
|
|
return getErrResponse(err), nil
|
|
|
|
}
|
2022-12-16 14:39:24 +08:00
|
|
|
|
2022-10-19 10:01:26 +08:00
|
|
|
msgBase := commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SystemInfo),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
)
|
2022-10-01 09:02:55 +08:00
|
|
|
if request.Base == nil {
|
|
|
|
request.Base = msgBase
|
|
|
|
} else {
|
|
|
|
request.Base.MsgID = msgBase.MsgID
|
|
|
|
request.Base.Timestamp = msgBase.Timestamp
|
|
|
|
request.Base.SourceID = msgBase.SourceID
|
|
|
|
}
|
|
|
|
|
2023-04-12 15:06:28 +08:00
|
|
|
var (
|
|
|
|
loadProgress int64
|
|
|
|
refreshProgress int64
|
|
|
|
)
|
2022-10-01 09:02:55 +08:00
|
|
|
if len(request.GetPartitionNames()) == 0 {
|
2023-04-12 15:06:28 +08:00
|
|
|
if loadProgress, refreshProgress, err = getCollectionProgress(ctx, node.queryCoord, request.GetBase(), collectionID); err != nil {
|
2022-10-01 09:02:55 +08:00
|
|
|
return getErrResponse(err), nil
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-12 15:06:28 +08:00
|
|
|
if loadProgress, refreshProgress, err = getPartitionProgress(ctx, node.queryCoord, request.GetBase(),
|
2023-08-22 17:06:22 +08:00
|
|
|
request.GetPartitionNames(), request.GetCollectionName(), collectionID, request.GetDbName()); err != nil {
|
2022-10-01 09:02:55 +08:00
|
|
|
return getErrResponse(err), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(
|
2022-10-01 09:02:55 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Any("request", request))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-10-01 09:02:55 +08:00
|
|
|
return &milvuspb.GetLoadingProgressResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-04-12 15:06:28 +08:00
|
|
|
Progress: loadProgress,
|
|
|
|
RefreshProgress: refreshProgress,
|
2022-10-01 09:02:55 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-12-14 10:23:22 +08:00
|
|
|
func (node *Proxy) GetLoadState(ctx context.Context, request *milvuspb.GetLoadStateRequest) (*milvuspb.GetLoadStateResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.GetLoadStateResponse{Status: merr.Status(err)}, nil
|
2022-12-16 14:39:24 +08:00
|
|
|
}
|
|
|
|
method := "GetLoadState"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetLoadState")
|
|
|
|
defer sp.End()
|
2022-12-16 14:39:24 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcReceived(method),
|
|
|
|
zap.Any("request", request))
|
|
|
|
|
|
|
|
getErrResponse := func(err error) *milvuspb.GetLoadStateResponse {
|
|
|
|
log.Warn("fail to get load state",
|
|
|
|
zap.String("collection_name", request.CollectionName),
|
|
|
|
zap.Strings("partition_name", request.PartitionNames),
|
|
|
|
zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
|
|
|
return &milvuspb.GetLoadStateResponse{
|
2023-03-24 15:27:58 +08:00
|
|
|
Status: merr.Status(err),
|
2022-12-16 14:39:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validateCollectionName(request.CollectionName); err != nil {
|
|
|
|
return getErrResponse(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
successResponse := &milvuspb.GetLoadStateResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-16 14:39:24 +08:00
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Any("request", request))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
}()
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
collectionID, err := globalMetaCache.GetCollectionID(ctx, request.GetDbName(), request.CollectionName)
|
2022-12-16 14:39:24 +08:00
|
|
|
if err != nil {
|
2024-01-28 15:33:02 +08:00
|
|
|
log.Warn("failed to get collection id",
|
|
|
|
zap.String("dbName", request.GetDbName()),
|
|
|
|
zap.String("collectionName", request.CollectionName),
|
|
|
|
zap.Error(err))
|
2022-12-16 14:39:24 +08:00
|
|
|
successResponse.State = commonpb.LoadState_LoadStateNotExist
|
|
|
|
return successResponse, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msgBase := commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SystemInfo),
|
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
|
|
|
)
|
|
|
|
if request.Base == nil {
|
|
|
|
request.Base = msgBase
|
|
|
|
} else {
|
|
|
|
request.Base.MsgID = msgBase.MsgID
|
|
|
|
request.Base.Timestamp = msgBase.Timestamp
|
|
|
|
request.Base.SourceID = msgBase.SourceID
|
|
|
|
}
|
|
|
|
|
|
|
|
var progress int64
|
|
|
|
if len(request.GetPartitionNames()) == 0 {
|
2023-04-12 15:06:28 +08:00
|
|
|
if progress, _, err = getCollectionProgress(ctx, node.queryCoord, request.GetBase(), collectionID); err != nil {
|
2023-09-30 10:31:28 +08:00
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, merr.ErrCollectionNotLoaded) {
|
|
|
|
successResponse.State = commonpb.LoadState_LoadStateNotLoad
|
|
|
|
return successResponse, nil
|
|
|
|
}
|
2023-01-10 20:35:39 +08:00
|
|
|
return &milvuspb.GetLoadStateResponse{
|
2023-09-30 10:31:28 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-10 20:35:39 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-12-16 14:39:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2023-04-12 15:06:28 +08:00
|
|
|
if progress, _, err = getPartitionProgress(ctx, node.queryCoord, request.GetBase(),
|
2023-08-22 17:06:22 +08:00
|
|
|
request.GetPartitionNames(), request.GetCollectionName(), collectionID, request.GetDbName()); err != nil {
|
2023-09-30 10:31:28 +08:00
|
|
|
if err != nil {
|
|
|
|
if errors.IsAny(err,
|
|
|
|
merr.ErrCollectionNotLoaded,
|
|
|
|
merr.ErrPartitionNotLoaded) {
|
|
|
|
successResponse.State = commonpb.LoadState_LoadStateNotLoad
|
|
|
|
return successResponse, nil
|
|
|
|
}
|
2023-01-10 20:35:39 +08:00
|
|
|
return &milvuspb.GetLoadStateResponse{
|
2023-09-30 10:31:28 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-10 20:35:39 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-12-16 14:39:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if progress >= 100 {
|
|
|
|
successResponse.State = commonpb.LoadState_LoadStateLoaded
|
|
|
|
} else {
|
|
|
|
successResponse.State = commonpb.LoadState_LoadStateLoading
|
|
|
|
}
|
|
|
|
return successResponse, nil
|
2022-12-14 10:23:22 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 19:21:46 +08:00
|
|
|
// CreateIndex create index for collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) CreateIndex(ctx context.Context, request *milvuspb.CreateIndexRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-10 16:48:50 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateIndex")
|
|
|
|
defer sp.End()
|
2021-12-10 16:48:50 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
cit := &createIndexTask{
|
2023-10-20 14:26:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
req: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
datacoord: node.dataCoord,
|
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:48:50 +08:00
|
|
|
method := "CreateIndex"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("field", request.FieldName),
|
|
|
|
zap.Any("extra_params", request.ExtraParams))
|
2021-12-10 16:48:50 +08:00
|
|
|
|
2023-05-06 10:40:39 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-10 16:48:50 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(cit); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-10 16:48:50 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2023-05-06 10:40:39 +08:00
|
|
|
log.Info(
|
2021-12-10 16:48:50 +08:00
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", cit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cit.EndTs()))
|
2021-12-10 16:48:50 +08:00
|
|
|
|
|
|
|
if err := cit.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-10 16:48:50 +08:00
|
|
|
zap.Uint64("BeginTs", cit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cit.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2023-05-06 10:40:39 +08:00
|
|
|
log.Info(
|
2021-12-10 16:48:50 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", cit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cit.EndTs()))
|
2021-12-10 16:48:50 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return cit.result, nil
|
|
|
|
}
|
|
|
|
|
2023-12-18 14:28:41 +08:00
|
|
|
func (node *Proxy) AlterIndex(ctx context.Context, request *milvuspb.AlterIndexRequest) (*commonpb.Status, error) {
|
2023-12-21 18:07:24 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-AlterIndex")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
task := &alterIndexTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
req: request,
|
|
|
|
datacoord: node.dataCoord,
|
|
|
|
querycoord: node.queryCoord,
|
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
|
|
|
}
|
|
|
|
|
|
|
|
method := "AlterIndex"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("indexName", request.GetIndexName()),
|
|
|
|
zap.Any("extraParams", request.ExtraParams))
|
|
|
|
|
|
|
|
log.Info(rpcReceived(method))
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(task); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.AbandonLabel).Inc()
|
|
|
|
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", task.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", task.EndTs()))
|
|
|
|
|
|
|
|
if err := task.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTs", task.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", task.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.FailLabel).Inc()
|
|
|
|
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", task.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", task.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return task.result, nil
|
2023-12-18 14:28:41 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 19:23:41 +08:00
|
|
|
// DescribeIndex get the meta information of index, such as index state, index id and etc.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) DescribeIndex(ctx context.Context, request *milvuspb.DescribeIndexRequest) (*milvuspb.DescribeIndexResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.DescribeIndexResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-10 16:52:37 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DescribeIndex")
|
|
|
|
defer sp.End()
|
2021-12-10 16:52:37 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
dit := &describeIndexTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DescribeIndexRequest: request,
|
2023-01-04 19:37:36 +08:00
|
|
|
datacoord: node.dataCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:52:37 +08:00
|
|
|
method := "DescribeIndex"
|
|
|
|
// avoid data race
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("field", request.FieldName),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("index name", request.IndexName))
|
|
|
|
|
|
|
|
log.Debug(rpcReceived(method))
|
2021-12-10 16:52:37 +08:00
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(dit); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-10 16:52:37 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.DescribeIndexResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:52:37 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
2021-12-10 16:52:37 +08:00
|
|
|
|
|
|
|
if err := dit.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-10 16:52:37 +08:00
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.DescribeIndexResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:52:37 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
2021-12-10 16:52:37 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return dit.result, nil
|
|
|
|
}
|
|
|
|
|
2023-04-23 14:50:32 +08:00
|
|
|
// GetIndexStatistics get the information of index.
|
|
|
|
func (node *Proxy) GetIndexStatistics(ctx context.Context, request *milvuspb.GetIndexStatisticsRequest) (*milvuspb.GetIndexStatisticsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-05-06 10:34:39 +08:00
|
|
|
return &milvuspb.GetIndexStatisticsResponse{
|
2023-05-10 09:31:19 +08:00
|
|
|
Status: merr.Status(err),
|
2023-05-06 10:34:39 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetIndexStatistics")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
dit := &getIndexStatisticsTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
GetIndexStatisticsRequest: request,
|
|
|
|
datacoord: node.dataCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
method := "GetIndexStatistics"
|
|
|
|
// avoid data race
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("index name", request.IndexName))
|
|
|
|
|
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(dit); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method,
|
|
|
|
metrics.AbandonLabel).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.GetIndexStatisticsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-05-06 10:34:39 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
|
|
|
|
|
|
|
if err := dit.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(rpcFailedToWaitToFinish(method), zap.Error(err), zap.Uint64("BeginTs", dit.BeginTs()), zap.Uint64("EndTs", dit.EndTs()))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.FailLabel).Inc()
|
|
|
|
return &milvuspb.GetIndexStatisticsResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Status(err),
|
2023-05-06 10:34:39 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
|
|
|
return dit.result, nil
|
2023-04-23 14:50:32 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 19:25:36 +08:00
|
|
|
// DropIndex drop the index of collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) DropIndex(ctx context.Context, request *milvuspb.DropIndexRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-10 16:46:51 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropIndex")
|
|
|
|
defer sp.End()
|
2021-12-10 16:46:51 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
dit := &dropIndexTask{
|
2023-10-20 14:26:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DropIndexRequest: request,
|
|
|
|
dataCoord: node.dataCoord,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-02-20 18:30:37 +08:00
|
|
|
}
|
2021-08-31 12:07:58 +08:00
|
|
|
|
2021-12-10 16:46:51 +08:00
|
|
|
method := "DropIndex"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-12-10 16:46:51 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("field", request.FieldName),
|
|
|
|
zap.String("index name", request.IndexName))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-10 16:46:51 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(dit); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2021-12-10 16:46:51 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-20 18:30:37 +08:00
|
|
|
}
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2021-12-10 16:46:51 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
2021-12-10 16:46:51 +08:00
|
|
|
|
|
|
|
if err := dit.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-10 16:46:51 +08:00
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-02-20 18:30:37 +08:00
|
|
|
}
|
2021-12-10 16:46:51 +08:00
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2021-12-10 16:46:51 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", dit.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dit.EndTs()))
|
2021-12-10 16:46:51 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-20 18:30:37 +08:00
|
|
|
return dit.result, nil
|
|
|
|
}
|
|
|
|
|
2023-08-31 11:39:02 +08:00
|
|
|
// GetIndexBuildProgress gets index build progress with field_name and index_name.
|
2021-04-27 15:46:45 +08:00
|
|
|
// IndexRows is the num of indexed rows. And TotalRows is the total number of segment rows.
|
2022-09-27 19:12:54 +08:00
|
|
|
// Deprecated: use DescribeIndex instead
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetIndexBuildProgress(ctx context.Context, request *milvuspb.GetIndexBuildProgressRequest) (*milvuspb.GetIndexBuildProgressResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.GetIndexBuildProgressResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-10 16:42:09 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetIndexBuildProgress")
|
|
|
|
defer sp.End()
|
2021-12-10 16:42:09 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
gibpt := &getIndexBuildProgressTask{
|
2021-04-28 11:15:28 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
GetIndexBuildProgressRequest: request,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-06-21 18:22:13 +08:00
|
|
|
dataCoord: node.dataCoord,
|
2021-04-28 11:15:28 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:42:09 +08:00
|
|
|
method := "GetIndexBuildProgress"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("field", request.FieldName),
|
|
|
|
zap.String("index name", request.IndexName))
|
2021-12-10 16:42:09 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-10 16:42:09 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(gibpt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2021-12-10 16:42:09 +08:00
|
|
|
|
2021-04-28 11:15:28 +08:00
|
|
|
return &milvuspb.GetIndexBuildProgressResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-04-28 11:15:28 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:42:09 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", gibpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", gibpt.EndTs()))
|
2021-12-10 16:42:09 +08:00
|
|
|
|
|
|
|
if err := gibpt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-04-28 11:15:28 +08:00
|
|
|
zap.Error(err),
|
2021-12-10 16:42:09 +08:00
|
|
|
zap.Uint64("BeginTs", gibpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", gibpt.EndTs()))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2021-04-28 11:15:28 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetIndexBuildProgressResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-04-28 11:15:28 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-10 16:42:09 +08:00
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", gibpt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", gibpt.EndTs()))
|
2021-04-28 11:15:28 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-04-28 11:15:28 +08:00
|
|
|
return gibpt.result, nil
|
2021-04-27 15:46:45 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 09:05:35 +08:00
|
|
|
// GetIndexState get the build-state of index.
|
2022-09-27 19:12:54 +08:00
|
|
|
// Deprecated: use DescribeIndex instead
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetIndexState(ctx context.Context, request *milvuspb.GetIndexStateRequest) (*milvuspb.GetIndexStateResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.GetIndexStateResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-10 16:59:54 +08:00
|
|
|
|
2023-06-06 10:24:34 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetIndexState")
|
2023-01-12 16:09:39 +08:00
|
|
|
defer sp.End()
|
2021-12-10 16:59:54 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
dipt := &getIndexStateTask{
|
2021-03-12 14:22:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
GetIndexStateRequest: request,
|
2023-01-04 19:37:36 +08:00
|
|
|
dataCoord: node.dataCoord,
|
2021-06-21 17:28:03 +08:00
|
|
|
rootCoord: node.rootCoord,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:59:54 +08:00
|
|
|
method := "GetIndexState"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("field", request.FieldName),
|
|
|
|
zap.String("index name", request.IndexName))
|
2021-12-10 16:59:54 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2021-12-10 16:59:54 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(dipt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-10 16:59:54 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.GetIndexStateResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:59:54 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", dipt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dipt.EndTs()))
|
2021-12-10 16:59:54 +08:00
|
|
|
|
|
|
|
if err := dipt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-10 16:59:54 +08:00
|
|
|
zap.Uint64("BeginTs", dipt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dipt.EndTs()))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.GetIndexStateResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:59:54 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", dipt.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dipt.EndTs()))
|
2021-12-10 16:59:54 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return dipt.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 09:08:08 +08:00
|
|
|
// Insert insert records into collection.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) Insert(ctx context.Context, request *milvuspb.InsertRequest) (*milvuspb.MutationResult, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Insert")
|
|
|
|
defer sp.End()
|
2021-12-06 14:19:40 +08:00
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.MutationResult{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2023-07-14 16:08:31 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName),
|
|
|
|
zap.Int("len(FieldsData)", len(request.FieldsData)),
|
|
|
|
zap.Int("len(HashKeys)", len(request.HashKeys)),
|
|
|
|
zap.Uint32("NumRows", request.NumRows),
|
|
|
|
)
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "Insert"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-05-21 22:23:24 +08:00
|
|
|
metrics.ProxyReceiveBytes.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.InsertLabel, request.GetCollectionName()).Add(float64(proto.Size(request)))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2023-01-04 17:21:36 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
it := &insertTask{
|
2021-06-21 18:22:13 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
2022-12-08 18:37:19 +08:00
|
|
|
insertMsg: &msgstream.InsertMsg{
|
2021-01-22 09:36:18 +08:00
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
HashValues: request.HashKeys,
|
|
|
|
},
|
2023-03-04 23:21:50 +08:00
|
|
|
InsertRequest: msgpb.InsertRequest{
|
2022-10-19 10:01:26 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_Insert),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
),
|
2023-06-25 17:20:43 +08:00
|
|
|
DbName: request.GetDbName(),
|
2021-01-22 09:36:18 +08:00
|
|
|
CollectionName: request.CollectionName,
|
|
|
|
PartitionName: request.PartitionName,
|
2022-03-25 14:27:25 +08:00
|
|
|
FieldsData: request.FieldsData,
|
|
|
|
NumRows: uint64(request.NumRows),
|
2023-03-04 23:21:50 +08:00
|
|
|
Version: msgpb.InsertDataVersion_ColumnBased,
|
2021-01-22 09:36:18 +08:00
|
|
|
},
|
|
|
|
},
|
2022-10-09 10:06:58 +08:00
|
|
|
idAllocator: node.rowIDAllocator,
|
2022-07-11 14:38:24 +08:00
|
|
|
segIDAssigner: node.segAssigner,
|
|
|
|
chMgr: node.chMgr,
|
|
|
|
chTicker: node.chTicker,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-08-27 10:08:47 +08:00
|
|
|
|
2021-12-06 14:19:40 +08:00
|
|
|
constructFailedResponse := func(err error) *milvuspb.MutationResult {
|
2022-03-25 14:27:25 +08:00
|
|
|
numRows := request.NumRows
|
2021-08-27 10:08:47 +08:00
|
|
|
errIndex := make([]uint32, numRows)
|
|
|
|
for i := uint32(0); i < numRows; i++ {
|
|
|
|
errIndex[i] = i
|
|
|
|
}
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-12-06 14:19:40 +08:00
|
|
|
return &milvuspb.MutationResult{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-12-06 14:19:40 +08:00
|
|
|
ErrIndex: errIndex,
|
|
|
|
}
|
2021-08-27 10:08:47 +08:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:08:31 +08:00
|
|
|
log.Debug("Enqueue insert request in Proxy")
|
2021-11-30 20:03:35 +08:00
|
|
|
|
2021-12-06 14:19:40 +08:00
|
|
|
if err := node.sched.dmQueue.Enqueue(it); err != nil {
|
2022-11-08 21:59:02 +08:00
|
|
|
log.Warn("Failed to enqueue insert task: " + err.Error())
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-04-27 23:03:47 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2021-12-06 14:19:40 +08:00
|
|
|
return constructFailedResponse(err), nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-11-30 20:03:35 +08:00
|
|
|
|
2023-07-14 16:08:31 +08:00
|
|
|
log.Debug("Detail of insert request in Proxy")
|
2021-12-06 14:19:40 +08:00
|
|
|
|
|
|
|
if err := it.WaitToFinish(); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("Failed to execute insert task in task scheduler: " + err.Error())
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2021-12-06 14:19:40 +08:00
|
|
|
return constructFailedResponse(err), nil
|
|
|
|
}
|
|
|
|
|
2023-09-12 16:07:18 +08:00
|
|
|
if it.result.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
2021-12-06 14:19:40 +08:00
|
|
|
setErrorIndex := func() {
|
2022-03-25 14:27:25 +08:00
|
|
|
numRows := request.NumRows
|
2021-12-06 14:19:40 +08:00
|
|
|
errIndex := make([]uint32, numRows)
|
|
|
|
for i := uint32(0); i < numRows; i++ {
|
|
|
|
errIndex[i] = i
|
|
|
|
}
|
|
|
|
it.result.ErrIndex = errIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
setErrorIndex()
|
2023-07-14 16:08:31 +08:00
|
|
|
log.Warn("fail to insert data", zap.Uint32s("err_index", it.result.ErrIndex))
|
2021-12-06 14:19:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// InsertCnt always equals to the number of entities in the request
|
2022-03-25 14:27:25 +08:00
|
|
|
it.result.InsertCnt = int64(request.NumRows)
|
2021-11-30 20:03:35 +08:00
|
|
|
|
2023-10-18 02:16:11 +08:00
|
|
|
rateCol.Add(internalpb.RateType_DMLInsert.String(), float64(it.insertMsg.Size()))
|
2023-01-04 17:21:36 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-06-02 16:06:03 +08:00
|
|
|
successCnt := it.result.InsertCnt - int64(len(it.result.ErrIndex))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyInsertVectors.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(successCnt))
|
|
|
|
metrics.ProxyMutationLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), metrics.InsertLabel).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
metrics.ProxyCollectionMutationLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), metrics.InsertLabel, request.CollectionName).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-22 09:36:18 +08:00
|
|
|
return it.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 09:10:20 +08:00
|
|
|
// Delete delete records from collection, then these records cannot be searched.
|
2021-08-26 12:15:52 +08:00
|
|
|
func (node *Proxy) Delete(ctx context.Context, request *milvuspb.DeleteRequest) (*milvuspb.MutationResult, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Delete")
|
|
|
|
defer sp.End()
|
2023-07-14 16:08:31 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName),
|
|
|
|
zap.String("expr", request.Expr),
|
|
|
|
)
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("Start processing delete request in Proxy")
|
|
|
|
defer log.Debug("Finish processing delete request in Proxy")
|
2021-10-09 22:50:39 +08:00
|
|
|
|
2023-05-21 22:23:24 +08:00
|
|
|
metrics.ProxyReceiveBytes.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.DeleteLabel, request.GetCollectionName()).Add(float64(proto.Size(request)))
|
2022-06-02 16:06:03 +08:00
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-08-26 12:15:52 +08:00
|
|
|
return &milvuspb.MutationResult{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-26 12:15:52 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "Delete"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-04-27 23:03:47 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2021-08-26 12:15:52 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
dr := &deleteRunner{
|
|
|
|
req: request,
|
|
|
|
idAllocator: node.rowIDAllocator,
|
|
|
|
tsoAllocatorIns: node.tsoAllocator,
|
|
|
|
chMgr: node.chMgr,
|
|
|
|
chTicker: node.chTicker,
|
|
|
|
queue: node.sched.dmQueue,
|
|
|
|
lb: node.lbPolicy,
|
|
|
|
}
|
2021-10-09 22:50:39 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
log.Debug("init delete runner in Proxy")
|
|
|
|
if err := dr.Init(ctx); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("Failed to enqueue delete task: " + err.Error())
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-08-26 12:15:52 +08:00
|
|
|
return &milvuspb.MutationResult{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-26 12:15:52 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
log.Debug("Run delete in Proxy")
|
2021-08-26 12:15:52 +08:00
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
if err := dr.Run(ctx); err != nil {
|
|
|
|
log.Error("Failed to enqueue delete task: " + err.Error())
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2024-01-17 19:16:55 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2023-12-26 19:52:48 +08:00
|
|
|
|
2021-08-26 12:15:52 +08:00
|
|
|
return &milvuspb.MutationResult{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-26 12:15:52 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-12-26 19:52:48 +08:00
|
|
|
receiveSize := proto.Size(dr.req)
|
2023-01-04 17:21:36 +08:00
|
|
|
rateCol.Add(internalpb.RateType_DMLDelete.String(), float64(receiveSize))
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyMutationLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), metrics.DeleteLabel).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
metrics.ProxyCollectionMutationLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), metrics.DeleteLabel, request.CollectionName).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2023-12-26 19:52:48 +08:00
|
|
|
return dr.result, nil
|
2021-08-26 12:15:52 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 17:21:36 +08:00
|
|
|
// Upsert upsert records into collection.
|
|
|
|
func (node *Proxy) Upsert(ctx context.Context, request *milvuspb.UpsertRequest) (*milvuspb.MutationResult, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Upsert")
|
|
|
|
defer sp.End()
|
2023-01-04 17:21:36 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.String("partition", request.PartitionName),
|
|
|
|
zap.Uint32("NumRows", request.NumRows),
|
|
|
|
)
|
|
|
|
log.Debug("Start processing upsert request in Proxy")
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-01-04 17:21:36 +08:00
|
|
|
return &milvuspb.MutationResult{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-04 17:21:36 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
method := "Upsert"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
|
2023-05-21 22:23:24 +08:00
|
|
|
metrics.ProxyReceiveBytes.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.UpsertLabel, request.GetCollectionName()).Add(float64(proto.Size(request)))
|
2023-01-04 17:21:36 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
request.Base = commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_Upsert),
|
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
|
|
|
)
|
|
|
|
|
2023-01-04 17:21:36 +08:00
|
|
|
it := &upsertTask{
|
|
|
|
baseMsg: msgstream.BaseMsg{
|
|
|
|
HashValues: request.HashKeys,
|
|
|
|
},
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
2023-06-25 17:20:43 +08:00
|
|
|
req: request,
|
2023-01-04 17:21:36 +08:00
|
|
|
result: &milvuspb.MutationResult{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-01-04 17:21:36 +08:00
|
|
|
IDs: &schemapb.IDs{
|
|
|
|
IdField: nil,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
idAllocator: node.rowIDAllocator,
|
|
|
|
segIDAssigner: node.segAssigner,
|
|
|
|
chMgr: node.chMgr,
|
|
|
|
chTicker: node.chTicker,
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Enqueue upsert request in Proxy",
|
|
|
|
zap.Int("len(FieldsData)", len(request.FieldsData)),
|
|
|
|
zap.Int("len(HashKeys)", len(request.HashKeys)))
|
|
|
|
|
|
|
|
if err := node.sched.dmQueue.Enqueue(it); err != nil {
|
|
|
|
log.Info("Failed to enqueue upsert task",
|
|
|
|
zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.AbandonLabel).Inc()
|
|
|
|
return &milvuspb.MutationResult{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-04 17:21:36 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("Detail of upsert request in Proxy",
|
|
|
|
zap.Uint64("BeginTS", it.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", it.EndTs()))
|
|
|
|
|
|
|
|
if err := it.WaitToFinish(); err != nil {
|
|
|
|
log.Info("Failed to execute insert task in task scheduler",
|
|
|
|
zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.FailLabel).Inc()
|
2023-03-06 14:29:51 +08:00
|
|
|
// Not every error case changes the status internally
|
|
|
|
// change status there to handle it
|
2023-09-12 16:07:18 +08:00
|
|
|
if it.result.GetStatus().GetErrorCode() == commonpb.ErrorCode_Success {
|
2023-09-26 17:15:27 +08:00
|
|
|
it.result.Status = merr.Status(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
numRows := request.NumRows
|
|
|
|
errIndex := make([]uint32, numRows)
|
|
|
|
for i := uint32(0); i < numRows; i++ {
|
|
|
|
errIndex[i] = i
|
2023-03-06 14:29:51 +08:00
|
|
|
}
|
2023-09-26 17:15:27 +08:00
|
|
|
|
|
|
|
return &milvuspb.MutationResult{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
ErrIndex: errIndex,
|
|
|
|
}, nil
|
2023-01-04 17:21:36 +08:00
|
|
|
}
|
|
|
|
|
2023-09-12 16:07:18 +08:00
|
|
|
if it.result.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
2023-01-04 17:21:36 +08:00
|
|
|
setErrorIndex := func() {
|
|
|
|
numRows := request.NumRows
|
|
|
|
errIndex := make([]uint32, numRows)
|
|
|
|
for i := uint32(0); i < numRows; i++ {
|
|
|
|
errIndex[i] = i
|
|
|
|
}
|
|
|
|
it.result.ErrIndex = errIndex
|
|
|
|
}
|
|
|
|
setErrorIndex()
|
|
|
|
}
|
|
|
|
|
2024-01-03 10:06:48 +08:00
|
|
|
// UpsertCnt always equals to the number of entities in the request
|
|
|
|
it.result.UpsertCnt = int64(request.NumRows)
|
|
|
|
|
2023-10-18 02:16:11 +08:00
|
|
|
rateCol.Add(internalpb.RateType_DMLUpsert.String(), float64(it.upsertMsg.DeleteMsg.Size()+it.upsertMsg.DeleteMsg.Size()))
|
2023-01-04 17:21:36 +08:00
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
2024-01-03 10:06:48 +08:00
|
|
|
successCnt := it.result.UpsertCnt - int64(len(it.result.ErrIndex))
|
|
|
|
metrics.ProxyUpsertVectors.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(successCnt))
|
2023-01-04 17:21:36 +08:00
|
|
|
metrics.ProxyMutationLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), metrics.UpsertLabel).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
metrics.ProxyCollectionMutationLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), metrics.UpsertLabel, request.CollectionName).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
|
|
|
log.Debug("Finish processing upsert request in Proxy")
|
|
|
|
return it.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:19:31 +08:00
|
|
|
// Search search the most similar records of requests.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) Search(ctx context.Context, request *milvuspb.SearchRequest) (*milvuspb.SearchResults, error) {
|
2022-09-16 09:56:47 +08:00
|
|
|
receiveSize := proto.Size(request)
|
2023-05-21 22:23:24 +08:00
|
|
|
metrics.ProxyReceiveBytes.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.SearchLabel,
|
|
|
|
request.GetCollectionName(),
|
|
|
|
).Add(float64(receiveSize))
|
2023-05-21 22:23:24 +08:00
|
|
|
|
|
|
|
metrics.ProxyReceivedNQ.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.SearchLabel,
|
|
|
|
request.GetCollectionName(),
|
|
|
|
).Add(float64(request.GetNq()))
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
rateCol.Add(internalpb.RateType_DQLSearch.String(), float64(request.GetNq()))
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.SearchResults{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2023-10-16 15:34:08 +08:00
|
|
|
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "Search"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2021-11-29 18:07:42 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Search")
|
|
|
|
defer sp.End()
|
2021-11-29 18:07:42 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
if request.SearchByPrimaryKeys {
|
|
|
|
placeholderGroupBytes, err := node.getVectorPlaceholderGroupForSearchByPks(ctx, request)
|
|
|
|
if err != nil {
|
|
|
|
return &milvuspb.SearchResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
request.PlaceholderGroup = placeholderGroupBytes
|
|
|
|
}
|
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
qt := &searchTask{
|
2021-02-23 09:58:06 +08:00
|
|
|
ctx: ctx,
|
2021-01-22 09:36:18 +08:00
|
|
|
Condition: NewTaskCondition(ctx),
|
2021-03-12 14:22:09 +08:00
|
|
|
SearchRequest: &internalpb.SearchRequest{
|
2022-10-19 10:01:26 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_Search),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
),
|
2022-11-04 14:25:38 +08:00
|
|
|
ReqID: paramtable.GetNodeID(),
|
2021-01-22 09:36:18 +08:00
|
|
|
},
|
2023-06-13 10:20:37 +08:00
|
|
|
request: request,
|
|
|
|
tr: timerecord.NewTimeRecorder("search"),
|
|
|
|
qc: node.queryCoord,
|
|
|
|
node: node,
|
|
|
|
lb: node.lbPolicy,
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 19:49:02 +08:00
|
|
|
guaranteeTs := request.GuaranteeTimestamp
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.Any("partitions", request.PartitionNames),
|
|
|
|
zap.Any("dsl", request.Dsl),
|
|
|
|
zap.Any("len(PlaceholderGroup)", len(request.PlaceholderGroup)),
|
2021-12-21 19:49:02 +08:00
|
|
|
zap.Any("OutputFields", request.OutputFields),
|
|
|
|
zap.Any("search_params", request.SearchParams),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("guarantee_timestamp", guaranteeTs),
|
|
|
|
)
|
2021-11-29 18:07:42 +08:00
|
|
|
|
2023-04-14 15:30:29 +08:00
|
|
|
defer func() {
|
|
|
|
span := tr.ElapseSpan()
|
|
|
|
if span >= SlowReadSpan {
|
2023-11-30 10:42:27 +08:00
|
|
|
log.Info(rpcSlow(method), zap.Int64("nq", qt.SearchRequest.GetNq()), zap.Duration("duration", span))
|
2023-04-14 15:30:29 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2023-08-10 18:53:17 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-21 19:49:02 +08:00
|
|
|
if err := node.sched.dqQueue.Enqueue(qt); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn(
|
2021-12-21 19:49:02 +08:00
|
|
|
rpcFailedToEnqueue(method),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Error(err),
|
|
|
|
)
|
2021-11-29 18:07:42 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.AbandonLabel,
|
|
|
|
).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.SearchResults{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-08-23 10:44:52 +08:00
|
|
|
tr.CtxRecord(ctx, "search request enqueue")
|
2021-01-22 09:36:18 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(
|
2021-12-21 19:49:02 +08:00
|
|
|
rpcEnqueued(method),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("timestamp", qt.Base.Timestamp),
|
|
|
|
)
|
2021-11-29 18:07:42 +08:00
|
|
|
|
2021-12-21 19:49:02 +08:00
|
|
|
if err := qt.WaitToFinish(); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn(
|
2021-12-21 19:49:02 +08:00
|
|
|
rpcFailedToWaitToFinish(method),
|
2023-11-30 10:42:27 +08:00
|
|
|
zap.Int64("nq", qt.SearchRequest.GetNq()),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Error(err),
|
|
|
|
)
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.FailLabel,
|
|
|
|
).Inc()
|
2021-06-11 09:50:34 +08:00
|
|
|
|
2021-01-22 09:36:18 +08:00
|
|
|
return &milvuspb.SearchResults{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-01-22 09:36:18 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-08-23 10:44:52 +08:00
|
|
|
span := tr.CtxRecord(ctx, "wait search result")
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyWaitForSearchResultLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.SearchLabel,
|
|
|
|
).Observe(float64(span.Milliseconds()))
|
|
|
|
|
2022-10-18 19:17:27 +08:00
|
|
|
tr.CtxRecord(ctx, "wait search result")
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcDone(method))
|
2021-11-29 18:07:42 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxySearchVectors.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(qt.result.GetResults().GetNumQueries()))
|
2023-10-16 15:34:08 +08:00
|
|
|
|
2022-03-04 15:45:56 +08:00
|
|
|
searchDur := tr.ElapseSpan().Milliseconds()
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxySQLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.SearchLabel,
|
|
|
|
).Observe(float64(searchDur))
|
|
|
|
|
|
|
|
metrics.ProxyCollectionSQLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.SearchLabel,
|
|
|
|
request.CollectionName,
|
|
|
|
).Observe(float64(searchDur))
|
|
|
|
|
2022-06-02 16:06:03 +08:00
|
|
|
if qt.result != nil {
|
|
|
|
sentSize := proto.Size(qt.result)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReadReqSendBytes.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(sentSize))
|
2022-10-13 14:57:24 +08:00
|
|
|
rateCol.Add(metricsinfo.ReadResultThroughput, float64(sentSize))
|
2022-06-02 16:06:03 +08:00
|
|
|
}
|
2021-01-22 09:36:18 +08:00
|
|
|
return qt.result, nil
|
|
|
|
}
|
|
|
|
|
2024-01-04 19:22:46 +08:00
|
|
|
func (node *Proxy) HybridSearch(ctx context.Context, request *milvuspb.HybridSearchRequest) (*milvuspb.SearchResults, error) {
|
2024-01-08 15:34:48 +08:00
|
|
|
receiveSize := proto.Size(request)
|
|
|
|
metrics.ProxyReceiveBytes.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.HybridSearchLabel,
|
|
|
|
request.GetCollectionName(),
|
|
|
|
).Add(float64(receiveSize))
|
|
|
|
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.SearchResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
method := "HybridSearch"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-HybridSearch")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
qt := &hybridSearchTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
request: request,
|
|
|
|
tr: timerecord.NewTimeRecorder(method),
|
|
|
|
qc: node.queryCoord,
|
|
|
|
node: node,
|
|
|
|
lb: node.lbPolicy,
|
|
|
|
}
|
|
|
|
|
|
|
|
guaranteeTs := request.GuaranteeTimestamp
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
|
|
|
zap.Any("partitions", request.PartitionNames),
|
|
|
|
zap.Any("OutputFields", request.OutputFields),
|
|
|
|
zap.Uint64("guarantee_timestamp", guaranteeTs),
|
|
|
|
)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
span := tr.ElapseSpan()
|
|
|
|
if span >= SlowReadSpan {
|
|
|
|
log.Info(rpcSlow(method), zap.Duration("duration", span))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
|
|
|
if err := node.sched.dqQueue.Enqueue(qt); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.AbandonLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.SearchResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
tr.CtxRecord(ctx, "hybrid search request enqueue")
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("timestamp", qt.request.Base.Timestamp),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := qt.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.FailLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.SearchResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
span := tr.CtxRecord(ctx, "wait hybrid search result")
|
|
|
|
metrics.ProxyWaitForSearchResultLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.HybridSearchLabel,
|
|
|
|
).Observe(float64(span.Milliseconds()))
|
|
|
|
|
|
|
|
tr.CtxRecord(ctx, "wait hybrid search result")
|
|
|
|
log.Debug(rpcDone(method))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
metrics.ProxySearchVectors.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(len(qt.request.GetRequests())))
|
|
|
|
|
|
|
|
searchDur := tr.ElapseSpan().Milliseconds()
|
|
|
|
metrics.ProxySQLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.HybridSearchLabel,
|
|
|
|
).Observe(float64(searchDur))
|
|
|
|
|
|
|
|
metrics.ProxyCollectionSQLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.HybridSearchLabel,
|
|
|
|
request.CollectionName,
|
|
|
|
).Observe(float64(searchDur))
|
|
|
|
|
|
|
|
if qt.result != nil {
|
|
|
|
sentSize := proto.Size(qt.result)
|
|
|
|
metrics.ProxyReadReqSendBytes.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(sentSize))
|
|
|
|
rateCol.Add(metricsinfo.ReadResultThroughput, float64(sentSize))
|
|
|
|
}
|
|
|
|
return qt.result, nil
|
2023-12-18 14:28:41 +08:00
|
|
|
}
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
func (node *Proxy) getVectorPlaceholderGroupForSearchByPks(ctx context.Context, request *milvuspb.SearchRequest) ([]byte, error) {
|
|
|
|
placeholderGroup := &commonpb.PlaceholderGroup{}
|
|
|
|
err := proto.Unmarshal(request.PlaceholderGroup, placeholderGroup)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(placeholderGroup.Placeholders) != 1 || len(placeholderGroup.Placeholders[0].Values) != 1 {
|
|
|
|
return nil, merr.WrapErrParameterInvalidMsg("please provide primary key")
|
|
|
|
}
|
|
|
|
queryExpr := string(placeholderGroup.Placeholders[0].Values[0])
|
|
|
|
|
|
|
|
annsField, err := funcutil.GetAttrByKeyFromRepeatedKV(AnnsFieldKey, request.SearchParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
queryRequest := &milvuspb.QueryRequest{
|
|
|
|
Base: request.Base,
|
|
|
|
DbName: request.DbName,
|
|
|
|
CollectionName: request.CollectionName,
|
|
|
|
Expr: queryExpr,
|
|
|
|
OutputFields: []string{annsField},
|
|
|
|
PartitionNames: request.PartitionNames,
|
|
|
|
TravelTimestamp: request.TravelTimestamp,
|
|
|
|
GuaranteeTimestamp: request.GuaranteeTimestamp,
|
|
|
|
QueryParams: nil,
|
|
|
|
NotReturnAllMeta: request.NotReturnAllMeta,
|
|
|
|
ConsistencyLevel: request.ConsistencyLevel,
|
|
|
|
UseDefaultConsistency: request.UseDefaultConsistency,
|
|
|
|
}
|
|
|
|
|
|
|
|
queryResults, _ := node.Query(ctx, queryRequest)
|
|
|
|
|
|
|
|
err = merr.Error(queryResults.GetStatus())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var vectorFieldsData *schemapb.FieldData
|
|
|
|
for _, fieldsData := range queryResults.GetFieldsData() {
|
|
|
|
if fieldsData.GetFieldName() == annsField {
|
|
|
|
vectorFieldsData = fieldsData
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
placeholderGroupBytes, err := funcutil.FieldDataToPlaceholderGroupBytes(vectorFieldsData)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return placeholderGroupBytes, nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 19:23:40 +08:00
|
|
|
// Flush notify data nodes to persist the data of collection.
|
2021-06-23 16:56:11 +08:00
|
|
|
func (node *Proxy) Flush(ctx context.Context, request *milvuspb.FlushRequest) (*milvuspb.FlushResponse, error) {
|
|
|
|
resp := &milvuspb.FlushResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2021-06-23 16:56:11 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-06-23 16:56:11 +08:00
|
|
|
return resp, nil
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
2021-12-10 17:01:42 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Flush")
|
|
|
|
defer sp.End()
|
2021-12-10 17:01:42 +08:00
|
|
|
|
2021-09-11 11:36:22 +08:00
|
|
|
ft := &flushTask{
|
2023-10-20 14:26:09 +08:00
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
FlushRequest: request,
|
|
|
|
dataCoord: node.dataCoord,
|
|
|
|
replicateMsgStream: node.replicateMsgStream,
|
2021-02-03 17:30:10 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 17:01:42 +08:00
|
|
|
method := "Flush"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2021-12-10 17:01:42 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-08-31 12:07:58 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.Any("collections", request.CollectionNames))
|
2021-12-10 17:01:42 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
2023-10-13 18:33:36 +08:00
|
|
|
if err := node.sched.dcQueue.Enqueue(ft); err != nil {
|
2021-12-10 17:01:42 +08:00
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-10 17:01:42 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-06-23 16:56:11 +08:00
|
|
|
return resp, nil
|
2021-02-03 17:30:10 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 17:01:42 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", ft.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", ft.EndTs()))
|
2021-12-10 17:01:42 +08:00
|
|
|
|
|
|
|
if err := ft.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.Error(err),
|
2021-12-10 17:01:42 +08:00
|
|
|
zap.Uint64("BeginTs", ft.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", ft.EndTs()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-06-23 16:56:11 +08:00
|
|
|
return resp, nil
|
2021-02-03 17:30:10 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 17:01:42 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", ft.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", ft.EndTs()))
|
2021-12-10 17:01:42 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-03 17:30:10 +08:00
|
|
|
return ft.result, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
|
|
|
|
2021-11-16 19:25:35 +08:00
|
|
|
// Query get the records by primary keys.
|
2023-10-26 19:30:10 +08:00
|
|
|
func (node *Proxy) query(ctx context.Context, qt *queryTask) (*milvuspb.QueryResults, error) {
|
|
|
|
request := qt.request
|
2022-09-16 09:56:47 +08:00
|
|
|
receiveSize := proto.Size(request)
|
2023-05-21 22:23:24 +08:00
|
|
|
metrics.ProxyReceiveBytes.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.QueryLabel,
|
|
|
|
request.GetCollectionName(),
|
|
|
|
).Add(float64(receiveSize))
|
2023-05-21 22:23:24 +08:00
|
|
|
|
|
|
|
metrics.ProxyReceivedNQ.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.SearchLabel,
|
|
|
|
request.GetCollectionName(),
|
|
|
|
).Add(float64(1))
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
rateCol.Add(internalpb.RateType_DQLQuery.String(), 1)
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-06-22 10:36:08 +08:00
|
|
|
return &milvuspb.QueryResults{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-06-22 10:36:08 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-08-16 17:06:10 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Query")
|
|
|
|
defer sp.End()
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("Query")
|
2021-12-15 10:19:10 +08:00
|
|
|
|
|
|
|
method := "Query"
|
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.TotalLabel,
|
|
|
|
).Inc()
|
2022-04-27 23:03:47 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-12-29 21:29:45 +08:00
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("collection", request.CollectionName),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Strings("partitions", request.PartitionNames),
|
|
|
|
)
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2023-04-14 15:30:29 +08:00
|
|
|
defer func() {
|
|
|
|
span := tr.ElapseSpan()
|
|
|
|
if span >= SlowReadSpan {
|
|
|
|
log.Info(
|
|
|
|
rpcSlow(method),
|
|
|
|
zap.String("expr", request.Expr),
|
|
|
|
zap.Strings("OutputFields", request.OutputFields),
|
|
|
|
zap.Uint64("travel_timestamp", request.TravelTimestamp),
|
|
|
|
zap.Uint64("guarantee_timestamp", request.GuaranteeTimestamp),
|
|
|
|
zap.Duration("duration", span))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcReceived(method),
|
2022-06-23 13:42:13 +08:00
|
|
|
zap.String("expr", request.Expr),
|
|
|
|
zap.Strings("OutputFields", request.OutputFields),
|
|
|
|
zap.Uint64("travel_timestamp", request.TravelTimestamp),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Uint64("guarantee_timestamp", request.GuaranteeTimestamp),
|
|
|
|
)
|
2021-08-31 12:07:58 +08:00
|
|
|
|
2021-12-15 10:19:10 +08:00
|
|
|
if err := node.sched.dqQueue.Enqueue(qt); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn(
|
2021-12-15 10:19:10 +08:00
|
|
|
rpcFailedToEnqueue(method),
|
2023-10-16 15:34:08 +08:00
|
|
|
zap.Error(err),
|
|
|
|
)
|
2021-12-15 10:19:10 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.AbandonLabel,
|
|
|
|
).Inc()
|
2022-04-27 23:03:47 +08:00
|
|
|
|
2021-08-16 17:06:10 +08:00
|
|
|
return &milvuspb.QueryResults{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-16 17:06:10 +08:00
|
|
|
}, nil
|
2021-06-24 16:44:07 +08:00
|
|
|
}
|
2022-08-23 10:44:52 +08:00
|
|
|
tr.CtxRecord(ctx, "query request enqueue")
|
2021-06-24 16:44:07 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcEnqueued(method))
|
2021-12-15 10:19:10 +08:00
|
|
|
|
|
|
|
if err := qt.WaitToFinish(); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn(
|
2021-12-15 10:19:10 +08:00
|
|
|
rpcFailedToWaitToFinish(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-06-07 17:21:36 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-04-27 23:03:47 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2021-08-16 17:06:10 +08:00
|
|
|
return &milvuspb.QueryResults{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-16 17:06:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-08-23 10:44:52 +08:00
|
|
|
span := tr.CtxRecord(ctx, "wait query result")
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyWaitForSearchResultLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.QueryLabel,
|
|
|
|
).Observe(float64(span.Milliseconds()))
|
2022-10-18 19:17:27 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug(rpcDone(method))
|
2021-12-15 10:19:10 +08:00
|
|
|
|
2023-10-16 15:34:08 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
method,
|
|
|
|
metrics.SuccessLabel,
|
|
|
|
).Inc()
|
|
|
|
|
|
|
|
metrics.ProxySQLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.QueryLabel,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
|
|
|
metrics.ProxyCollectionSQLatency.WithLabelValues(
|
|
|
|
strconv.FormatInt(paramtable.GetNodeID(), 10),
|
|
|
|
metrics.QueryLabel,
|
|
|
|
request.CollectionName,
|
|
|
|
).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-04-27 23:03:47 +08:00
|
|
|
|
2022-06-02 16:06:03 +08:00
|
|
|
sentSize := proto.Size(qt.result)
|
2022-10-13 14:57:24 +08:00
|
|
|
rateCol.Add(metricsinfo.ReadResultThroughput, float64(sentSize))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReadReqSendBytes.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Add(float64(sentSize))
|
2023-10-16 15:34:08 +08:00
|
|
|
|
2023-05-25 11:39:26 +08:00
|
|
|
return qt.result, nil
|
2021-08-16 17:06:10 +08:00
|
|
|
}
|
2021-06-22 18:42:03 +08:00
|
|
|
|
2023-10-26 19:30:10 +08:00
|
|
|
// Query get the records by primary keys.
|
|
|
|
func (node *Proxy) Query(ctx context.Context, request *milvuspb.QueryRequest) (*milvuspb.QueryResults, error) {
|
|
|
|
qt := &queryTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
RetrieveRequest: &internalpb.RetrieveRequest{
|
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_Retrieve),
|
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
|
|
|
),
|
|
|
|
ReqID: paramtable.GetNodeID(),
|
|
|
|
},
|
|
|
|
request: request,
|
|
|
|
qc: node.queryCoord,
|
|
|
|
lb: node.lbPolicy,
|
|
|
|
}
|
|
|
|
return node.query(ctx, qt)
|
|
|
|
}
|
|
|
|
|
2021-11-17 19:51:24 +08:00
|
|
|
// CreateAlias create alias for collection, then you can search the collection with alias.
|
2021-09-18 11:13:51 +08:00
|
|
|
func (node *Proxy) CreateAlias(ctx context.Context, request *milvuspb.CreateAliasRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2021-12-15 07:03:10 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateAlias")
|
|
|
|
defer sp.End()
|
2021-12-15 07:03:10 +08:00
|
|
|
|
2021-09-18 11:13:51 +08:00
|
|
|
cat := &CreateAliasTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
CreateAliasRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
2021-12-15 07:03:10 +08:00
|
|
|
method := "CreateAlias"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2021-12-15 07:03:10 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-15 07:03:10 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("alias", request.Alias),
|
|
|
|
zap.String("collection", request.CollectionName))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-15 07:03:10 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(cat); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2021-12-15 07:03:10 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 07:03:10 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", cat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cat.EndTs()))
|
2021-12-15 07:03:10 +08:00
|
|
|
|
|
|
|
if err := cat.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-09-18 11:13:51 +08:00
|
|
|
zap.Error(err),
|
2021-12-15 07:03:10 +08:00
|
|
|
zap.Uint64("BeginTs", cat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cat.EndTs()))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2021-09-18 11:13:51 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2021-12-15 07:03:10 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", cat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", cat.EndTs()))
|
2021-12-15 07:03:10 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-09-18 11:13:51 +08:00
|
|
|
return cat.result, nil
|
|
|
|
}
|
|
|
|
|
2024-01-11 19:12:51 +08:00
|
|
|
// DescribeAlias describe alias of collection.
|
2023-03-30 11:28:25 +08:00
|
|
|
func (node *Proxy) DescribeAlias(ctx context.Context, request *milvuspb.DescribeAliasRequest) (*milvuspb.DescribeAliasResponse, error) {
|
2024-01-11 19:12:51 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.DescribeAliasResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DescribeAlias")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
dat := &DescribeAliasTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
nodeID: node.session.ServerID,
|
|
|
|
DescribeAliasRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
method := "DescribeAlias"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.TotalLabel).Inc()
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("alias", request.Alias))
|
|
|
|
|
|
|
|
log.Debug(rpcReceived(method))
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(dat); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.AbandonLabel).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.DescribeAliasResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", dat.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", dat.EndTs()))
|
|
|
|
|
|
|
|
if err := dat.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(rpcFailedToWaitToFinish(method), zap.Uint64("BeginTs", dat.BeginTs()), zap.Uint64("EndTs", dat.EndTs()), zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.FailLabel).Inc()
|
|
|
|
return &milvuspb.DescribeAliasResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", dat.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", dat.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return dat.result, nil
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
|
|
|
|
2024-01-11 19:12:51 +08:00
|
|
|
// ListAliases show all aliases of db.
|
2023-03-30 11:28:25 +08:00
|
|
|
func (node *Proxy) ListAliases(ctx context.Context, request *milvuspb.ListAliasesRequest) (*milvuspb.ListAliasesResponse, error) {
|
2024-01-11 19:12:51 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.ListAliasesResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ListAliases")
|
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
lat := &ListAliasesTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
nodeID: node.session.ServerID,
|
|
|
|
ListAliasesRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
method := "ListAliases"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.TotalLabel).Inc()
|
|
|
|
|
|
|
|
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(lat); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
|
|
|
zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.AbandonLabel).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.ListAliasesResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", lat.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", lat.EndTs()))
|
|
|
|
|
|
|
|
if err := lat.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(rpcFailedToWaitToFinish(method), zap.Uint64("BeginTs", lat.BeginTs()), zap.Uint64("EndTs", lat.EndTs()), zap.Error(err))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.FailLabel).Inc()
|
|
|
|
return &milvuspb.ListAliasesResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(
|
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", lat.BeginTs()),
|
|
|
|
zap.Uint64("EndTs", lat.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(node.session.ServerID, 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return lat.result, nil
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
|
|
|
|
2021-11-17 19:53:18 +08:00
|
|
|
// DropAlias alter the alias of collection.
|
2021-09-18 11:13:51 +08:00
|
|
|
func (node *Proxy) DropAlias(ctx context.Context, request *milvuspb.DropAliasRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2021-12-15 10:31:52 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropAlias")
|
|
|
|
defer sp.End()
|
2021-12-15 10:31:52 +08:00
|
|
|
|
2021-09-18 11:13:51 +08:00
|
|
|
dat := &DropAliasTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DropAliasRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
2021-12-15 10:31:52 +08:00
|
|
|
method := "DropAlias"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2021-12-15 10:31:52 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-15 10:31:52 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("alias", request.Alias))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-15 10:31:52 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(dat); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2021-12-15 10:31:52 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 10:31:52 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", dat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dat.EndTs()))
|
2021-12-15 10:31:52 +08:00
|
|
|
|
|
|
|
if err := dat.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-09-18 11:13:51 +08:00
|
|
|
zap.Error(err),
|
2021-12-15 10:31:52 +08:00
|
|
|
zap.Uint64("BeginTs", dat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dat.EndTs()))
|
2021-09-18 11:13:51 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2021-12-15 10:31:52 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", dat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", dat.EndTs()))
|
2021-12-15 10:31:52 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-09-18 11:13:51 +08:00
|
|
|
return dat.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-17 19:57:12 +08:00
|
|
|
// AlterAlias alter alias of collection.
|
2021-09-18 11:13:51 +08:00
|
|
|
func (node *Proxy) AlterAlias(ctx context.Context, request *milvuspb.AlterAliasRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2021-12-15 10:25:33 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-AlterAlias")
|
|
|
|
defer sp.End()
|
2021-12-15 10:25:33 +08:00
|
|
|
|
2021-09-18 11:13:51 +08:00
|
|
|
aat := &AlterAliasTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
AlterAliasRequest: request,
|
|
|
|
rootCoord: node.rootCoord,
|
|
|
|
}
|
|
|
|
|
2021-12-15 10:25:33 +08:00
|
|
|
method := "AlterAlias"
|
2022-03-02 16:23:55 +08:00
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.TotalLabel).Inc()
|
2021-12-15 10:25:33 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-15 10:25:33 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("db", request.DbName),
|
|
|
|
zap.String("alias", request.Alias),
|
|
|
|
zap.String("collection", request.CollectionName))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(rpcReceived(method))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2021-12-15 10:25:33 +08:00
|
|
|
if err := node.sched.ddQueue.Enqueue(aat); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToEnqueue(method),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.AbandonLabel).Inc()
|
2021-12-15 10:25:33 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 10:25:33 +08:00
|
|
|
log.Debug(
|
|
|
|
rpcEnqueued(method),
|
|
|
|
zap.Uint64("BeginTs", aat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", aat.EndTs()))
|
2021-12-15 10:25:33 +08:00
|
|
|
|
|
|
|
if err := aat.WaitToFinish(); err != nil {
|
|
|
|
log.Warn(
|
|
|
|
rpcFailedToWaitToFinish(method),
|
2021-09-18 11:13:51 +08:00
|
|
|
zap.Error(err),
|
2021-12-15 10:25:33 +08:00
|
|
|
zap.Uint64("BeginTs", aat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", aat.EndTs()))
|
2021-09-18 11:13:51 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-03-02 16:23:55 +08:00
|
|
|
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info(
|
2021-12-15 10:25:33 +08:00
|
|
|
rpcDone(method),
|
|
|
|
zap.Uint64("BeginTs", aat.BeginTs()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Uint64("EndTs", aat.EndTs()))
|
2021-12-15 10:25:33 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-09-18 11:13:51 +08:00
|
|
|
return aat.result, nil
|
|
|
|
}
|
|
|
|
|
2021-11-18 21:24:38 +08:00
|
|
|
// CalcDistance calculates the distances between vectors.
|
2021-08-16 17:06:10 +08:00
|
|
|
func (node *Proxy) CalcDistance(ctx context.Context, request *milvuspb.CalcDistanceRequest) (*milvuspb.CalcDistanceResults, error) {
|
2023-07-18 14:23:20 +08:00
|
|
|
return &milvuspb.CalcDistanceResults{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrServiceUnavailable("CalcDistance deprecated")),
|
2023-07-18 14:23:20 +08:00
|
|
|
}, nil
|
2021-07-01 18:56:17 +08:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:28:25 +08:00
|
|
|
// FlushAll notifies Proxy to flush all collection's DML messages.
|
2023-09-06 10:35:48 +08:00
|
|
|
func (node *Proxy) FlushAll(ctx context.Context, req *milvuspb.FlushAllRequest) (*milvuspb.FlushAllResponse, error) {
|
2023-03-30 11:28:25 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-FlushAll")
|
|
|
|
defer sp.End()
|
2023-09-06 10:35:48 +08:00
|
|
|
log := log.With(zap.String("db", req.GetDbName()))
|
2023-03-30 11:28:25 +08:00
|
|
|
|
|
|
|
resp := &milvuspb.FlushAllResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-03-30 11:28:25 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
log.Info(rpcReceived("FlushAll"))
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
hasError := func(status *commonpb.Status, err error) bool {
|
|
|
|
if err != nil {
|
2023-09-01 15:23:01 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-09-15 10:09:21 +08:00
|
|
|
log.Warn("FlushAll failed", zap.Error(err))
|
2023-06-25 17:20:43 +08:00
|
|
|
return true
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
2023-09-15 10:09:21 +08:00
|
|
|
if status.GetErrorCode() != commonpb.ErrorCode_Success {
|
2023-06-25 17:20:43 +08:00
|
|
|
log.Warn("FlushAll failed", zap.String("err", status.GetReason()))
|
|
|
|
resp.Status = status
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
dbsRsp, err := node.rootCoord.ListDatabases(ctx, &milvuspb.ListDatabasesRequest{
|
|
|
|
Base: commonpbutil.NewMsgBase(commonpbutil.WithMsgType(commonpb.MsgType_ListDatabases)),
|
2023-03-30 11:28:25 +08:00
|
|
|
})
|
2023-06-25 17:20:43 +08:00
|
|
|
if hasError(dbsRsp.GetStatus(), err) {
|
2023-03-30 11:28:25 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2023-09-06 10:35:48 +08:00
|
|
|
dbNames := dbsRsp.DbNames
|
|
|
|
if req.GetDbName() != "" {
|
|
|
|
dbNames = lo.Filter(dbNames, func(dbName string, _ int) bool {
|
|
|
|
return dbName == req.GetDbName()
|
|
|
|
})
|
|
|
|
if len(dbNames) == 0 {
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(merr.WrapErrDatabaseNotFound(req.GetDbName()))
|
2023-09-06 10:35:48 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
2023-06-25 17:20:43 +08:00
|
|
|
|
2023-09-06 10:35:48 +08:00
|
|
|
for _, dbName := range dbNames {
|
2023-06-25 17:20:43 +08:00
|
|
|
// Flush all collections to accelerate the flushAll progress
|
|
|
|
showColRsp, err := node.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{
|
|
|
|
Base: commonpbutil.NewMsgBase(commonpbutil.WithMsgType(commonpb.MsgType_ShowCollections)),
|
|
|
|
DbName: dbName,
|
|
|
|
})
|
|
|
|
if hasError(showColRsp.GetStatus(), err) {
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2023-09-01 15:23:01 +08:00
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
for _, collection := range showColRsp.GetCollectionNames() {
|
|
|
|
collection := collection
|
|
|
|
group.Go(func() error {
|
|
|
|
flushRsp, err := node.Flush(ctx, &milvuspb.FlushRequest{
|
|
|
|
Base: commonpbutil.NewMsgBase(commonpbutil.WithMsgType(commonpb.MsgType_Flush)),
|
|
|
|
DbName: dbName,
|
|
|
|
CollectionNames: []string{collection},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if flushRsp.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
|
|
|
return merr.Error(flushRsp.GetStatus())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
err = group.Wait()
|
|
|
|
if hasError(nil, err) {
|
2023-06-25 17:20:43 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// allocate current ts as FlushAllTs
|
|
|
|
ts, err := node.tsoAllocator.AllocOne(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("FlushAll failed", zap.Error(err))
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-03-30 11:28:25 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.FlushAllTs = ts
|
|
|
|
|
|
|
|
log.Info(rpcDone("FlushAll"), zap.Uint64("FlushAllTs", ts),
|
|
|
|
zap.Time("FlushAllTime", tsoutil.PhysicalTime(ts)))
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-11-18 21:26:28 +08:00
|
|
|
// GetDdChannel returns the used channel for dd operations.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetDdChannel(ctx context.Context, request *internalpb.GetDdChannelRequest) (*milvuspb.StringResponse, error) {
|
2023-05-31 20:24:31 +08:00
|
|
|
return &milvuspb.StringResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrServiceUnavailable("unimp")),
|
2023-05-31 20:24:31 +08:00
|
|
|
}, nil
|
2021-01-22 09:36:18 +08:00
|
|
|
}
|
2021-02-04 10:25:01 +08:00
|
|
|
|
2021-11-18 22:13:28 +08:00
|
|
|
// GetPersistentSegmentInfo get the information of sealed segment.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetPersistentSegmentInfo(ctx context.Context, req *milvuspb.GetPersistentSegmentInfoRequest) (*milvuspb.GetPersistentSegmentInfoResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetPersistentSegmentInfo")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2021-03-22 19:28:43 +08:00
|
|
|
log.Debug("GetPersistentSegmentInfo",
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.String("db", req.DbName),
|
|
|
|
zap.Any("collection", req.CollectionName))
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
resp := &milvuspb.GetPersistentSegmentInfoResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2021-02-04 10:25:01 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-06-22 10:36:08 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-03-02 16:23:55 +08:00
|
|
|
method := "GetPersistentSegmentInfo"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-10-18 19:17:27 +08:00
|
|
|
|
|
|
|
// list segments
|
2023-06-25 17:20:43 +08:00
|
|
|
collectionID, err := globalMetaCache.GetCollectionID(ctx, req.GetDbName(), req.GetCollectionName())
|
2021-02-04 10:25:01 +08:00
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-10-18 19:17:27 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
getSegmentsByStatesResponse, err := node.dataCoord.GetSegmentsByStates(ctx, &datapb.GetSegmentsByStatesRequest{
|
|
|
|
CollectionID: collectionID,
|
|
|
|
// -1 means list all partition segemnts
|
|
|
|
PartitionID: -1,
|
|
|
|
States: []commonpb.SegmentState{commonpb.SegmentState_Flushing, commonpb.SegmentState_Flushed, commonpb.SegmentState_Sealed},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-02-04 10:25:01 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-18 19:17:27 +08:00
|
|
|
|
|
|
|
// get Segment info
|
2021-06-21 18:22:13 +08:00
|
|
|
infoResp, err := node.dataCoord.GetSegmentInfo(ctx, &datapb.GetSegmentInfoRequest{
|
2022-10-19 10:01:26 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SegmentInfo),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
),
|
2022-10-18 19:17:27 +08:00
|
|
|
SegmentIDs: getSegmentsByStatesResponse.Segments,
|
2021-02-04 10:25:01 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("GetPersistentSegmentInfo fail",
|
|
|
|
zap.Error(err))
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-02-04 10:25:01 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2023-09-15 10:09:21 +08:00
|
|
|
err = merr.Error(infoResp.GetStatus())
|
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.FailLabel).Inc()
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-02-04 10:25:01 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2023-09-15 10:09:21 +08:00
|
|
|
log.Debug("GetPersistentSegmentInfo",
|
|
|
|
zap.Int("len(infos)", len(infoResp.Infos)),
|
|
|
|
zap.Any("status", infoResp.Status))
|
2021-02-04 10:25:01 +08:00
|
|
|
persistentInfos := make([]*milvuspb.PersistentSegmentInfo, len(infoResp.Infos))
|
|
|
|
for i, info := range infoResp.Infos {
|
|
|
|
persistentInfos[i] = &milvuspb.PersistentSegmentInfo{
|
2021-04-09 09:55:04 +08:00
|
|
|
SegmentID: info.ID,
|
2021-02-04 10:25:01 +08:00
|
|
|
CollectionID: info.CollectionID,
|
|
|
|
PartitionID: info.PartitionID,
|
2021-06-04 11:45:45 +08:00
|
|
|
NumRows: info.NumOfRows,
|
2021-02-04 10:25:01 +08:00
|
|
|
State: info.State,
|
|
|
|
}
|
|
|
|
}
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.SuccessLabel).Inc()
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-04 10:25:01 +08:00
|
|
|
resp.Infos = persistentInfos
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-12-10 22:53:27 +08:00
|
|
|
// GetQuerySegmentInfo gets segment information from QueryCoord.
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) GetQuerySegmentInfo(ctx context.Context, req *milvuspb.GetQuerySegmentInfoRequest) (*milvuspb.GetQuerySegmentInfoResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetQuerySegmentInfo")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2021-03-22 19:28:43 +08:00
|
|
|
log.Debug("GetQuerySegmentInfo",
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2021-03-22 19:28:43 +08:00
|
|
|
zap.String("db", req.DbName),
|
|
|
|
zap.Any("collection", req.CollectionName))
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
resp := &milvuspb.GetQuerySegmentInfoResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2021-02-04 14:37:12 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-06-22 10:36:08 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-05-25 15:17:59 +08:00
|
|
|
|
2022-10-18 19:17:27 +08:00
|
|
|
method := "GetQuerySegmentInfo"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
collID, err := globalMetaCache.GetCollectionID(ctx, req.GetDbName(), req.CollectionName)
|
2021-10-26 19:26:43 +08:00
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-10-26 19:26:43 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2021-06-22 16:44:09 +08:00
|
|
|
infoResp, err := node.queryCoord.GetSegmentInfo(ctx, &querypb.GetSegmentInfoRequest{
|
2022-10-19 10:01:26 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SegmentInfo),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
),
|
2021-10-26 19:26:43 +08:00
|
|
|
CollectionID: collID,
|
2021-02-04 14:37:12 +08:00
|
|
|
})
|
2023-09-15 10:09:21 +08:00
|
|
|
if err == nil {
|
|
|
|
err = merr.Error(infoResp.GetStatus())
|
|
|
|
}
|
2021-02-04 14:37:12 +08:00
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("Failed to get segment info from QueryCoord",
|
|
|
|
zap.Error(err))
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-02-04 14:37:12 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("GetQuerySegmentInfo",
|
|
|
|
zap.Any("infos", infoResp.Infos),
|
|
|
|
zap.Any("status", infoResp.Status))
|
2021-02-04 14:37:12 +08:00
|
|
|
queryInfos := make([]*milvuspb.QuerySegmentInfo, len(infoResp.Infos))
|
|
|
|
for i, info := range infoResp.Infos {
|
|
|
|
queryInfos[i] = &milvuspb.QuerySegmentInfo{
|
|
|
|
SegmentID: info.SegmentID,
|
|
|
|
CollectionID: info.CollectionID,
|
|
|
|
PartitionID: info.PartitionID,
|
|
|
|
NumRows: info.NumRows,
|
|
|
|
MemSize: info.MemSize,
|
|
|
|
IndexName: info.IndexName,
|
|
|
|
IndexID: info.IndexID,
|
2021-12-15 16:53:12 +08:00
|
|
|
State: info.SegmentState,
|
2022-05-20 18:03:58 +08:00
|
|
|
NodeIds: info.NodeIds,
|
2021-02-04 14:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-18 19:17:27 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-02-04 14:37:12 +08:00
|
|
|
resp.Infos = queryInfos
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2021-12-09 16:09:32 +08:00
|
|
|
// Dummy handles dummy request
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) Dummy(ctx context.Context, req *milvuspb.DummyRequest) (*milvuspb.DummyResponse, error) {
|
2021-05-26 16:57:32 +08:00
|
|
|
failedResponse := &milvuspb.DummyResponse{
|
|
|
|
Response: `{"status": "fail"}`,
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(wxyu): change name RequestType to Request
|
|
|
|
drt, err := parseDummyRequestType(req.RequestType)
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Dummy")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2021-05-26 16:57:32 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("Failed to parse dummy request type",
|
|
|
|
zap.Error(err))
|
2021-05-26 16:57:32 +08:00
|
|
|
return failedResponse, nil
|
|
|
|
}
|
|
|
|
|
2021-08-16 17:06:10 +08:00
|
|
|
if drt.RequestType == "query" {
|
|
|
|
drr, err := parseDummyQueryRequest(req.RequestType)
|
2021-05-26 16:57:32 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("Failed to parse dummy query request",
|
|
|
|
zap.Error(err))
|
2021-05-26 16:57:32 +08:00
|
|
|
return failedResponse, nil
|
|
|
|
}
|
|
|
|
|
2021-08-16 17:06:10 +08:00
|
|
|
request := &milvuspb.QueryRequest{
|
2021-05-26 16:57:32 +08:00
|
|
|
DbName: drr.DbName,
|
|
|
|
CollectionName: drr.CollectionName,
|
|
|
|
PartitionNames: drr.PartitionNames,
|
2021-08-16 17:06:10 +08:00
|
|
|
OutputFields: drr.OutputFields,
|
2021-05-25 14:44:43 +08:00
|
|
|
}
|
|
|
|
|
2021-08-16 17:06:10 +08:00
|
|
|
_, err = node.Query(ctx, request)
|
2021-05-26 16:57:32 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("Failed to execute dummy query",
|
|
|
|
zap.Error(err))
|
2021-05-26 16:57:32 +08:00
|
|
|
return failedResponse, err
|
|
|
|
}
|
2021-05-25 14:44:43 +08:00
|
|
|
|
|
|
|
return &milvuspb.DummyResponse{
|
|
|
|
Response: `{"status": "success"}`,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-05-26 16:57:32 +08:00
|
|
|
log.Debug("cannot find specify dummy request type")
|
|
|
|
return failedResponse, nil
|
2021-05-25 14:44:43 +08:00
|
|
|
}
|
|
|
|
|
2021-12-10 21:06:40 +08:00
|
|
|
// RegisterLink registers a link
|
2021-06-22 14:40:07 +08:00
|
|
|
func (node *Proxy) RegisterLink(ctx context.Context, req *milvuspb.RegisterLinkRequest) (*milvuspb.RegisterLinkResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
code := node.GetStateCode()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-RegisterLink")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2021-12-13 10:01:18 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
2023-10-09 10:09:33 +08:00
|
|
|
zap.String("state", code.String()))
|
2021-03-22 19:28:43 +08:00
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("RegisterLink")
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(code); err != nil {
|
2021-03-04 22:27:12 +08:00
|
|
|
return &milvuspb.RegisterLinkResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2021-03-04 22:27:12 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2023-09-21 09:45:27 +08:00
|
|
|
// metrics.ProxyLinkedSDKs.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10)).Inc()
|
2021-03-04 22:27:12 +08:00
|
|
|
return &milvuspb.RegisterLinkResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Success(os.Getenv(metricsinfo.DeployModeEnvKey)),
|
2021-03-04 22:27:12 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-06-22 10:36:08 +08:00
|
|
|
|
2022-04-20 16:15:41 +08:00
|
|
|
// GetMetrics gets the metrics of proxy
|
2021-08-18 10:12:10 +08:00
|
|
|
// TODO(dragondriver): cache the Metrics and set a retention to the cache
|
|
|
|
func (node *Proxy) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetMetrics")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2023-01-04 17:39:35 +08:00
|
|
|
log.RatedDebug(60, "Proxy.GetMetrics",
|
|
|
|
zap.Int64("nodeID", paramtable.GetNodeID()),
|
2021-08-18 10:12:10 +08:00
|
|
|
zap.String("req", req.Request))
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2021-08-18 10:12:10 +08:00
|
|
|
log.Warn("Proxy.GetMetrics failed",
|
2023-01-04 17:39:35 +08:00
|
|
|
zap.Int64("nodeID", paramtable.GetNodeID()),
|
2021-08-18 10:12:10 +08:00
|
|
|
zap.String("req", req.Request),
|
2023-03-24 15:27:58 +08:00
|
|
|
zap.Error(err))
|
2021-08-18 10:12:10 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-18 10:12:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
metricType, err := metricsinfo.ParseMetricType(req.Request)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Proxy.GetMetrics failed to parse metric type",
|
2023-01-04 17:39:35 +08:00
|
|
|
zap.Int64("nodeID", paramtable.GetNodeID()),
|
2021-08-18 10:12:10 +08:00
|
|
|
zap.String("req", req.Request),
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Status(err),
|
2021-08-18 10:12:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:01:26 +08:00
|
|
|
req.Base = commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SystemInfo),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
)
|
2021-08-18 10:12:10 +08:00
|
|
|
if metricType == metricsinfo.SystemInfoMetrics {
|
2023-01-04 17:39:35 +08:00
|
|
|
metrics, err := node.metricsCacheManager.GetSystemInfoMetrics()
|
|
|
|
if err != nil {
|
|
|
|
metrics, err = getSystemInfoMetrics(ctx, req, node)
|
2021-09-03 17:15:26 +08:00
|
|
|
}
|
2021-08-18 10:12:10 +08:00
|
|
|
|
2023-01-04 17:39:35 +08:00
|
|
|
log.RatedDebug(60, "Proxy.GetMetrics",
|
|
|
|
zap.Int64("nodeID", paramtable.GetNodeID()),
|
2021-08-18 10:12:10 +08:00
|
|
|
zap.String("req", req.Request),
|
2023-01-04 17:39:35 +08:00
|
|
|
zap.String("metricType", metricType),
|
2021-08-18 10:12:10 +08:00
|
|
|
zap.Any("metrics", metrics), // TODO(dragondriver): necessary? may be very large
|
|
|
|
zap.Error(err))
|
|
|
|
|
2021-09-03 17:15:26 +08:00
|
|
|
node.metricsCacheManager.UpdateSystemInfoMetrics(metrics)
|
|
|
|
|
2021-12-01 22:17:46 +08:00
|
|
|
return metrics, nil
|
2021-08-18 10:12:10 +08:00
|
|
|
}
|
|
|
|
|
2023-01-04 17:39:35 +08:00
|
|
|
log.RatedWarn(60, "Proxy.GetMetrics failed, request metric type is not implemented yet",
|
|
|
|
zap.Int64("nodeID", paramtable.GetNodeID()),
|
2021-08-18 10:12:10 +08:00
|
|
|
zap.String("req", req.Request),
|
2023-01-04 17:39:35 +08:00
|
|
|
zap.String("metricType", metricType))
|
2021-08-18 10:12:10 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrMetricNotFound(metricType)),
|
2021-08-18 10:12:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-09-16 09:56:47 +08:00
|
|
|
// GetProxyMetrics gets the metrics of proxy, it's an internal interface which is different from GetMetrics interface,
|
|
|
|
// because it only obtains the metrics of Proxy, not including the topological metrics of Query cluster and Data cluster.
|
|
|
|
func (node *Proxy) GetProxyMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetProxyMetrics")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2023-01-04 17:39:35 +08:00
|
|
|
zap.Int64("nodeID", paramtable.GetNodeID()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("req", req.Request))
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2022-09-16 09:56:47 +08:00
|
|
|
log.Warn("Proxy.GetProxyMetrics failed",
|
2023-03-24 15:27:58 +08:00
|
|
|
zap.Error(err))
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-03-24 15:27:58 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-16 09:56:47 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
metricType, err := metricsinfo.ParseMetricType(req.Request)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Proxy.GetProxyMetrics failed to parse metric type",
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-16 09:56:47 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-19 10:01:26 +08:00
|
|
|
req.Base = commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SystemInfo),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
)
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
if metricType == metricsinfo.SystemInfoMetrics {
|
|
|
|
proxyMetrics, err := getProxyMetrics(ctx, req, node)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Proxy.GetProxyMetrics failed to getProxyMetrics",
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-09-18 14:05:28 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-16 09:56:47 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-09-21 09:45:27 +08:00
|
|
|
// log.Debug("Proxy.GetProxyMetrics",
|
2023-03-09 14:15:55 +08:00
|
|
|
// zap.String("metricType", metricType))
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
return proxyMetrics, nil
|
|
|
|
}
|
|
|
|
|
2022-11-08 21:59:02 +08:00
|
|
|
log.Warn("Proxy.GetProxyMetrics failed, request metric type is not implemented yet",
|
2023-01-04 17:39:35 +08:00
|
|
|
zap.String("metricType", metricType))
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrMetricNotFound(metricType)),
|
2022-09-16 09:56:47 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-11-06 16:54:59 +08:00
|
|
|
// LoadBalance would do a load balancing operation between query nodes
|
|
|
|
func (node *Proxy) LoadBalance(ctx context.Context, req *milvuspb.LoadBalanceRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-LoadBalance")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2021-11-06 16:54:59 +08:00
|
|
|
log.Debug("Proxy.LoadBalance",
|
2022-11-04 14:25:38 +08:00
|
|
|
zap.Int64("proxy_id", paramtable.GetNodeID()),
|
2021-11-06 16:54:59 +08:00
|
|
|
zap.Any("req", req))
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2021-11-06 16:54:59 +08:00
|
|
|
}
|
|
|
|
|
2023-10-11 21:01:35 +08:00
|
|
|
status := merr.Success()
|
2022-04-20 16:15:41 +08:00
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
collectionID, err := globalMetaCache.GetCollectionID(ctx, req.GetDbName(), req.GetCollectionName())
|
2022-04-20 16:15:41 +08:00
|
|
|
if err != nil {
|
2022-11-30 14:11:15 +08:00
|
|
|
log.Warn("failed to get collection id",
|
2023-07-14 15:56:31 +08:00
|
|
|
zap.String("collectionName", req.GetCollectionName()),
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2023-09-26 17:15:27 +08:00
|
|
|
status = merr.Status(err)
|
2022-04-20 16:15:41 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
2021-11-06 16:54:59 +08:00
|
|
|
infoResp, err := node.queryCoord.LoadBalance(ctx, &querypb.LoadBalanceRequest{
|
2022-10-19 10:01:26 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_LoadBalanceSegments),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-19 10:01:26 +08:00
|
|
|
),
|
2021-11-06 16:54:59 +08:00
|
|
|
SourceNodeIDs: []int64{req.SrcNodeID},
|
|
|
|
DstNodeIDs: req.DstNodeIDs,
|
2021-12-15 16:53:12 +08:00
|
|
|
BalanceReason: querypb.TriggerCondition_GrpcRequest,
|
2021-11-06 16:54:59 +08:00
|
|
|
SealedSegmentIDs: req.SealedSegmentIDs,
|
2022-04-20 16:15:41 +08:00
|
|
|
CollectionID: collectionID,
|
2021-11-06 16:54:59 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2022-11-30 14:11:15 +08:00
|
|
|
log.Warn("Failed to LoadBalance from Query Coordinator",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Any("req", req),
|
|
|
|
zap.Error(err))
|
2023-09-26 17:15:27 +08:00
|
|
|
status = merr.Status(err)
|
2021-11-06 16:54:59 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
if infoResp.ErrorCode != commonpb.ErrorCode_Success {
|
2022-11-30 14:11:15 +08:00
|
|
|
log.Warn("Failed to LoadBalance from Query Coordinator",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("errMsg", infoResp.Reason))
|
2023-09-26 17:15:27 +08:00
|
|
|
status = infoResp
|
2021-11-06 16:54:59 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("LoadBalance Done",
|
|
|
|
zap.Any("req", req),
|
|
|
|
zap.Any("status", infoResp))
|
2021-11-06 16:54:59 +08:00
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2022-10-18 19:17:27 +08:00
|
|
|
// GetReplicas gets replica info
|
|
|
|
func (node *Proxy) GetReplicas(ctx context.Context, req *milvuspb.GetReplicasRequest) (*milvuspb.GetReplicasResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetReplicas")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug("received get replicas request",
|
|
|
|
zap.Int64("collection", req.GetCollectionID()),
|
|
|
|
zap.Bool("with shard nodes", req.GetWithShardNodes()))
|
2022-10-18 19:17:27 +08:00
|
|
|
resp := &milvuspb.GetReplicasResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-10-18 19:17:27 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-10-21 15:57:28 +08:00
|
|
|
req.Base = commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_GetReplicas),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-21 15:57:28 +08:00
|
|
|
)
|
2022-10-18 19:17:27 +08:00
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
if req.GetCollectionName() != "" {
|
2023-10-08 11:53:32 +08:00
|
|
|
var err error
|
|
|
|
req.CollectionID, err = globalMetaCache.GetCollectionID(ctx, req.GetDbName(), req.GetCollectionName())
|
|
|
|
if err != nil {
|
|
|
|
resp.Status = merr.Status(err)
|
|
|
|
return resp, nil
|
|
|
|
}
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2023-04-07 17:30:28 +08:00
|
|
|
r, err := node.queryCoord.GetReplicas(ctx, req)
|
2022-10-18 19:17:27 +08:00
|
|
|
if err != nil {
|
2023-04-07 17:30:28 +08:00
|
|
|
log.Warn("Failed to get replicas from Query Coordinator",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2023-04-07 17:30:28 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-10-18 19:17:27 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2023-04-07 17:30:28 +08:00
|
|
|
log.Debug("received get replicas response", zap.String("resp", r.String()))
|
|
|
|
return r, nil
|
2022-10-18 19:17:27 +08:00
|
|
|
}
|
|
|
|
|
2022-10-19 10:01:26 +08:00
|
|
|
// GetCompactionState gets the compaction state of multiple segments
|
2021-11-09 14:47:02 +08:00
|
|
|
func (node *Proxy) GetCompactionState(ctx context.Context, req *milvuspb.GetCompactionStateRequest) (*milvuspb.GetCompactionStateResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetCompactionState")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.Int64("compactionID", req.GetCompactionID()))
|
|
|
|
|
|
|
|
log.Debug("received GetCompactionState request")
|
2021-11-09 14:47:02 +08:00
|
|
|
resp := &milvuspb.GetCompactionStateResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-11-09 14:47:02 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.dataCoord.GetCompactionState(ctx, req)
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("received GetCompactionState response",
|
|
|
|
zap.Any("resp", resp),
|
|
|
|
zap.Error(err))
|
2021-11-09 14:47:02 +08:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2021-12-30 19:15:22 +08:00
|
|
|
// ManualCompaction invokes compaction on specified collection
|
2021-11-09 14:47:02 +08:00
|
|
|
func (node *Proxy) ManualCompaction(ctx context.Context, req *milvuspb.ManualCompactionRequest) (*milvuspb.ManualCompactionResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ManualCompaction")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.Int64("collectionID", req.GetCollectionID()))
|
|
|
|
|
|
|
|
log.Info("received ManualCompaction request")
|
2021-11-09 14:47:02 +08:00
|
|
|
resp := &milvuspb.ManualCompactionResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-11-09 14:47:02 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.dataCoord.ManualCompaction(ctx, req)
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Info("received ManualCompaction response",
|
|
|
|
zap.Any("resp", resp),
|
|
|
|
zap.Error(err))
|
2021-11-09 14:47:02 +08:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2022-04-20 16:15:41 +08:00
|
|
|
// GetCompactionStateWithPlans returns the compactions states with the given plan ID
|
2021-11-09 14:47:02 +08:00
|
|
|
func (node *Proxy) GetCompactionStateWithPlans(ctx context.Context, req *milvuspb.GetCompactionPlansRequest) (*milvuspb.GetCompactionPlansResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetCompactionStateWithPlans")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.Int64("compactionID", req.GetCompactionID()))
|
|
|
|
|
|
|
|
log.Debug("received GetCompactionStateWithPlans request")
|
2021-11-09 14:47:02 +08:00
|
|
|
resp := &milvuspb.GetCompactionPlansResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2021-11-09 14:47:02 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.dataCoord.GetCompactionStateWithPlans(ctx, req)
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("received GetCompactionStateWithPlans response",
|
|
|
|
zap.Any("resp", resp),
|
|
|
|
zap.Error(err))
|
2021-11-09 14:47:02 +08:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2023-09-12 21:07:19 +08:00
|
|
|
// GetFlushState gets the flush state of the collection based on the provided flush ts and segment IDs.
|
2021-11-23 10:55:14 +08:00
|
|
|
func (node *Proxy) GetFlushState(ctx context.Context, req *milvuspb.GetFlushStateRequest) (*milvuspb.GetFlushStateResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetFlushState")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug("received get flush state request",
|
|
|
|
zap.Any("request", req))
|
2021-11-23 22:57:17 +08:00
|
|
|
var err error
|
2023-09-21 14:53:25 +08:00
|
|
|
failResp := &milvuspb.GetFlushStateResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-21 14:53:25 +08:00
|
|
|
failResp.Status = merr.Status(err)
|
2022-11-08 21:59:02 +08:00
|
|
|
log.Warn("unable to get flush state because of closed server")
|
2023-09-21 14:53:25 +08:00
|
|
|
return failResp, nil
|
2021-11-23 10:55:14 +08:00
|
|
|
}
|
|
|
|
|
2023-09-12 21:07:19 +08:00
|
|
|
stateReq := &datapb.GetFlushStateRequest{
|
|
|
|
SegmentIDs: req.GetSegmentIDs(),
|
|
|
|
FlushTs: req.GetFlushTs(),
|
|
|
|
}
|
2023-09-14 19:57:20 +08:00
|
|
|
|
|
|
|
if len(req.GetCollectionName()) > 0 { // For compatibility with old client
|
|
|
|
if err = validateCollectionName(req.GetCollectionName()); err != nil {
|
2023-09-21 14:53:25 +08:00
|
|
|
failResp.Status = merr.Status(err)
|
|
|
|
return failResp, nil
|
2023-09-14 19:57:20 +08:00
|
|
|
}
|
|
|
|
collectionID, err := globalMetaCache.GetCollectionID(ctx, req.GetDbName(), req.GetCollectionName())
|
|
|
|
if err != nil {
|
2023-09-21 14:53:25 +08:00
|
|
|
failResp.Status = merr.Status(err)
|
|
|
|
return failResp, nil
|
2023-09-14 19:57:20 +08:00
|
|
|
}
|
|
|
|
stateReq.CollectionID = collectionID
|
|
|
|
}
|
2023-09-12 21:07:19 +08:00
|
|
|
|
2023-09-21 14:53:25 +08:00
|
|
|
resp, err := node.dataCoord.GetFlushState(ctx, stateReq)
|
2021-12-24 14:14:15 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("failed to get flush state response",
|
|
|
|
zap.Error(err))
|
2023-09-21 14:53:25 +08:00
|
|
|
failResp.Status = merr.Status(err)
|
|
|
|
return failResp, nil
|
2021-12-24 14:14:15 +08:00
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("received get flush state response",
|
|
|
|
zap.Any("response", resp))
|
2021-11-23 10:55:14 +08:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:28:25 +08:00
|
|
|
// GetFlushAllState checks if all DML messages before `FlushAllTs` have been flushed.
|
|
|
|
func (node *Proxy) GetFlushAllState(ctx context.Context, req *milvuspb.GetFlushAllStateRequest) (*milvuspb.GetFlushAllStateResponse, error) {
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetFlushAllState")
|
|
|
|
defer sp.End()
|
|
|
|
log := log.Ctx(ctx).With(zap.Uint64("FlushAllTs", req.GetFlushAllTs()),
|
2023-09-06 10:35:48 +08:00
|
|
|
zap.Time("FlushAllTime", tsoutil.PhysicalTime(req.GetFlushAllTs())),
|
|
|
|
zap.String("db", req.GetDbName()))
|
2023-03-30 11:28:25 +08:00
|
|
|
log.Debug("receive GetFlushAllState request")
|
|
|
|
|
|
|
|
var err error
|
|
|
|
resp := &milvuspb.GetFlushAllStateResponse{}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-03-30 11:28:25 +08:00
|
|
|
log.Warn("GetFlushAllState failed, closed server")
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = node.dataCoord.GetFlushAllState(ctx, req)
|
|
|
|
if err != nil {
|
2023-09-04 09:57:09 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2023-09-15 10:09:21 +08:00
|
|
|
log.Warn("GetFlushAllState failed", zap.Error(err))
|
2023-03-30 11:28:25 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
log.Debug("GetFlushAllState done", zap.Bool("flushed", resp.GetFlushed()))
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2021-06-22 14:40:07 +08:00
|
|
|
// checkHealthy checks proxy state is Healthy
|
|
|
|
func (node *Proxy) checkHealthy() bool {
|
2023-10-09 10:09:33 +08:00
|
|
|
code := node.GetStateCode()
|
2022-10-10 15:55:22 +08:00
|
|
|
return code == commonpb.StateCode_Healthy
|
2021-06-22 10:36:08 +08:00
|
|
|
}
|
|
|
|
|
2022-03-09 18:33:59 +08:00
|
|
|
// Import data files(json, numpy, etc.) on MinIO/S3 storage, read and parse them into sealed segments
|
|
|
|
func (node *Proxy) Import(ctx context.Context, req *milvuspb.ImportRequest) (*milvuspb.ImportResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-Import")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2022-04-20 14:03:40 +08:00
|
|
|
log.Info("received import request",
|
2023-07-14 15:56:31 +08:00
|
|
|
zap.String("collectionName", req.GetCollectionName()),
|
2022-10-27 16:21:34 +08:00
|
|
|
zap.String("partition name", req.GetPartitionName()),
|
|
|
|
zap.Strings("files", req.GetFiles()))
|
2022-04-12 13:25:34 +08:00
|
|
|
resp := &milvuspb.ImportResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-04-12 13:25:34 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-03-09 18:33:59 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-18 19:17:27 +08:00
|
|
|
|
2022-10-20 12:15:27 +08:00
|
|
|
err := importutil.ValidateOptions(req.GetOptions())
|
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("failed to execute import request",
|
|
|
|
zap.Error(err))
|
2023-09-26 17:15:27 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-10-20 12:15:27 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-10-18 19:17:27 +08:00
|
|
|
method := "Import"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
|
2022-04-12 13:25:34 +08:00
|
|
|
// Call rootCoord to finish import.
|
2022-06-02 15:34:04 +08:00
|
|
|
respFromRC, err := node.rootCoord.Import(ctx, req)
|
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("failed to execute bulk insert request",
|
|
|
|
zap.Error(err))
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-06-02 15:34:04 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-18 19:17:27 +08:00
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-06-02 15:34:04 +08:00
|
|
|
return respFromRC, nil
|
2022-03-09 18:33:59 +08:00
|
|
|
}
|
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
// GetImportState checks import task state from RootCoord.
|
2022-04-25 17:37:46 +08:00
|
|
|
func (node *Proxy) GetImportState(ctx context.Context, req *milvuspb.GetImportStateRequest) (*milvuspb.GetImportStateResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-GetImportState")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug("received get import state request",
|
|
|
|
zap.Int64("taskID", req.GetTask()))
|
2023-09-26 17:15:27 +08:00
|
|
|
resp := &milvuspb.GetImportStateResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-26 17:15:27 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-04-25 17:37:46 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-18 19:17:27 +08:00
|
|
|
method := "GetImportState"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-04-25 17:37:46 +08:00
|
|
|
|
|
|
|
resp, err := node.rootCoord.GetImportState(ctx, req)
|
2022-10-18 19:17:27 +08:00
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("failed to execute get import state",
|
|
|
|
zap.Error(err))
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-10-18 19:17:27 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("successfully received get import state response",
|
|
|
|
zap.Int64("taskID", req.GetTask()),
|
|
|
|
zap.Any("resp", resp), zap.Error(err))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-10-18 19:17:27 +08:00
|
|
|
return resp, nil
|
2022-04-25 17:37:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListImportTasks get id array of all import tasks from rootcoord
|
|
|
|
func (node *Proxy) ListImportTasks(ctx context.Context, req *milvuspb.ListImportTasksRequest) (*milvuspb.ListImportTasksResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ListImportTasks")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2022-11-08 21:59:02 +08:00
|
|
|
log.Debug("received list import tasks request")
|
2023-09-26 17:15:27 +08:00
|
|
|
resp := &milvuspb.ListImportTasksResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-26 17:15:27 +08:00
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-04-25 17:37:46 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-18 19:17:27 +08:00
|
|
|
method := "ListImportTasks"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
2022-10-18 19:17:27 +08:00
|
|
|
metrics.TotalLabel).Inc()
|
2022-04-25 17:37:46 +08:00
|
|
|
resp, err := node.rootCoord.ListImportTasks(ctx, req)
|
2022-10-18 19:17:27 +08:00
|
|
|
if err != nil {
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("failed to execute list import tasks",
|
|
|
|
zap.Error(err))
|
2023-09-15 10:09:21 +08:00
|
|
|
resp.Status = merr.Status(err)
|
2022-04-06 14:57:31 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("successfully received list import tasks response",
|
|
|
|
zap.String("collection", req.CollectionName),
|
2023-11-21 20:58:23 +08:00
|
|
|
zap.Any("tasks", lo.SliceToMap(resp.GetTasks(), func(state *milvuspb.GetImportStateResponse) (int64, commonpb.ImportState) {
|
|
|
|
return state.GetId(), state.GetState()
|
|
|
|
})))
|
2022-11-04 14:25:38 +08:00
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-04-06 14:57:31 +08:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2022-04-11 19:49:34 +08:00
|
|
|
// InvalidateCredentialCache invalidate the credential cache of specified username.
|
|
|
|
func (node *Proxy) InvalidateCredentialCache(ctx context.Context, request *proxypb.InvalidateCredCacheRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-InvalidateCredentialCache")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2022-04-11 19:49:34 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("username", request.Username))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log.Debug("received request to invalidate credential cache")
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-04-11 19:49:34 +08:00
|
|
|
|
|
|
|
username := request.Username
|
|
|
|
if globalMetaCache != nil {
|
|
|
|
globalMetaCache.RemoveCredential(username) // no need to return error, though credential may be not cached
|
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("complete to invalidate credential cache")
|
2022-04-11 19:49:34 +08:00
|
|
|
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateCredentialCache update the credential cache of specified username.
|
|
|
|
func (node *Proxy) UpdateCredentialCache(ctx context.Context, request *proxypb.UpdateCredCacheRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-UpdateCredentialCache")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
2022-04-11 19:49:34 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("username", request.Username))
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log.Debug("received request to update credential cache")
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-04-11 19:49:34 +08:00
|
|
|
|
|
|
|
credInfo := &internalpb.CredentialInfo{
|
2022-06-29 20:02:18 +08:00
|
|
|
Username: request.Username,
|
|
|
|
Sha256Password: request.Password,
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
if globalMetaCache != nil {
|
|
|
|
globalMetaCache.UpdateCredential(credInfo) // no need to return error, though credential may be not cached
|
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("complete to update credential cache")
|
2022-04-11 19:49:34 +08:00
|
|
|
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) CreateCredential(ctx context.Context, req *milvuspb.CreateCredentialRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateCredential")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("username", req.Username))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("CreateCredential",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-04-11 19:49:34 +08:00
|
|
|
// validate params
|
|
|
|
username := req.Username
|
|
|
|
if err := ValidateUsername(username); err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
rawPassword, err := crypto.Base64Decode(req.Password)
|
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("decode password fail",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
err = errors.Wrap(err, "decode password fail")
|
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
if err = ValidatePassword(rawPassword); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("illegal password",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
encryptedPassword, err := crypto.PasswordEncrypt(rawPassword)
|
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("encrypt password fail",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
err = errors.Wrap(err, "encrypt password failed")
|
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
2022-08-04 11:04:34 +08:00
|
|
|
|
2022-04-11 19:49:34 +08:00
|
|
|
credInfo := &internalpb.CredentialInfo{
|
|
|
|
Username: req.Username,
|
|
|
|
EncryptedPassword: encryptedPassword,
|
2022-06-29 20:02:18 +08:00
|
|
|
Sha256Password: crypto.SHA256(rawPassword, req.Username),
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
result, err := node.rootCoord.CreateCredential(ctx, credInfo)
|
|
|
|
if err != nil { // for error like conntext timeout etc.
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("create credential fail",
|
|
|
|
zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
2022-04-19 16:35:39 +08:00
|
|
|
func (node *Proxy) UpdateCredential(ctx context.Context, req *milvuspb.UpdateCredentialRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-UpdateCredential")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("username", req.Username))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("UpdateCredential",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-04-19 16:35:39 +08:00
|
|
|
rawOldPassword, err := crypto.Base64Decode(req.OldPassword)
|
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("decode old password fail",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
err = errors.Wrap(err, "decode old password failed")
|
|
|
|
return merr.Status(err), nil
|
2022-04-19 16:35:39 +08:00
|
|
|
}
|
|
|
|
rawNewPassword, err := crypto.Base64Decode(req.NewPassword)
|
2022-04-11 19:49:34 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("decode password fail",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
err = errors.Wrap(err, "decode password failed")
|
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
2022-04-19 16:35:39 +08:00
|
|
|
// valid new password
|
|
|
|
if err = ValidatePassword(rawNewPassword); err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("illegal password",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
2022-08-19 19:42:50 +08:00
|
|
|
|
2023-04-26 21:16:34 +08:00
|
|
|
skipPasswordVerify := false
|
|
|
|
if currentUser, _ := GetCurUserFromContext(ctx); currentUser != "" {
|
|
|
|
for _, s := range Params.CommonCfg.SuperUsers.GetAsStrings() {
|
|
|
|
if s == currentUser {
|
|
|
|
skipPasswordVerify = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !skipPasswordVerify && !passwordVerify(ctx, req.Username, rawOldPassword, globalMetaCache) {
|
2023-10-09 10:09:33 +08:00
|
|
|
err := merr.WrapErrPrivilegeNotAuthenticated("old password not correct for %s", req.GetUsername())
|
|
|
|
return merr.Status(err), nil
|
2022-04-19 16:35:39 +08:00
|
|
|
}
|
|
|
|
// update meta data
|
|
|
|
encryptedPassword, err := crypto.PasswordEncrypt(rawNewPassword)
|
2022-04-11 19:49:34 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("encrypt password fail",
|
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
err = errors.Wrap(err, "encrypt password failed")
|
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
2022-04-19 16:35:39 +08:00
|
|
|
updateCredReq := &internalpb.CredentialInfo{
|
2022-04-11 19:49:34 +08:00
|
|
|
Username: req.Username,
|
2022-06-29 20:02:18 +08:00
|
|
|
Sha256Password: crypto.SHA256(rawNewPassword, req.Username),
|
2022-04-11 19:49:34 +08:00
|
|
|
EncryptedPassword: encryptedPassword,
|
|
|
|
}
|
2022-04-19 16:35:39 +08:00
|
|
|
result, err := node.rootCoord.UpdateCredential(ctx, updateCredReq)
|
2022-04-11 19:49:34 +08:00
|
|
|
if err != nil { // for error like conntext timeout etc.
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("update credential fail",
|
|
|
|
zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) DeleteCredential(ctx context.Context, req *milvuspb.DeleteCredentialRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DeleteCredential")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("username", req.Username))
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("DeleteCredential",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("role", typeutil.ProxyRole))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
2022-04-20 13:03:40 +08:00
|
|
|
if req.Username == util.UserRoot {
|
2023-10-09 10:09:33 +08:00
|
|
|
err := merr.WrapErrPrivilegeNotPermitted("root user cannot be deleted")
|
|
|
|
return merr.Status(err), nil
|
2022-04-20 13:03:40 +08:00
|
|
|
}
|
2022-04-11 19:49:34 +08:00
|
|
|
result, err := node.rootCoord.DeleteCredential(ctx, req)
|
|
|
|
if err != nil { // for error like conntext timeout etc.
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Error("delete credential fail",
|
|
|
|
zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-04-11 19:49:34 +08:00
|
|
|
}
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) ListCredUsers(ctx context.Context, req *milvuspb.ListCredUsersRequest) (*milvuspb.ListCredUsersResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ListCredUsers")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole))
|
|
|
|
|
|
|
|
log.Debug("ListCredUsers")
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.ListCredUsersResponse{Status: merr.Status(err)}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-07-07 21:16:22 +08:00
|
|
|
rootCoordReq := &milvuspb.ListCredUsersRequest{
|
2022-10-19 10:01:26 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_ListCredUsernames),
|
|
|
|
),
|
2022-07-07 21:16:22 +08:00
|
|
|
}
|
|
|
|
resp, err := node.rootCoord.ListCredUsers(ctx, rootCoordReq)
|
2022-04-11 19:49:34 +08:00
|
|
|
if err != nil {
|
|
|
|
return &milvuspb.ListCredUsersResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-04-11 19:49:34 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return &milvuspb.ListCredUsersResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-07-07 21:16:22 +08:00
|
|
|
Usernames: resp.Usernames,
|
2022-04-11 19:49:34 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-04-20 16:15:41 +08:00
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) CreateRole(ctx context.Context, req *milvuspb.CreateRoleRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateRole")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("CreateRole", zap.Stringer("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var roleName string
|
|
|
|
if req.Entity != nil {
|
|
|
|
roleName = req.Entity.Name
|
|
|
|
}
|
|
|
|
if err := ValidateRoleName(roleName); err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
result, err := node.rootCoord.CreateRole(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to create role", zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
return result, nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) DropRole(ctx context.Context, req *milvuspb.DropRoleRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropRole")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("DropRole",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
if err := ValidateRoleName(req.RoleName); err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2022-08-15 16:40:48 +08:00
|
|
|
if IsDefaultRole(req.RoleName) {
|
2023-12-18 14:28:41 +08:00
|
|
|
err := merr.WrapErrPrivilegeNotPermitted("the role[%s] is a default role, which can't be dropped", req.GetRoleName())
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-15 16:40:48 +08:00
|
|
|
}
|
2022-08-04 11:04:34 +08:00
|
|
|
result, err := node.rootCoord.DropRole(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to drop role",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.String("role_name", req.RoleName),
|
|
|
|
zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
return result, nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) OperateUserRole(ctx context.Context, req *milvuspb.OperateUserRoleRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-OperateUserRole")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("OperateUserRole", zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
if err := ValidateUsername(req.Username); err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
if err := ValidateRoleName(req.RoleName); err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
result, err := node.rootCoord.OperateUserRole(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to operate user role", zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
return result, nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) SelectRole(ctx context.Context, req *milvuspb.SelectRoleRequest) (*milvuspb.SelectRoleResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-SelectRole")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug("SelectRole", zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.SelectRoleResponse{Status: merr.Status(err)}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if req.Role != nil {
|
|
|
|
if err := ValidateRoleName(req.Role.Name); err != nil {
|
|
|
|
return &milvuspb.SelectRoleResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-02 21:12:59 +08:00
|
|
|
}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := node.rootCoord.SelectRole(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to select role", zap.Error(err))
|
2022-08-04 11:04:34 +08:00
|
|
|
return &milvuspb.SelectRoleResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-02 21:12:59 +08:00
|
|
|
}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
return result, nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) SelectUser(ctx context.Context, req *milvuspb.SelectUserRequest) (*milvuspb.SelectUserResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-SelectUser")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Debug("SelectUser", zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.SelectUserResponse{Status: merr.Status(err)}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if req.User != nil {
|
|
|
|
if err := ValidateUsername(req.User.Name); err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("invalid username", zap.Error(err))
|
2022-08-04 11:04:34 +08:00
|
|
|
return &milvuspb.SelectUserResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-02 21:12:59 +08:00
|
|
|
}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result, err := node.rootCoord.SelectUser(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to select user", zap.Error(err))
|
2022-08-04 11:04:34 +08:00
|
|
|
return &milvuspb.SelectUserResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-02 21:12:59 +08:00
|
|
|
}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
return result, nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) validPrivilegeParams(req *milvuspb.OperatePrivilegeRequest) error {
|
|
|
|
if req.Entity == nil {
|
|
|
|
return fmt.Errorf("the entity in the request is nil")
|
|
|
|
}
|
|
|
|
if req.Entity.Grantor == nil {
|
|
|
|
return fmt.Errorf("the grantor entity in the grant entity is nil")
|
|
|
|
}
|
|
|
|
if req.Entity.Grantor.Privilege == nil {
|
|
|
|
return fmt.Errorf("the privilege entity in the grantor entity is nil")
|
|
|
|
}
|
|
|
|
if err := ValidatePrivilege(req.Entity.Grantor.Privilege.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if req.Entity.Object == nil {
|
|
|
|
return fmt.Errorf("the resource entity in the grant entity is nil")
|
|
|
|
}
|
|
|
|
if err := ValidateObjectType(req.Entity.Object.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := ValidateObjectName(req.Entity.ObjectName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if req.Entity.Role == nil {
|
|
|
|
return fmt.Errorf("the object entity in the grant entity is nil")
|
|
|
|
}
|
|
|
|
if err := ValidateRoleName(req.Entity.Role.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) OperatePrivilege(ctx context.Context, req *milvuspb.OperatePrivilegeRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-OperatePrivilege")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("OperatePrivilege",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
if err := node.validPrivilegeParams(req); err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
curUser, err := GetCurUserFromContext(ctx)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to get current user", zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
req.Entity.Grantor.User = &milvuspb.UserEntity{Name: curUser}
|
|
|
|
result, err := node.rootCoord.OperatePrivilege(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to operate privilege", zap.Error(err))
|
2023-09-04 09:57:09 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
2024-01-23 15:56:54 +08:00
|
|
|
relatedPrivileges := util.RelatedPrivileges[util.PrivilegeNameForMetastore(req.Entity.Grantor.Privilege.Name)]
|
|
|
|
if len(relatedPrivileges) != 0 {
|
|
|
|
for _, relatedPrivilege := range relatedPrivileges {
|
|
|
|
relatedReq := proto.Clone(req).(*milvuspb.OperatePrivilegeRequest)
|
|
|
|
relatedReq.Entity.Grantor.Privilege.Name = util.PrivilegeNameForAPI(relatedPrivilege)
|
|
|
|
result, err = node.rootCoord.OperatePrivilege(ctx, relatedReq)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("fail to operate related privilege", zap.String("related_privilege", relatedPrivilege), zap.Error(err))
|
|
|
|
return merr.Status(err), nil
|
|
|
|
}
|
|
|
|
if !merr.Ok(result) {
|
|
|
|
log.Warn("fail to operate related privilege", zap.String("related_privilege", relatedPrivilege), zap.Any("result", result))
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-04 11:04:34 +08:00
|
|
|
return result, nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func (node *Proxy) validGrantParams(req *milvuspb.SelectGrantRequest) error {
|
|
|
|
if req.Entity == nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.WrapErrParameterInvalidMsg("the grant entity in the request is nil")
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if req.Entity.Object != nil {
|
|
|
|
if err := ValidateObjectType(req.Entity.Object.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateObjectName(req.Entity.ObjectName); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if req.Entity.Role == nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.WrapErrParameterInvalidMsg("the role entity in the grant entity is nil")
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateRoleName(req.Entity.Role.Name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) SelectGrant(ctx context.Context, req *milvuspb.SelectGrantRequest) (*milvuspb.SelectGrantResponse, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-SelectGrant")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug("SelectGrant",
|
|
|
|
zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.SelectGrantResponse{Status: merr.Status(err)}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := node.validGrantParams(req); err != nil {
|
|
|
|
return &milvuspb.SelectGrantResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-02 21:12:59 +08:00
|
|
|
}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
result, err := node.rootCoord.SelectGrant(ctx, req)
|
|
|
|
if err != nil {
|
2023-08-04 18:37:08 +08:00
|
|
|
log.Warn("fail to select grant", zap.Error(err))
|
2022-08-04 11:04:34 +08:00
|
|
|
return &milvuspb.SelectGrantResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2022-09-02 21:12:59 +08:00
|
|
|
}, nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) RefreshPolicyInfoCache(ctx context.Context, req *proxypb.RefreshPolicyInfoCacheRequest) (*commonpb.Status, error) {
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-RefreshPolicyInfoCache")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx)
|
|
|
|
|
|
|
|
log.Debug("RefreshPrivilegeInfoCache",
|
|
|
|
zap.Any("req", req))
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if globalMetaCache != nil {
|
|
|
|
err := globalMetaCache.RefreshPolicyInfo(typeutil.CacheOp{
|
|
|
|
OpType: typeutil.CacheOpType(req.OpType),
|
|
|
|
OpKey: req.OpKey,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2023-10-09 10:09:33 +08:00
|
|
|
log.Warn("fail to refresh policy info",
|
2022-11-14 15:29:06 +08:00
|
|
|
zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2022-08-04 11:04:34 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Debug("RefreshPrivilegeInfoCache success")
|
2022-08-04 11:04:34 +08:00
|
|
|
|
2023-10-11 21:01:35 +08:00
|
|
|
return merr.Success(), nil
|
2022-05-28 00:04:01 +08:00
|
|
|
}
|
2022-09-16 09:56:47 +08:00
|
|
|
|
|
|
|
// SetRates limits the rates of requests.
|
|
|
|
func (node *Proxy) SetRates(ctx context.Context, request *proxypb.SetRatesRequest) (*commonpb.Status, error) {
|
2023-10-11 21:01:35 +08:00
|
|
|
resp := merr.Success()
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
resp = merr.Status(err)
|
2022-09-16 09:56:47 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2023-04-25 15:54:35 +08:00
|
|
|
err := node.multiRateLimiter.SetRates(request.GetRates())
|
2022-09-16 09:56:47 +08:00
|
|
|
// TODO: set multiple rate limiter rates
|
|
|
|
if err != nil {
|
2023-09-26 17:15:27 +08:00
|
|
|
resp = merr.Status(err)
|
2022-09-16 09:56:47 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2023-09-26 17:15:27 +08:00
|
|
|
|
2022-09-16 09:56:47 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
2022-10-18 13:39:26 +08:00
|
|
|
|
|
|
|
func (node *Proxy) CheckHealth(ctx context.Context, request *milvuspb.CheckHealthRequest) (*milvuspb.CheckHealthResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2022-10-20 19:47:33 +08:00
|
|
|
return &milvuspb.CheckHealthResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2022-10-20 19:47:33 +08:00
|
|
|
IsHealthy: false,
|
2023-10-11 21:01:35 +08:00
|
|
|
Reasons: []string{err.Error()},
|
2023-09-21 09:45:27 +08:00
|
|
|
}, nil
|
2022-10-18 13:39:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
group, ctx := errgroup.WithContext(ctx)
|
|
|
|
errReasons := make([]string, 0)
|
|
|
|
|
|
|
|
mu := &sync.Mutex{}
|
|
|
|
fn := func(role string, resp *milvuspb.CheckHealthResponse, err error) error {
|
|
|
|
mu.Lock()
|
|
|
|
defer mu.Unlock()
|
|
|
|
|
2023-01-12 16:09:39 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-RefreshPolicyInfoCache")
|
|
|
|
defer sp.End()
|
2022-11-14 15:29:06 +08:00
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(zap.String("role", role))
|
|
|
|
|
2022-10-18 13:39:26 +08:00
|
|
|
if err != nil {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("check health fail",
|
|
|
|
zap.Error(err))
|
2022-10-18 13:39:26 +08:00
|
|
|
errReasons = append(errReasons, fmt.Sprintf("check health fail for %s", role))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !resp.IsHealthy {
|
2022-11-14 15:29:06 +08:00
|
|
|
log.Warn("check health fail")
|
2022-10-18 13:39:26 +08:00
|
|
|
errReasons = append(errReasons, resp.Reasons...)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
group.Go(func() error {
|
|
|
|
resp, err := node.rootCoord.CheckHealth(ctx, request)
|
|
|
|
return fn("rootcoord", resp, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
group.Go(func() error {
|
|
|
|
resp, err := node.queryCoord.CheckHealth(ctx, request)
|
|
|
|
return fn("querycoord", resp, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
group.Go(func() error {
|
|
|
|
resp, err := node.dataCoord.CheckHealth(ctx, request)
|
|
|
|
return fn("datacoord", resp, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
err := group.Wait()
|
|
|
|
if err != nil || len(errReasons) != 0 {
|
|
|
|
return &milvuspb.CheckHealthResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-10-18 13:39:26 +08:00
|
|
|
IsHealthy: false,
|
|
|
|
Reasons: errReasons,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-12-30 18:35:32 +08:00
|
|
|
states, reasons := node.multiRateLimiter.GetQuotaStates()
|
2022-10-20 19:47:33 +08:00
|
|
|
return &milvuspb.CheckHealthResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2022-12-30 18:35:32 +08:00
|
|
|
QuotaStates: states,
|
|
|
|
Reasons: reasons,
|
|
|
|
IsHealthy: true,
|
2022-10-20 19:47:33 +08:00
|
|
|
}, nil
|
2022-10-18 13:39:26 +08:00
|
|
|
}
|
2023-01-12 18:31:41 +08:00
|
|
|
|
2023-01-19 14:13:43 +08:00
|
|
|
func (node *Proxy) RenameCollection(ctx context.Context, req *milvuspb.RenameCollectionRequest) (*commonpb.Status, error) {
|
2023-02-21 16:22:26 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-RenameCollection")
|
2023-01-19 14:13:43 +08:00
|
|
|
defer sp.End()
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
zap.String("oldName", req.GetOldName()),
|
|
|
|
zap.String("newName", req.GetNewName()))
|
|
|
|
|
|
|
|
log.Info("received rename collection request")
|
|
|
|
var err error
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-01-19 14:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := validateCollectionName(req.GetNewName()); err != nil {
|
|
|
|
log.Warn("validate new collection name fail", zap.Error(err))
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err), nil
|
2023-01-19 14:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
req.Base = commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_RenameCollection),
|
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
|
|
|
)
|
|
|
|
resp, err := node.rootCoord.RenameCollection(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("failed to rename collection", zap.Error(err))
|
2023-09-18 14:05:28 +08:00
|
|
|
return merr.Status(err), err
|
2023-01-19 14:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2023-01-12 18:31:41 +08:00
|
|
|
func (node *Proxy) CreateResourceGroup(ctx context.Context, request *milvuspb.CreateResourceGroupRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
method := "CreateResourceGroup"
|
|
|
|
if err := ValidateResourceGroupName(request.GetResourceGroup()); err != nil {
|
|
|
|
log.Warn("CreateResourceGroup failed",
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
return getErrResponse(err, method), nil
|
|
|
|
}
|
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-CreateResourceGroup")
|
|
|
|
defer sp.End()
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
t := &CreateResourceGroupTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
CreateResourceGroupRequest: request,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("CreateResourceGroup received")
|
2023-01-30 10:19:48 +08:00
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(t); err != nil {
|
|
|
|
log.Warn("CreateResourceGroup failed to enqueue",
|
|
|
|
zap.Error(err))
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("CreateResourceGroup enqueued",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
if err := t.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("CreateResourceGroup failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("CreateResourceGroup done",
|
2023-01-30 10:19:48 +08:00
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return t.result, nil
|
2023-01-12 18:31:41 +08:00
|
|
|
}
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
func getErrResponse(err error, method string) *commonpb.Status {
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
|
|
|
|
2023-10-09 10:09:33 +08:00
|
|
|
return merr.Status(err)
|
2023-02-07 17:52:31 +08:00
|
|
|
}
|
|
|
|
|
2023-01-12 18:31:41 +08:00
|
|
|
func (node *Proxy) DropResourceGroup(ctx context.Context, request *milvuspb.DropResourceGroupRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
method := "DropResourceGroup"
|
2023-01-30 10:19:48 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DropResourceGroup")
|
|
|
|
defer sp.End()
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
t := &DropResourceGroupTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DropResourceGroupRequest: request,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("DropResourceGroup received")
|
2023-01-30 10:19:48 +08:00
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(t); err != nil {
|
|
|
|
log.Warn("DropResourceGroup failed to enqueue",
|
|
|
|
zap.Error(err))
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("DropResourceGroup enqueued",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
if err := t.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("DropResourceGroup failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("DropResourceGroup done",
|
2023-01-30 10:19:48 +08:00
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return t.result, nil
|
2023-01-12 18:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) TransferNode(ctx context.Context, request *milvuspb.TransferNodeRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
method := "TransferNode"
|
|
|
|
if err := ValidateResourceGroupName(request.GetSourceResourceGroup()); err != nil {
|
|
|
|
log.Warn("TransferNode failed",
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
return getErrResponse(err, method), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateResourceGroupName(request.GetTargetResourceGroup()); err != nil {
|
|
|
|
log.Warn("TransferNode failed",
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
return getErrResponse(err, method), nil
|
|
|
|
}
|
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-TransferNode")
|
|
|
|
defer sp.End()
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
t := &TransferNodeTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
TransferNodeRequest: request,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("TransferNode received")
|
2023-01-30 10:19:48 +08:00
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(t); err != nil {
|
|
|
|
log.Warn("TransferNode failed to enqueue",
|
|
|
|
zap.Error(err))
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("TransferNode enqueued",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
if err := t.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("TransferNode failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("TransferNode done",
|
2023-01-30 10:19:48 +08:00
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return t.result, nil
|
2023-01-12 18:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) TransferReplica(ctx context.Context, request *milvuspb.TransferReplicaRequest) (*commonpb.Status, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return merr.Status(err), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
2023-01-12 18:31:41 +08:00
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
method := "TransferReplica"
|
|
|
|
if err := ValidateResourceGroupName(request.GetSourceResourceGroup()); err != nil {
|
|
|
|
log.Warn("TransferReplica failed",
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
return getErrResponse(err, method), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ValidateResourceGroupName(request.GetTargetResourceGroup()); err != nil {
|
|
|
|
log.Warn("TransferReplica failed",
|
|
|
|
zap.Error(err),
|
|
|
|
)
|
|
|
|
return getErrResponse(err, method), nil
|
|
|
|
}
|
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-TransferReplica")
|
|
|
|
defer sp.End()
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
t := &TransferReplicaTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
TransferReplicaRequest: request,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("TransferReplica received")
|
2023-01-30 10:19:48 +08:00
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(t); err != nil {
|
|
|
|
log.Warn("TransferReplica failed to enqueue",
|
|
|
|
zap.Error(err))
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("TransferReplica enqueued",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
if err := t.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("TransferReplica failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
2023-02-07 17:52:31 +08:00
|
|
|
return getErrResponse(err, method), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
2024-01-17 17:48:53 +08:00
|
|
|
log.Info("TransferReplica done",
|
2023-01-30 10:19:48 +08:00
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return t.result, nil
|
2023-01-12 18:31:41 +08:00
|
|
|
}
|
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
func (node *Proxy) ListResourceGroups(ctx context.Context, request *milvuspb.ListResourceGroupsRequest) (*milvuspb.ListResourceGroupsResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-01-30 10:19:48 +08:00
|
|
|
return &milvuspb.ListResourceGroupsResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-30 10:19:48 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-ListResourceGroups")
|
|
|
|
defer sp.End()
|
|
|
|
method := "ListResourceGroups"
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
t := &ListResourceGroupsTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
ListResourceGroupsRequest: request,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
|
|
|
|
|
|
|
log.Debug("ListResourceGroups received")
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(t); err != nil {
|
|
|
|
log.Warn("ListResourceGroups failed to enqueue",
|
|
|
|
zap.Error(err))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.AbandonLabel).Inc()
|
|
|
|
return &milvuspb.ListResourceGroupsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-30 10:19:48 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("ListResourceGroups enqueued",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
if err := t.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("ListResourceGroups failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.FailLabel).Inc()
|
|
|
|
return &milvuspb.ListResourceGroupsResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-30 10:19:48 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("ListResourceGroups done",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return t.result, nil
|
2023-01-12 18:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) DescribeResourceGroup(ctx context.Context, request *milvuspb.DescribeResourceGroupRequest) (*milvuspb.DescribeResourceGroupResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
2023-01-30 10:19:48 +08:00
|
|
|
return &milvuspb.DescribeResourceGroupResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(err),
|
2023-01-30 10:19:48 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
method := "DescribeResourceGroup"
|
|
|
|
GetErrResponse := func(err error) *milvuspb.DescribeResourceGroupResponse {
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method, metrics.FailLabel).Inc()
|
|
|
|
|
|
|
|
return &milvuspb.DescribeResourceGroupResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-02-07 17:52:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
ctx, sp := otel.Tracer(typeutil.ProxyRole).Start(ctx, "Proxy-DescribeResourceGroup")
|
|
|
|
defer sp.End()
|
|
|
|
tr := timerecord.NewTimeRecorder(method)
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.TotalLabel).Inc()
|
|
|
|
t := &DescribeResourceGroupTask{
|
|
|
|
ctx: ctx,
|
|
|
|
Condition: NewTaskCondition(ctx),
|
|
|
|
DescribeResourceGroupRequest: request,
|
|
|
|
queryCoord: node.queryCoord,
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Ctx(ctx).With(
|
|
|
|
zap.String("role", typeutil.ProxyRole),
|
|
|
|
)
|
|
|
|
|
|
|
|
log.Debug("DescribeResourceGroup received")
|
|
|
|
|
|
|
|
if err := node.sched.ddQueue.Enqueue(t); err != nil {
|
|
|
|
log.Warn("DescribeResourceGroup failed to enqueue",
|
|
|
|
zap.Error(err))
|
|
|
|
|
2023-02-07 17:52:31 +08:00
|
|
|
return GetErrResponse(err), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("DescribeResourceGroup enqueued",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
if err := t.WaitToFinish(); err != nil {
|
|
|
|
log.Warn("DescribeResourceGroup failed to WaitToFinish",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
2023-02-07 17:52:31 +08:00
|
|
|
return GetErrResponse(err), nil
|
2023-01-30 10:19:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("DescribeResourceGroup done",
|
|
|
|
zap.Uint64("BeginTS", t.BeginTs()),
|
|
|
|
zap.Uint64("EndTS", t.EndTs()))
|
|
|
|
|
|
|
|
metrics.ProxyFunctionCall.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method,
|
|
|
|
metrics.SuccessLabel).Inc()
|
|
|
|
metrics.ProxyReqLatency.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), method).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return t.result, nil
|
2023-01-12 18:31:41 +08:00
|
|
|
}
|
2023-03-30 11:28:25 +08:00
|
|
|
|
|
|
|
func (node *Proxy) ListIndexedSegment(ctx context.Context, request *federpb.ListIndexedSegmentRequest) (*federpb.ListIndexedSegmentResponse, error) {
|
2023-05-31 20:24:31 +08:00
|
|
|
return &federpb.ListIndexedSegmentResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrServiceUnavailable("unimp")),
|
2023-05-31 20:24:31 +08:00
|
|
|
}, nil
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *Proxy) DescribeSegmentIndexData(ctx context.Context, request *federpb.DescribeSegmentIndexDataRequest) (*federpb.DescribeSegmentIndexDataResponse, error) {
|
2023-05-31 20:24:31 +08:00
|
|
|
return &federpb.DescribeSegmentIndexDataResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrServiceUnavailable("unimp")),
|
2023-05-31 20:24:31 +08:00
|
|
|
}, nil
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
2023-05-19 12:51:23 +08:00
|
|
|
|
|
|
|
func (node *Proxy) Connect(ctx context.Context, request *milvuspb.ConnectRequest) (*milvuspb.ConnectResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.ConnectResponse{Status: merr.Status(err)}, nil
|
2023-05-19 12:51:23 +08:00
|
|
|
}
|
|
|
|
|
2023-08-03 15:53:07 +08:00
|
|
|
db := GetCurDBNameFromContextOrDefault(ctx)
|
2023-12-05 16:50:47 +08:00
|
|
|
logsToBePrinted := append(connection.ZapClientInfo(request.GetClientInfo()), zap.String("db", db))
|
2023-08-03 15:53:07 +08:00
|
|
|
log := log.Ctx(ctx).With(logsToBePrinted...)
|
|
|
|
|
|
|
|
log.Info("connect received")
|
|
|
|
|
|
|
|
resp, err := node.rootCoord.ListDatabases(ctx, &milvuspb.ListDatabasesRequest{
|
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_ListDatabases),
|
|
|
|
),
|
|
|
|
})
|
2023-09-15 10:09:21 +08:00
|
|
|
if err == nil {
|
|
|
|
err = merr.Error(resp.GetStatus())
|
|
|
|
}
|
2023-08-03 15:53:07 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Info("connect failed, failed to list databases", zap.Error(err))
|
|
|
|
return &milvuspb.ConnectResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-08-03 15:53:07 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !funcutil.SliceContain(resp.GetDbNames(), db) {
|
|
|
|
log.Info("connect failed, target database not exist")
|
|
|
|
return &milvuspb.ConnectResponse{
|
2023-10-09 10:09:33 +08:00
|
|
|
Status: merr.Status(merr.WrapErrDatabaseNotFound(db)),
|
2023-08-03 15:53:07 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-05-19 12:51:23 +08:00
|
|
|
ts, err := node.tsoAllocator.AllocOne(ctx)
|
|
|
|
if err != nil {
|
2023-08-03 15:53:07 +08:00
|
|
|
log.Info("connect failed, failed to allocate timestamp", zap.Error(err))
|
2023-05-19 12:51:23 +08:00
|
|
|
return &milvuspb.ConnectResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-05-19 12:51:23 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
serverInfo := &commonpb.ServerInfo{
|
|
|
|
BuildTags: os.Getenv(metricsinfo.GitBuildTagsEnvKey),
|
|
|
|
BuildTime: os.Getenv(metricsinfo.MilvusBuildTimeEnvKey),
|
|
|
|
GitCommit: os.Getenv(metricsinfo.GitCommitEnvKey),
|
|
|
|
GoVersion: os.Getenv(metricsinfo.MilvusUsedGoVersion),
|
|
|
|
DeployMode: os.Getenv(metricsinfo.DeployModeEnvKey),
|
|
|
|
Reserved: make(map[string]string),
|
|
|
|
}
|
|
|
|
|
2023-12-05 16:50:47 +08:00
|
|
|
connection.GetManager().Register(ctx, int64(ts), request.GetClientInfo())
|
2023-05-19 12:51:23 +08:00
|
|
|
|
|
|
|
return &milvuspb.ConnectResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-05-19 12:51:23 +08:00
|
|
|
ServerInfo: serverInfo,
|
|
|
|
Identifier: int64(ts),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:26:09 +08:00
|
|
|
func (node *Proxy) ReplicateMessage(ctx context.Context, req *milvuspb.ReplicateMessageRequest) (*milvuspb.ReplicateMessageResponse, error) {
|
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if paramtable.Get().CommonCfg.TTMsgEnabled.GetAsBool() {
|
|
|
|
return &milvuspb.ReplicateMessageResponse{
|
|
|
|
Status: merr.Status(merr.ErrDenyReplicateMessage),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
ctxLog := log.Ctx(ctx)
|
|
|
|
|
|
|
|
if req.GetChannelName() == "" {
|
|
|
|
ctxLog.Warn("channel name is empty")
|
|
|
|
return &milvuspb.ReplicateMessageResponse{
|
|
|
|
Status: merr.Status(merr.WrapErrParameterInvalidMsg("invalid channel name for the replicate message request")),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the latest position of the replicate msg channel
|
|
|
|
replicateMsgChannel := Params.CommonCfg.ReplicateMsgChannel.GetValue()
|
|
|
|
if req.GetChannelName() == replicateMsgChannel {
|
|
|
|
msgID, err := msgstream.GetChannelLatestMsgID(ctx, node.factory, replicateMsgChannel)
|
|
|
|
if err != nil {
|
|
|
|
ctxLog.Warn("failed to get the latest message id of the replicate msg channel", zap.Error(err))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
position := base64.StdEncoding.EncodeToString(msgID)
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(nil), Position: position}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msgPack := &msgstream.MsgPack{
|
|
|
|
BeginTs: req.BeginTs,
|
|
|
|
EndTs: req.EndTs,
|
|
|
|
Msgs: make([]msgstream.TsMsg, 0),
|
|
|
|
StartPositions: req.StartPositions,
|
|
|
|
EndPositions: req.EndPositions,
|
|
|
|
}
|
|
|
|
// getTsMsgFromConsumerMsg
|
|
|
|
for i, msgBytes := range req.Msgs {
|
|
|
|
header := commonpb.MsgHeader{}
|
|
|
|
err = proto.Unmarshal(msgBytes, &header)
|
|
|
|
if err != nil {
|
|
|
|
ctxLog.Warn("failed to unmarshal msg header", zap.Int("index", i), zap.Error(err))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
if header.GetBase() == nil {
|
|
|
|
ctxLog.Warn("msg header base is nil", zap.Int("index", i))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(merr.ErrInvalidMsgBytes)}, nil
|
|
|
|
}
|
|
|
|
tsMsg, err := node.replicateStreamManager.GetMsgDispatcher().Unmarshal(msgBytes, header.GetBase().GetMsgType())
|
|
|
|
if err != nil {
|
|
|
|
ctxLog.Warn("failed to unmarshal msg", zap.Int("index", i), zap.Error(err))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(merr.ErrInvalidMsgBytes)}, nil
|
|
|
|
}
|
|
|
|
switch realMsg := tsMsg.(type) {
|
|
|
|
case *msgstream.InsertMsg:
|
|
|
|
assignedSegmentInfos, err := node.segAssigner.GetSegmentID(realMsg.GetCollectionID(), realMsg.GetPartitionID(),
|
|
|
|
realMsg.GetShardName(), uint32(realMsg.NumRows), req.EndTs)
|
|
|
|
if err != nil {
|
|
|
|
ctxLog.Warn("failed to get segment id", zap.Error(err))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
if len(assignedSegmentInfos) == 0 {
|
|
|
|
ctxLog.Warn("no segment id assigned")
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(merr.ErrNoAssignSegmentID)}, nil
|
|
|
|
}
|
|
|
|
for assignSegmentID := range assignedSegmentInfos {
|
|
|
|
realMsg.SegmentID = assignSegmentID
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, tsMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
msgStream, err := node.replicateStreamManager.GetReplicateMsgStream(ctx, req.ChannelName)
|
|
|
|
if err != nil {
|
|
|
|
ctxLog.Warn("failed to get msg stream from the replicate stream manager", zap.Error(err))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
messageIDsMap, err := msgStream.Broadcast(msgPack)
|
|
|
|
if err != nil {
|
|
|
|
ctxLog.Warn("failed to produce msg", zap.Error(err))
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(err)}, nil
|
|
|
|
}
|
|
|
|
var position string
|
|
|
|
if len(messageIDsMap[req.GetChannelName()]) == 0 {
|
|
|
|
ctxLog.Warn("no message id returned")
|
|
|
|
} else {
|
|
|
|
messageIDs := messageIDsMap[req.GetChannelName()]
|
|
|
|
position = base64.StdEncoding.EncodeToString(messageIDs[len(messageIDs)-1].Serialize())
|
|
|
|
}
|
|
|
|
return &milvuspb.ReplicateMessageResponse{Status: merr.Status(nil), Position: position}, nil
|
|
|
|
}
|
|
|
|
|
2023-05-19 12:51:23 +08:00
|
|
|
func (node *Proxy) ListClientInfos(ctx context.Context, req *proxypb.ListClientInfosRequest) (*proxypb.ListClientInfosResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &proxypb.ListClientInfosResponse{Status: merr.Status(err)}, nil
|
2023-05-19 12:51:23 +08:00
|
|
|
}
|
|
|
|
|
2023-12-05 16:50:47 +08:00
|
|
|
clients := connection.GetManager().List()
|
2023-05-19 12:51:23 +08:00
|
|
|
return &proxypb.ListClientInfosResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-05-19 12:51:23 +08:00
|
|
|
ClientInfos: clients,
|
|
|
|
}, nil
|
|
|
|
}
|
2023-07-25 10:05:00 +08:00
|
|
|
|
|
|
|
func (node *Proxy) AllocTimestamp(ctx context.Context, req *milvuspb.AllocTimestampRequest) (*milvuspb.AllocTimestampResponse, error) {
|
2023-10-09 10:09:33 +08:00
|
|
|
if err := merr.CheckHealthy(node.GetStateCode()); err != nil {
|
|
|
|
return &milvuspb.AllocTimestampResponse{Status: merr.Status(err)}, nil
|
2023-07-25 10:05:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("AllocTimestamp request receive")
|
|
|
|
ts, err := node.tsoAllocator.AllocOne(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Info("AllocTimestamp failed", zap.Error(err))
|
|
|
|
return &milvuspb.AllocTimestampResponse{
|
2023-09-04 09:57:09 +08:00
|
|
|
Status: merr.Status(err),
|
2023-07-25 10:05:00 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("AllocTimestamp request success", zap.Uint64("timestamp", ts))
|
|
|
|
|
|
|
|
return &milvuspb.AllocTimestampResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-07-25 10:05:00 +08:00
|
|
|
Timestamp: ts,
|
|
|
|
}, nil
|
|
|
|
}
|
2023-09-26 09:57:25 +08:00
|
|
|
|
|
|
|
func (node *Proxy) GetVersion(ctx context.Context, request *milvuspb.GetVersionRequest) (*milvuspb.GetVersionResponse, error) {
|
|
|
|
// TODO implement me
|
|
|
|
return &milvuspb.GetVersionResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-26 09:57:25 +08:00
|
|
|
}, nil
|
|
|
|
}
|