2021-12-20 17:45:37 +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 11:12:56 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-20 17:45:37 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 11:12:56 +08:00
|
|
|
//
|
2021-12-20 17:45:37 +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 11:12:56 +08:00
|
|
|
|
2021-06-18 21:30:08 +08:00
|
|
|
package rootcoord
|
2021-01-19 14:44:03 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-14 10:05:18 +08:00
|
|
|
"encoding/json"
|
2022-04-25 11:07:47 +08:00
|
|
|
"errors"
|
2021-01-25 18:33:10 +08:00
|
|
|
"fmt"
|
2021-01-19 14:44:03 +08:00
|
|
|
"math/rand"
|
2022-03-17 17:17:22 +08:00
|
|
|
"os"
|
2021-08-18 14:36:10 +08:00
|
|
|
"strconv"
|
2022-01-27 11:25:41 +08:00
|
|
|
"strings"
|
2021-01-19 14:44:03 +08:00
|
|
|
"sync"
|
|
|
|
"sync/atomic"
|
2021-11-22 16:23:17 +08:00
|
|
|
"syscall"
|
2021-01-19 14:44:03 +08:00
|
|
|
"time"
|
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2022-04-07 22:05:32 +08:00
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
2021-12-17 14:13:16 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/common"
|
2021-10-01 11:08:24 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/kv"
|
2021-04-22 14:45:57 +08:00
|
|
|
etcdkv "github.com/milvus-io/milvus/internal/kv/etcd"
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
2021-06-01 11:04:31 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/metrics"
|
2022-03-03 21:57:56 +08:00
|
|
|
ms "github.com/milvus-io/milvus/internal/mq/msgstream"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-05-15 18:08:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/proxypb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2021-06-22 16:14:09 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2021-05-15 18:08:08 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/tso"
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2022-04-21 19:57:42 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/crypto"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2021-10-01 11:08:24 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2021-12-23 18:39:11 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/retry"
|
2021-05-21 19:28:52 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2022-03-28 16:41:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/timerecord"
|
2021-06-30 16:18:13 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/trace"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/tsoutil"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2021-01-19 14:44:03 +08:00
|
|
|
)
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
// UniqueID is an alias of typeutil.UniqueID.
|
|
|
|
type UniqueID = typeutil.UniqueID
|
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
// ------------------ struct -----------------------
|
|
|
|
|
2021-12-23 14:34:13 +08:00
|
|
|
// DdOperation used to save ddMsg into etcd
|
2021-05-14 21:26:06 +08:00
|
|
|
type DdOperation struct {
|
2021-09-23 10:37:54 +08:00
|
|
|
Body []byte `json:"body"`
|
2021-07-06 09:16:03 +08:00
|
|
|
Type string `json:"type"`
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
func metricProxy(v int64) string {
|
2021-06-01 11:04:31 +08:00
|
|
|
return fmt.Sprintf("client_%d", v)
|
|
|
|
}
|
|
|
|
|
2022-04-03 11:37:29 +08:00
|
|
|
var Params paramtable.ComponentParam
|
2021-12-23 18:39:11 +08:00
|
|
|
|
2021-06-17 16:47:57 +08:00
|
|
|
// Core root coordinator core
|
2021-01-19 14:44:03 +08:00
|
|
|
type Core struct {
|
2021-09-23 15:10:00 +08:00
|
|
|
MetaTable *MetaTable
|
2021-01-19 14:44:03 +08:00
|
|
|
//id allocator
|
2021-05-20 14:14:14 +08:00
|
|
|
IDAllocator func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error)
|
|
|
|
IDAllocatorUpdate func() error
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
//tso allocator
|
2022-03-02 21:11:57 +08:00
|
|
|
TSOAllocator func(count uint32) (typeutil.Timestamp, error)
|
|
|
|
TSOAllocatorUpdate func() error
|
|
|
|
TSOGetLastSavedTime func() time.Time
|
2021-01-19 14:44:03 +08:00
|
|
|
|
|
|
|
//inner members
|
2022-03-25 11:03:25 +08:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
wg sync.WaitGroup
|
|
|
|
etcdCli *clientv3.Client
|
|
|
|
kvBase kv.TxnKV //*etcdkv.EtcdKV
|
|
|
|
impTaskKv kv.MetaKv
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2021-08-18 14:36:10 +08:00
|
|
|
//DDL lock
|
|
|
|
ddlLock sync.Mutex
|
|
|
|
|
2021-09-15 22:05:49 +08:00
|
|
|
kvBaseCreate func(root string) (kv.TxnKV, error)
|
|
|
|
|
2022-03-25 11:03:25 +08:00
|
|
|
metaKVCreate func(root string) (kv.MetaKv, error)
|
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
//setMsgStreams, send time tick into dd channel and time tick channel
|
2021-08-18 14:36:10 +08:00
|
|
|
SendTimeTick func(t typeutil.Timestamp, reason string) error
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
//setMsgStreams, send create collection into dd channel
|
2021-09-27 18:10:00 +08:00
|
|
|
//returns corresponding message id for each channel
|
|
|
|
SendDdCreateCollectionReq func(ctx context.Context, req *internalpb.CreateCollectionRequest, channelNames []string) (map[string][]byte, error)
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
//setMsgStreams, send drop collection into dd channel, and notify the proxy to delete this collection
|
2021-06-11 16:39:29 +08:00
|
|
|
SendDdDropCollectionReq func(ctx context.Context, req *internalpb.DropCollectionRequest, channelNames []string) error
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
//setMsgStreams, send create partition into dd channel
|
2021-06-11 16:39:29 +08:00
|
|
|
SendDdCreatePartitionReq func(ctx context.Context, req *internalpb.CreatePartitionRequest, channelNames []string) error
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
//setMsgStreams, send drop partition into dd channel
|
2021-06-11 16:39:29 +08:00
|
|
|
SendDdDropPartitionReq func(ctx context.Context, req *internalpb.DropPartitionRequest, channelNames []string) error
|
2021-01-19 14:44:03 +08:00
|
|
|
|
2021-02-05 14:09:55 +08:00
|
|
|
//get binlog file path from data service,
|
2021-06-30 16:18:13 +08:00
|
|
|
CallGetBinlogFilePathsService func(ctx context.Context, segID typeutil.UniqueID, fieldID typeutil.UniqueID) ([]string, error)
|
|
|
|
CallGetNumRowsService func(ctx context.Context, segID typeutil.UniqueID, isFromFlushedChan bool) (int64, error)
|
2021-07-03 14:36:18 +08:00
|
|
|
CallGetFlushedSegmentsService func(ctx context.Context, collID, partID typeutil.UniqueID) ([]typeutil.UniqueID, error)
|
2021-01-21 10:01:29 +08:00
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
//call index builder's client to build index, return build id or get index state.
|
|
|
|
CallBuildIndexService func(ctx context.Context, binlog []string, field *schemapb.FieldSchema, idxInfo *etcdpb.IndexInfo, numRows int64) (typeutil.UniqueID, error)
|
|
|
|
CallDropIndexService func(ctx context.Context, indexID typeutil.UniqueID) error
|
|
|
|
CallGetIndexStatesService func(ctx context.Context, IndexBuildIDs []int64) ([]*indexpb.IndexInfo, error)
|
2021-01-21 10:01:29 +08:00
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
NewProxyClient func(sess *sessionutil.Session) (types.Proxy, error)
|
2021-01-23 10:12:41 +08:00
|
|
|
|
2021-02-05 14:09:55 +08:00
|
|
|
//query service interface, notify query service to release collection
|
2021-06-22 16:08:08 +08:00
|
|
|
CallReleaseCollectionService func(ctx context.Context, ts typeutil.Timestamp, dbID, collectionID typeutil.UniqueID) error
|
|
|
|
CallReleasePartitionService func(ctx context.Context, ts typeutil.Timestamp, dbID, collectionID typeutil.UniqueID, partitionIDs []typeutil.UniqueID) error
|
2021-02-05 14:09:55 +08:00
|
|
|
|
2021-11-11 00:54:45 +08:00
|
|
|
CallWatchChannels func(ctx context.Context, collectionID int64, channelNames []string) error
|
|
|
|
|
2022-04-06 15:33:32 +08:00
|
|
|
// Update segment state.
|
|
|
|
CallUpdateSegmentStateService func(ctx context.Context, segID typeutil.UniqueID, ss commonpb.SegmentState) error
|
|
|
|
|
2022-03-21 15:47:23 +08:00
|
|
|
//assign import task to data service
|
2022-04-01 11:33:28 +08:00
|
|
|
CallImportService func(ctx context.Context, req *datapb.ImportTaskRequest) *datapb.ImportTaskResponse
|
2022-03-21 15:47:23 +08:00
|
|
|
|
2022-04-25 11:07:47 +08:00
|
|
|
// Seals segments in collection cID, so they can get flushed later.
|
|
|
|
CallFlushOnCollection func(ctx context.Context, cID int64, segIDs []int64) error
|
|
|
|
|
2021-06-22 19:08:03 +08:00
|
|
|
//Proxy manager
|
|
|
|
proxyManager *proxyManager
|
2021-05-26 20:14:30 +08:00
|
|
|
|
|
|
|
// proxy clients
|
|
|
|
proxyClientManager *proxyClientManager
|
|
|
|
|
2021-09-03 17:15:26 +08:00
|
|
|
// metrics cache manager
|
|
|
|
metricsCacheManager *metricsinfo.MetricsCacheManager
|
|
|
|
|
2021-05-21 16:08:12 +08:00
|
|
|
// channel timetick
|
|
|
|
chanTimeTick *timetickSync
|
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
//time tick loop
|
|
|
|
lastTimeTick typeutil.Timestamp
|
|
|
|
|
|
|
|
//states code
|
|
|
|
stateCode atomic.Value
|
|
|
|
|
|
|
|
//call once
|
|
|
|
initOnce sync.Once
|
|
|
|
startOnce sync.Once
|
2021-02-23 11:40:30 +08:00
|
|
|
//isInit atomic.Value
|
2021-02-08 14:30:54 +08:00
|
|
|
|
2021-10-14 16:40:35 +08:00
|
|
|
session *sessionutil.Session
|
2021-05-21 19:28:52 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
factory dependency.Factory
|
2022-03-21 15:47:23 +08:00
|
|
|
|
|
|
|
//import manager
|
|
|
|
importManager *importManager
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------- function --------------------------
|
|
|
|
|
2021-12-28 19:47:21 +08:00
|
|
|
// NewCore creates a new rootcoord core
|
2022-04-07 22:05:32 +08:00
|
|
|
func NewCore(c context.Context, factory dependency.Factory) (*Core, error) {
|
2021-01-19 14:44:03 +08:00
|
|
|
ctx, cancel := context.WithCancel(c)
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
core := &Core{
|
2022-04-07 22:05:32 +08:00
|
|
|
ctx: ctx,
|
|
|
|
cancel: cancel,
|
|
|
|
ddlLock: sync.Mutex{},
|
|
|
|
factory: factory,
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
core.UpdateStateCode(internalpb.StateCode_Abnormal)
|
2021-01-19 14:44:03 +08:00
|
|
|
return core, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// UpdateStateCode update state code
|
2021-03-12 14:22:09 +08:00
|
|
|
func (c *Core) UpdateStateCode(code internalpb.StateCode) {
|
2021-02-23 11:40:30 +08:00
|
|
|
c.stateCode.Store(code)
|
|
|
|
}
|
|
|
|
|
2021-11-19 12:11:12 +08:00
|
|
|
func (c *Core) checkHealthy() (internalpb.StateCode, bool) {
|
2021-08-31 11:45:59 +08:00
|
|
|
code := c.stateCode.Load().(internalpb.StateCode)
|
2021-11-19 12:11:12 +08:00
|
|
|
ok := code == internalpb.StateCode_Healthy
|
|
|
|
return code, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func failStatus(code commonpb.ErrorCode, reason string) *commonpb.Status {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: code,
|
|
|
|
Reason: reason,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func succStatus() *commonpb.Status {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
Reason: "",
|
|
|
|
}
|
2021-08-31 11:45:59 +08:00
|
|
|
}
|
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
func (c *Core) checkInit() error {
|
|
|
|
if c.MetaTable == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("metaTable is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
if c.IDAllocator == nil {
|
2021-04-08 15:26:18 +08:00
|
|
|
return fmt.Errorf("idAllocator is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
if c.IDAllocatorUpdate == nil {
|
2021-04-08 17:31:39 +08:00
|
|
|
return fmt.Errorf("idAllocatorUpdate is nil")
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
if c.TSOAllocator == nil {
|
2021-04-08 15:26:18 +08:00
|
|
|
return fmt.Errorf("tsoAllocator is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
if c.TSOAllocatorUpdate == nil {
|
2021-04-08 17:31:39 +08:00
|
|
|
return fmt.Errorf("tsoAllocatorUpdate is nil")
|
|
|
|
}
|
2021-01-19 14:44:03 +08:00
|
|
|
if c.etcdCli == nil {
|
2021-04-08 15:26:18 +08:00
|
|
|
return fmt.Errorf("etcdCli is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
if c.kvBase == nil {
|
2021-04-08 15:26:18 +08:00
|
|
|
return fmt.Errorf("kvBase is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2022-03-25 11:03:25 +08:00
|
|
|
if c.impTaskKv == nil {
|
|
|
|
return fmt.Errorf("impTaskKv is nil")
|
|
|
|
}
|
2021-05-14 21:26:06 +08:00
|
|
|
if c.SendDdCreateCollectionReq == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("sendDdCreateCollectionReq is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-14 21:26:06 +08:00
|
|
|
if c.SendDdDropCollectionReq == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("sendDdDropCollectionReq is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-14 21:26:06 +08:00
|
|
|
if c.SendDdCreatePartitionReq == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("sendDdCreatePartitionReq is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-14 21:26:06 +08:00
|
|
|
if c.SendDdDropPartitionReq == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("sendDdDropPartitionReq is nil")
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-05-25 14:03:06 +08:00
|
|
|
if c.CallGetBinlogFilePathsService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callGetBinlogFilePathsService is nil")
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2021-05-25 14:03:06 +08:00
|
|
|
if c.CallGetNumRowsService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callGetNumRowsService is nil")
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
2021-05-25 14:03:06 +08:00
|
|
|
if c.CallBuildIndexService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callBuildIndexService is nil")
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2021-05-25 14:03:06 +08:00
|
|
|
if c.CallDropIndexService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callDropIndexService is nil")
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
2021-07-03 14:36:18 +08:00
|
|
|
if c.CallGetFlushedSegmentsService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callGetFlushedSegmentsService is nil")
|
2021-07-03 14:36:18 +08:00
|
|
|
}
|
2022-04-06 15:33:32 +08:00
|
|
|
if c.CallUpdateSegmentStateService == nil {
|
|
|
|
return fmt.Errorf("CallUpdateSegmentStateService is nil")
|
|
|
|
}
|
2021-11-11 00:54:45 +08:00
|
|
|
if c.CallWatchChannels == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callWatchChannels is nil")
|
2021-11-11 00:54:45 +08:00
|
|
|
}
|
2021-05-26 20:14:30 +08:00
|
|
|
if c.NewProxyClient == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("newProxyClient is nil")
|
2021-05-25 14:03:06 +08:00
|
|
|
}
|
|
|
|
if c.CallReleaseCollectionService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callReleaseCollectionService is nil")
|
2021-01-23 10:12:41 +08:00
|
|
|
}
|
2021-06-22 16:08:08 +08:00
|
|
|
if c.CallReleasePartitionService == nil {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("callReleasePartitionService is nil")
|
2021-06-22 16:08:08 +08:00
|
|
|
}
|
2022-03-21 15:47:23 +08:00
|
|
|
if c.CallImportService == nil {
|
|
|
|
return fmt.Errorf("callImportService is nil")
|
|
|
|
}
|
2021-05-26 20:14:30 +08:00
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) startTimeTickLoop() {
|
2021-09-17 12:37:50 +08:00
|
|
|
defer c.wg.Done()
|
2021-12-27 21:38:45 +08:00
|
|
|
ticker := time.NewTicker(Params.ProxyCfg.TimeTickInterval)
|
2021-05-31 16:48:31 +08:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-c.ctx.Done():
|
2021-06-17 16:47:57 +08:00
|
|
|
log.Debug("rootcoord context closed", zap.Error(c.ctx.Err()))
|
2021-05-31 16:48:31 +08:00
|
|
|
return
|
|
|
|
case <-ticker.C:
|
2021-08-18 14:36:10 +08:00
|
|
|
c.ddlLock.Lock()
|
2021-06-23 15:28:09 +08:00
|
|
|
if ts, err := c.TSOAllocator(1); err == nil {
|
2022-01-14 23:55:34 +08:00
|
|
|
err := c.SendTimeTick(ts, "timetick loop")
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Failed to send timetick", zap.Error(err))
|
|
|
|
}
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-08-18 14:36:10 +08:00
|
|
|
c.ddlLock.Unlock()
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:38:18 +08:00
|
|
|
func (c *Core) tsLoop() {
|
2021-09-17 12:37:50 +08:00
|
|
|
defer c.wg.Done()
|
2021-02-24 17:12:06 +08:00
|
|
|
tsoTicker := time.NewTicker(tso.UpdateTimestampStep)
|
2021-01-27 16:38:18 +08:00
|
|
|
defer tsoTicker.Stop()
|
|
|
|
ctx, cancel := context.WithCancel(c.ctx)
|
|
|
|
defer cancel()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-tsoTicker.C:
|
2021-05-20 14:14:14 +08:00
|
|
|
if err := c.TSOAllocatorUpdate(); err != nil {
|
2021-03-15 15:45:17 +08:00
|
|
|
log.Warn("failed to update timestamp: ", zap.Error(err))
|
|
|
|
continue
|
2021-01-27 16:38:18 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
ts := c.TSOGetLastSavedTime()
|
|
|
|
metrics.RootCoordETCDTimestampAllocCounter.Set(float64(ts.Unix()))
|
2021-05-20 14:14:14 +08:00
|
|
|
if err := c.IDAllocatorUpdate(); err != nil {
|
2021-03-15 15:45:17 +08:00
|
|
|
log.Warn("failed to update id: ", zap.Error(err))
|
|
|
|
continue
|
2021-01-27 16:38:18 +08:00
|
|
|
}
|
|
|
|
case <-ctx.Done():
|
|
|
|
// Server is closed and it should return nil.
|
2021-02-27 10:11:52 +08:00
|
|
|
log.Debug("tsLoop is closed")
|
2021-01-27 16:38:18 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-14 21:26:06 +08:00
|
|
|
|
2021-07-03 17:54:25 +08:00
|
|
|
func (c *Core) checkFlushedSegmentsLoop() {
|
2021-09-17 12:37:50 +08:00
|
|
|
defer c.wg.Done()
|
2021-07-03 17:54:25 +08:00
|
|
|
ticker := time.NewTicker(10 * time.Minute)
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-c.ctx.Done():
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("RootCoord context done, exit check FlushedSegmentsLoop")
|
2021-07-03 17:54:25 +08:00
|
|
|
return
|
|
|
|
case <-ticker.C:
|
|
|
|
log.Debug("check flushed segments")
|
2021-08-25 14:41:52 +08:00
|
|
|
c.checkFlushedSegments(c.ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Core) checkFlushedSegments(ctx context.Context) {
|
|
|
|
collID2Meta, segID2IndexMeta, indexID2Meta := c.MetaTable.dupMeta()
|
|
|
|
for _, collMeta := range collID2Meta {
|
|
|
|
if len(collMeta.FieldIndexes) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, partID := range collMeta.PartitionIDs {
|
|
|
|
ctx2, cancel2 := context.WithTimeout(ctx, 3*time.Minute)
|
|
|
|
segIDs, err := c.CallGetFlushedSegmentsService(ctx2, collMeta.ID, partID)
|
|
|
|
if err != nil {
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("failed to get flushed segments from data coord",
|
2021-08-25 14:41:52 +08:00
|
|
|
zap.Int64("collection id", collMeta.ID),
|
|
|
|
zap.Int64("partition id", partID),
|
|
|
|
zap.Error(err))
|
2022-03-28 16:41:28 +08:00
|
|
|
cancel2()
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, segID := range segIDs {
|
|
|
|
indexInfos := []*etcdpb.FieldIndexInfo{}
|
|
|
|
indexMeta, ok := segID2IndexMeta[segID]
|
|
|
|
if !ok {
|
|
|
|
indexInfos = append(indexInfos, collMeta.FieldIndexes...)
|
|
|
|
} else {
|
|
|
|
for _, idx := range collMeta.FieldIndexes {
|
|
|
|
if _, ok := indexMeta[idx.IndexID]; !ok {
|
|
|
|
indexInfos = append(indexInfos, idx)
|
2021-07-03 17:54:25 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-28 16:41:28 +08:00
|
|
|
}
|
|
|
|
for _, idxInfo := range indexInfos {
|
|
|
|
/* #nosec G601 */
|
|
|
|
field, err := GetFieldSchemaByID(&collMeta, idxInfo.FiledID)
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("GetFieldSchemaByID",
|
|
|
|
zap.Any("collection_meta", collMeta),
|
|
|
|
zap.Int64("field id", idxInfo.FiledID))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
indexMeta, ok := indexID2Meta[idxInfo.IndexID]
|
|
|
|
if !ok {
|
|
|
|
log.Debug("index meta does not exist", zap.Int64("index_id", idxInfo.IndexID))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
info := etcdpb.SegmentIndexInfo{
|
|
|
|
CollectionID: collMeta.ID,
|
|
|
|
PartitionID: partID,
|
|
|
|
SegmentID: segID,
|
|
|
|
FieldID: idxInfo.FiledID,
|
|
|
|
IndexID: idxInfo.IndexID,
|
|
|
|
EnableIndex: false,
|
|
|
|
}
|
|
|
|
log.Debug("building index by background checker",
|
|
|
|
zap.Int64("segment_id", segID),
|
|
|
|
zap.Int64("index_id", indexMeta.IndexID),
|
|
|
|
zap.Int64("collection_id", collMeta.ID))
|
|
|
|
info.BuildID, err = c.BuildIndex(ctx2, segID, field, &indexMeta, false)
|
|
|
|
if err != nil {
|
|
|
|
log.Debug("build index failed",
|
2021-08-25 14:41:52 +08:00
|
|
|
zap.Int64("segment_id", segID),
|
2022-03-28 16:41:28 +08:00
|
|
|
zap.Int64("field_id", field.FieldID),
|
|
|
|
zap.Int64("index_id", indexMeta.IndexID))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if info.BuildID != 0 {
|
|
|
|
info.EnableIndex = true
|
|
|
|
}
|
|
|
|
if err := c.MetaTable.AddIndex(&info); err != nil {
|
|
|
|
log.Debug("Add index into meta table failed",
|
|
|
|
zap.Int64("collection_id", collMeta.ID),
|
|
|
|
zap.Int64("index_id", info.IndexID),
|
|
|
|
zap.Int64("build_id", info.BuildID),
|
|
|
|
zap.Error(err))
|
2021-08-25 14:41:52 +08:00
|
|
|
}
|
2021-07-03 17:54:25 +08:00
|
|
|
}
|
|
|
|
}
|
2021-08-25 14:41:52 +08:00
|
|
|
cancel2()
|
2021-07-03 17:54:25 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-26 20:14:30 +08:00
|
|
|
}
|
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
func (c *Core) getSegments(ctx context.Context, collID typeutil.UniqueID) (map[typeutil.UniqueID]typeutil.UniqueID, error) {
|
|
|
|
collMeta, err := c.MetaTable.GetCollectionByID(collID, 0)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
segID2PartID := map[typeutil.UniqueID]typeutil.UniqueID{}
|
|
|
|
for _, partID := range collMeta.PartitionIDs {
|
|
|
|
if seg, err := c.CallGetFlushedSegmentsService(ctx, collID, partID); err == nil {
|
|
|
|
for _, s := range seg {
|
|
|
|
segID2PartID[s] = partID
|
|
|
|
}
|
|
|
|
} else {
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("failed to get flushed segments from data coord", zap.Int64("collection_id", collID), zap.Int64("partition_id", partID), zap.Error(err))
|
2021-07-03 14:36:18 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return segID2PartID, nil
|
|
|
|
}
|
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
func (c *Core) setMsgStreams() error {
|
2022-03-04 11:17:56 +08:00
|
|
|
if Params.CommonCfg.RootCoordSubName == "" {
|
2022-02-02 00:35:43 +08:00
|
|
|
return fmt.Errorf("RootCoordSubName is empty")
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
|
|
|
|
2021-08-18 14:36:10 +08:00
|
|
|
c.SendTimeTick = func(t typeutil.Timestamp, reason string) error {
|
2021-11-25 10:07:15 +08:00
|
|
|
pc := c.chanTimeTick.listDmlChannels()
|
2021-06-04 15:00:34 +08:00
|
|
|
pt := make([]uint64, len(pc))
|
|
|
|
for i := 0; i < len(pt); i++ {
|
|
|
|
pt[i] = t
|
|
|
|
}
|
|
|
|
ttMsg := internalpb.ChannelTimeTickMsg{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
MsgID: 0, //TODO
|
|
|
|
Timestamp: t,
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
2021-06-17 15:54:07 +08:00
|
|
|
ChannelNames: pc,
|
|
|
|
Timestamps: pt,
|
|
|
|
DefaultTimestamp: t,
|
2021-06-04 15:00:34 +08:00
|
|
|
}
|
2021-11-25 10:07:15 +08:00
|
|
|
return c.chanTimeTick.updateTimeTick(&ttMsg, reason)
|
2021-01-20 09:36:50 +08:00
|
|
|
}
|
|
|
|
|
2021-09-27 18:10:00 +08:00
|
|
|
c.SendDdCreateCollectionReq = func(ctx context.Context, req *internalpb.CreateCollectionRequest, channelNames []string) (map[string][]byte, error) {
|
2021-01-20 09:36:50 +08:00
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
2021-03-25 14:41:46 +08:00
|
|
|
Ctx: ctx,
|
2021-01-20 09:36:50 +08:00
|
|
|
BeginTimestamp: req.Base.Timestamp,
|
|
|
|
EndTimestamp: req.Base.Timestamp,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msg := &ms.CreateCollectionMsg{
|
2021-01-20 09:36:50 +08:00
|
|
|
BaseMsg: baseMsg,
|
|
|
|
CreateCollectionRequest: *req,
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, msg)
|
2021-11-25 10:07:15 +08:00
|
|
|
return c.chanTimeTick.broadcastMarkDmlChannels(channelNames, &msgPack)
|
2021-01-20 09:36:50 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdDropCollectionReq = func(ctx context.Context, req *internalpb.DropCollectionRequest, channelNames []string) error {
|
2021-01-20 09:36:50 +08:00
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
2021-03-25 14:41:46 +08:00
|
|
|
Ctx: ctx,
|
2021-01-20 09:36:50 +08:00
|
|
|
BeginTimestamp: req.Base.Timestamp,
|
|
|
|
EndTimestamp: req.Base.Timestamp,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msg := &ms.DropCollectionMsg{
|
2021-01-20 09:36:50 +08:00
|
|
|
BaseMsg: baseMsg,
|
|
|
|
DropCollectionRequest: *req,
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, msg)
|
2021-11-25 10:07:15 +08:00
|
|
|
return c.chanTimeTick.broadcastDmlChannels(channelNames, &msgPack)
|
2021-01-20 09:36:50 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdCreatePartitionReq = func(ctx context.Context, req *internalpb.CreatePartitionRequest, channelNames []string) error {
|
2021-01-20 09:36:50 +08:00
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
2021-03-25 14:41:46 +08:00
|
|
|
Ctx: ctx,
|
2021-01-20 09:36:50 +08:00
|
|
|
BeginTimestamp: req.Base.Timestamp,
|
|
|
|
EndTimestamp: req.Base.Timestamp,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msg := &ms.CreatePartitionMsg{
|
2021-01-20 09:36:50 +08:00
|
|
|
BaseMsg: baseMsg,
|
|
|
|
CreatePartitionRequest: *req,
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, msg)
|
2021-11-25 10:07:15 +08:00
|
|
|
return c.chanTimeTick.broadcastDmlChannels(channelNames, &msgPack)
|
2021-01-20 09:36:50 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 16:39:29 +08:00
|
|
|
c.SendDdDropPartitionReq = func(ctx context.Context, req *internalpb.DropPartitionRequest, channelNames []string) error {
|
2021-01-20 09:36:50 +08:00
|
|
|
msgPack := ms.MsgPack{}
|
|
|
|
baseMsg := ms.BaseMsg{
|
2021-03-25 14:41:46 +08:00
|
|
|
Ctx: ctx,
|
2021-01-20 09:36:50 +08:00
|
|
|
BeginTimestamp: req.Base.Timestamp,
|
|
|
|
EndTimestamp: req.Base.Timestamp,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msg := &ms.DropPartitionMsg{
|
2021-01-20 09:36:50 +08:00
|
|
|
BaseMsg: baseMsg,
|
|
|
|
DropPartitionRequest: *req,
|
|
|
|
}
|
2021-06-04 15:00:34 +08:00
|
|
|
msgPack.Msgs = append(msgPack.Msgs, msg)
|
2021-11-25 10:07:15 +08:00
|
|
|
return c.chanTimeTick.broadcastDmlChannels(channelNames, &msgPack)
|
2021-01-20 09:36:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// SetNewProxyClient set client to create proxy
|
2021-06-22 19:08:03 +08:00
|
|
|
func (c *Core) SetNewProxyClient(f func(sess *sessionutil.Session) (types.Proxy, error)) {
|
2021-05-26 20:14:30 +08:00
|
|
|
if c.NewProxyClient == nil {
|
|
|
|
c.NewProxyClient = f
|
|
|
|
} else {
|
2021-06-01 11:04:31 +08:00
|
|
|
log.Debug("NewProxyClient has already set")
|
2021-05-26 20:14:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 15:33:32 +08:00
|
|
|
// SetDataCoord set dataCoord.
|
2021-06-21 18:22:13 +08:00
|
|
|
func (c *Core) SetDataCoord(ctx context.Context, s types.DataCoord) error {
|
2021-06-25 16:48:10 +08:00
|
|
|
initCh := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
if err := s.Init(); err == nil {
|
|
|
|
if err := s.Start(); err == nil {
|
|
|
|
close(initCh)
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("RootCoord connected to DataCoord")
|
2021-06-25 16:48:10 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("Retrying RootCoord connection to DataCoord")
|
2021-06-25 16:48:10 +08:00
|
|
|
}
|
|
|
|
}()
|
2021-06-30 16:18:13 +08:00
|
|
|
c.CallGetBinlogFilePathsService = func(ctx context.Context, segID typeutil.UniqueID, fieldID typeutil.UniqueID) (retFiles []string, retErr error) {
|
2021-05-26 20:14:30 +08:00
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("get bin log file paths panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2022-02-09 10:19:56 +08:00
|
|
|
<-initCh //wait connect to DataCoord
|
2021-05-20 14:14:14 +08:00
|
|
|
ts, err := c.TSOAllocator(1)
|
2021-01-24 20:26:35 +08:00
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return nil, err
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
binlog, err := s.GetInsertBinlogPaths(ctx, &datapb.GetInsertBinlogPathsRequest{
|
2021-01-24 20:26:35 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-08 15:46:51 +08:00
|
|
|
MsgType: 0, //TODO, msg type
|
2021-01-24 20:26:35 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: ts,
|
2021-05-25 15:06:05 +08:00
|
|
|
SourceID: c.session.ServerID,
|
2021-01-24 20:26:35 +08:00
|
|
|
},
|
|
|
|
SegmentID: segID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return nil, err
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-03-10 22:06:22 +08:00
|
|
|
if binlog.Status.ErrorCode != commonpb.ErrorCode_Success {
|
2021-11-16 14:25:17 +08:00
|
|
|
return nil, fmt.Errorf("getInsertBinlogPaths from data service failed, error = %s", binlog.Status.Reason)
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-12-30 19:39:21 +08:00
|
|
|
binlogPaths := make([]string, 0)
|
2021-01-24 20:26:35 +08:00
|
|
|
for i := range binlog.FieldIDs {
|
|
|
|
if binlog.FieldIDs[i] == fieldID {
|
2021-12-30 19:39:21 +08:00
|
|
|
binlogPaths = append(binlogPaths, binlog.Paths[i].Values...)
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-30 19:39:21 +08:00
|
|
|
if len(binlogPaths) == 0 {
|
|
|
|
return nil, fmt.Errorf("binlog file does not exist, segment id = %d, field id = %d", segID, fieldID)
|
|
|
|
}
|
|
|
|
return binlogPaths, nil
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-03-08 15:46:51 +08:00
|
|
|
|
2021-06-30 16:18:13 +08:00
|
|
|
c.CallGetNumRowsService = func(ctx context.Context, segID typeutil.UniqueID, isFromFlushedChan bool) (retRows int64, retErr error) {
|
2021-05-26 20:14:30 +08:00
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("get num rows panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2021-06-25 16:48:10 +08:00
|
|
|
<-initCh
|
2021-05-20 14:14:14 +08:00
|
|
|
ts, err := c.TSOAllocator(1)
|
2021-03-08 15:46:51 +08:00
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return retRows, err
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
2021-03-12 14:22:09 +08:00
|
|
|
segInfo, err := s.GetSegmentInfo(ctx, &datapb.GetSegmentInfoRequest{
|
2021-03-08 15:46:51 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: 0, //TODO, msg type
|
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: ts,
|
2021-05-25 15:06:05 +08:00
|
|
|
SourceID: c.session.ServerID,
|
2021-03-08 15:46:51 +08:00
|
|
|
},
|
|
|
|
SegmentIDs: []typeutil.UniqueID{segID},
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return retRows, err
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
2021-03-10 22:06:22 +08:00
|
|
|
if segInfo.Status.ErrorCode != commonpb.ErrorCode_Success {
|
2021-11-16 14:25:17 +08:00
|
|
|
return retRows, fmt.Errorf("getSegmentInfo from data service failed, error = %s", segInfo.Status.Reason)
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
|
|
|
if len(segInfo.Infos) != 1 {
|
|
|
|
log.Debug("get segment info empty")
|
2021-09-07 11:16:37 +08:00
|
|
|
return retRows, nil
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
2021-03-13 17:05:36 +08:00
|
|
|
if !isFromFlushedChan && segInfo.Infos[0].State != commonpb.SegmentState_Flushed {
|
2021-03-08 15:46:51 +08:00
|
|
|
log.Debug("segment id not flushed", zap.Int64("segment id", segID))
|
2021-09-07 11:16:37 +08:00
|
|
|
return retRows, nil
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
return segInfo.Infos[0].NumOfRows, nil
|
2021-03-08 15:46:51 +08:00
|
|
|
}
|
2021-07-03 14:36:18 +08:00
|
|
|
|
|
|
|
c.CallGetFlushedSegmentsService = func(ctx context.Context, collID, partID typeutil.UniqueID) (retSegIDs []typeutil.UniqueID, retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("get flushed segments from data coord panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
<-initCh
|
|
|
|
req := &datapb.GetFlushedSegmentsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: 0, //TODO,msg type
|
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: 0,
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
|
|
|
CollectionID: collID,
|
|
|
|
PartitionID: partID,
|
|
|
|
}
|
|
|
|
rsp, err := s.GetFlushedSegments(ctx, req)
|
|
|
|
if err != nil {
|
2022-03-15 18:51:21 +08:00
|
|
|
return nil, err
|
2021-07-03 14:36:18 +08:00
|
|
|
}
|
|
|
|
if rsp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
2022-03-15 18:51:21 +08:00
|
|
|
return nil, fmt.Errorf("get flushed segments from data coord failed, reason = %s", rsp.Status.Reason)
|
2021-07-03 14:36:18 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
return rsp.Segments, nil
|
2021-07-03 14:36:18 +08:00
|
|
|
}
|
|
|
|
|
2022-04-06 15:33:32 +08:00
|
|
|
c.CallUpdateSegmentStateService = func(ctx context.Context, segID typeutil.UniqueID, ss commonpb.SegmentState) (retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("update segment state from data coord panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
<-initCh
|
|
|
|
req := &datapb.SetSegmentStateRequest{
|
|
|
|
SegmentId: segID,
|
|
|
|
NewState: ss,
|
|
|
|
}
|
|
|
|
resp, err := s.SetSegmentState(ctx, req)
|
|
|
|
if err != nil || resp.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
|
|
|
log.Error("failed to update segment state",
|
|
|
|
zap.Any("request", req), zap.Any("response", resp), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Info("successfully set segment state",
|
|
|
|
zap.Int64("segment ID", req.GetSegmentId()),
|
|
|
|
zap.String("new segment state", req.GetNewState().String()))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-11 00:54:45 +08:00
|
|
|
c.CallWatchChannels = func(ctx context.Context, collectionID int64, channelNames []string) (retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("watch channels panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
<-initCh
|
|
|
|
req := &datapb.WatchChannelsRequest{
|
|
|
|
CollectionID: collectionID,
|
|
|
|
ChannelNames: channelNames,
|
|
|
|
}
|
|
|
|
rsp, err := s.WatchChannels(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if rsp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return fmt.Errorf("data coord watch channels failed, reason = %s", rsp.Status.Reason)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-04-25 11:07:47 +08:00
|
|
|
|
2022-04-01 11:33:28 +08:00
|
|
|
c.CallImportService = func(ctx context.Context, req *datapb.ImportTaskRequest) *datapb.ImportTaskResponse {
|
2022-03-22 15:11:24 +08:00
|
|
|
resp := &datapb.ImportTaskResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
2022-03-21 15:47:23 +08:00
|
|
|
}
|
2022-03-22 15:11:24 +08:00
|
|
|
|
2022-03-21 15:47:23 +08:00
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
2022-03-22 15:11:24 +08:00
|
|
|
resp.Status.ErrorCode = commonpb.ErrorCode_UnexpectedError
|
|
|
|
resp.Status.Reason = "assign import task to data coord panic"
|
2022-03-21 15:47:23 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2022-03-22 15:11:24 +08:00
|
|
|
resp, _ = s.Import(ctx, req)
|
|
|
|
if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return resp
|
2022-03-21 15:47:23 +08:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:11:24 +08:00
|
|
|
return resp
|
2022-03-21 15:47:23 +08:00
|
|
|
}
|
|
|
|
|
2022-04-25 11:07:47 +08:00
|
|
|
c.CallFlushOnCollection = func(ctx context.Context, cID int64, segIDs []int64) error {
|
|
|
|
resp, err := s.Flush(ctx, &datapb.FlushRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Flush,
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
|
|
|
DbID: 0,
|
|
|
|
SegmentIDs: segIDs,
|
|
|
|
CollectionID: cID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return errors.New("failed to call flush to data coordinator: " + err.Error())
|
|
|
|
}
|
|
|
|
if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
return errors.New(resp.Status.Reason)
|
|
|
|
}
|
|
|
|
log.Info("flush on collection succeed", zap.Int64("collection ID", cID))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-24 20:26:35 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// SetIndexCoord set indexcoord
|
2021-06-21 17:28:03 +08:00
|
|
|
func (c *Core) SetIndexCoord(s types.IndexCoord) error {
|
2021-06-25 16:48:10 +08:00
|
|
|
initCh := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
if err := s.Init(); err == nil {
|
|
|
|
if err := s.Start(); err == nil {
|
|
|
|
close(initCh)
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("RootCoord connected to IndexCoord")
|
2021-06-25 16:48:10 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("Retrying RootCoord connection to IndexCoord")
|
2021-06-25 16:48:10 +08:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-12-09 14:19:40 +08:00
|
|
|
c.CallBuildIndexService = func(ctx context.Context, binlog []string, field *schemapb.FieldSchema, idxInfo *etcdpb.IndexInfo, numRows int64) (retID typeutil.UniqueID, retErr error) {
|
2021-05-26 20:14:30 +08:00
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("build index panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2021-06-25 16:48:10 +08:00
|
|
|
<-initCh
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := s.BuildIndex(ctx, &indexpb.BuildIndexRequest{
|
2021-01-24 20:26:35 +08:00
|
|
|
DataPaths: binlog,
|
2021-05-15 18:08:08 +08:00
|
|
|
TypeParams: field.TypeParams,
|
|
|
|
IndexParams: idxInfo.IndexParams,
|
|
|
|
IndexID: idxInfo.IndexID,
|
|
|
|
IndexName: idxInfo.IndexName,
|
2021-12-09 14:19:40 +08:00
|
|
|
NumRows: numRows,
|
|
|
|
FieldSchema: field,
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return retID, err
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-03-10 22:06:22 +08:00
|
|
|
if rsp.Status.ErrorCode != commonpb.ErrorCode_Success {
|
2021-11-16 14:25:17 +08:00
|
|
|
return retID, fmt.Errorf("buildIndex from index service failed, error = %s", rsp.Status.Reason)
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
return rsp.IndexBuildID, nil
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-02-20 15:38:44 +08:00
|
|
|
|
2021-05-26 20:14:30 +08:00
|
|
|
c.CallDropIndexService = func(ctx context.Context, indexID typeutil.UniqueID) (retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("drop index from index service panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2021-06-25 16:48:10 +08:00
|
|
|
<-initCh
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := s.DropIndex(ctx, &indexpb.DropIndexRequest{
|
2021-02-20 15:38:44 +08:00
|
|
|
IndexID: indexID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return err
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
2021-03-10 22:06:22 +08:00
|
|
|
if rsp.ErrorCode != commonpb.ErrorCode_Success {
|
2021-09-07 11:16:37 +08:00
|
|
|
return fmt.Errorf(rsp.Reason)
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
return nil
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
|
|
|
|
2022-03-28 16:41:28 +08:00
|
|
|
c.CallGetIndexStatesService = func(ctx context.Context, IndexBuildIDs []int64) (idxInfo []*indexpb.IndexInfo, retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("get index state from index service panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
<-initCh
|
|
|
|
res, err := s.GetIndexStates(ctx, &indexpb.GetIndexStatesRequest{
|
|
|
|
IndexBuildIDs: IndexBuildIDs,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Error("RootCoord failed to get index states from IndexCoord.", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug("got index states", zap.String("get index state result", res.String()))
|
2022-03-28 16:41:28 +08:00
|
|
|
if res.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
|
|
|
|
log.Error("Get index states failed.",
|
|
|
|
zap.String("error_code", res.GetStatus().GetErrorCode().String()),
|
|
|
|
zap.String("reason", res.GetStatus().GetReason()))
|
|
|
|
return nil, fmt.Errorf(res.GetStatus().GetErrorCode().String())
|
|
|
|
}
|
|
|
|
return res.GetStates(), nil
|
|
|
|
}
|
2021-01-24 20:26:35 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// SetQueryCoord set querycoord
|
2021-06-22 16:44:09 +08:00
|
|
|
func (c *Core) SetQueryCoord(s types.QueryCoord) error {
|
2021-06-25 16:48:10 +08:00
|
|
|
initCh := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
if err := s.Init(); err == nil {
|
|
|
|
if err := s.Start(); err == nil {
|
|
|
|
close(initCh)
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("RootCoord connected to QueryCoord")
|
2021-06-25 16:48:10 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("Retrying RootCoord connection to QueryCoord")
|
2021-06-25 16:48:10 +08:00
|
|
|
}
|
|
|
|
}()
|
2021-05-26 20:14:30 +08:00
|
|
|
c.CallReleaseCollectionService = func(ctx context.Context, ts typeutil.Timestamp, dbID typeutil.UniqueID, collectionID typeutil.UniqueID) (retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("release collection from query service panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2021-06-25 16:48:10 +08:00
|
|
|
<-initCh
|
2021-02-05 14:09:55 +08:00
|
|
|
req := &querypb.ReleaseCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_ReleaseCollection,
|
2021-02-05 14:09:55 +08:00
|
|
|
MsgID: 0, //TODO, msg ID
|
|
|
|
Timestamp: ts,
|
2021-05-25 15:06:05 +08:00
|
|
|
SourceID: c.session.ServerID,
|
2021-02-05 14:09:55 +08:00
|
|
|
},
|
|
|
|
DbID: dbID,
|
|
|
|
CollectionID: collectionID,
|
|
|
|
}
|
2021-02-26 17:44:24 +08:00
|
|
|
rsp, err := s.ReleaseCollection(ctx, req)
|
2021-02-05 14:09:55 +08:00
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return err
|
2021-02-05 14:09:55 +08:00
|
|
|
}
|
2021-03-10 22:06:22 +08:00
|
|
|
if rsp.ErrorCode != commonpb.ErrorCode_Success {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("releaseCollection from query service failed, error = %s", rsp.Reason)
|
2021-02-05 14:09:55 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
return nil
|
2021-02-05 14:09:55 +08:00
|
|
|
}
|
2021-06-22 16:08:08 +08:00
|
|
|
c.CallReleasePartitionService = func(ctx context.Context, ts typeutil.Timestamp, dbID, collectionID typeutil.UniqueID, partitionIDs []typeutil.UniqueID) (retErr error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
retErr = fmt.Errorf("release partition from query service panic, msg = %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2021-06-25 16:48:10 +08:00
|
|
|
<-initCh
|
2021-06-22 16:08:08 +08:00
|
|
|
req := &querypb.ReleasePartitionsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_ReleasePartitions,
|
|
|
|
MsgID: 0, //TODO, msg ID
|
|
|
|
Timestamp: ts,
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
|
|
|
DbID: dbID,
|
|
|
|
CollectionID: collectionID,
|
|
|
|
PartitionIDs: partitionIDs,
|
|
|
|
}
|
|
|
|
rsp, err := s.ReleasePartitions(ctx, req)
|
|
|
|
if err != nil {
|
2021-09-07 11:16:37 +08:00
|
|
|
return err
|
2021-06-22 16:08:08 +08:00
|
|
|
}
|
|
|
|
if rsp.ErrorCode != commonpb.ErrorCode_Success {
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("releasePartitions from query service failed, error = %s", rsp.Reason)
|
2021-06-22 16:08:08 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
return nil
|
2021-06-22 16:08:08 +08:00
|
|
|
}
|
2021-02-05 14:09:55 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-15 18:08:08 +08:00
|
|
|
// BuildIndex will check row num and call build index service
|
2021-06-30 16:18:13 +08:00
|
|
|
func (c *Core) BuildIndex(ctx context.Context, segID typeutil.UniqueID, field *schemapb.FieldSchema, idxInfo *etcdpb.IndexInfo, isFlush bool) (typeutil.UniqueID, error) {
|
2021-11-15 19:26:49 +08:00
|
|
|
log.Debug("start build index", zap.String("index name", idxInfo.IndexName),
|
|
|
|
zap.String("field name", field.Name), zap.Int64("segment id", segID))
|
2021-06-30 16:18:13 +08:00
|
|
|
sp, ctx := trace.StartSpanFromContext(ctx)
|
|
|
|
defer sp.Finish()
|
2021-05-15 18:08:08 +08:00
|
|
|
if c.MetaTable.IsSegmentIndexed(segID, field, idxInfo.IndexParams) {
|
2021-05-24 14:19:52 +08:00
|
|
|
return 0, nil
|
2021-05-15 18:08:08 +08:00
|
|
|
}
|
2021-06-30 16:18:13 +08:00
|
|
|
rows, err := c.CallGetNumRowsService(ctx, segID, isFlush)
|
2021-05-15 18:08:08 +08:00
|
|
|
if err != nil {
|
2021-05-24 14:19:52 +08:00
|
|
|
return 0, err
|
2021-05-15 18:08:08 +08:00
|
|
|
}
|
|
|
|
var bldID typeutil.UniqueID
|
2021-12-23 18:39:11 +08:00
|
|
|
if rows < Params.RootCoordCfg.MinSegmentSizeToEnableIndex {
|
2021-05-15 18:08:08 +08:00
|
|
|
log.Debug("num of rows is less than MinSegmentSizeToEnableIndex", zap.Int64("num rows", rows))
|
|
|
|
} else {
|
2021-06-30 16:18:13 +08:00
|
|
|
binlogs, err := c.CallGetBinlogFilePathsService(ctx, segID, field.FieldID)
|
2021-05-15 18:08:08 +08:00
|
|
|
if err != nil {
|
2021-05-24 14:19:52 +08:00
|
|
|
return 0, err
|
2021-05-15 18:08:08 +08:00
|
|
|
}
|
2021-12-09 14:19:40 +08:00
|
|
|
bldID, err = c.CallBuildIndexService(ctx, binlogs, field, idxInfo, rows)
|
2021-05-15 18:08:08 +08:00
|
|
|
if err != nil {
|
2021-05-24 14:19:52 +08:00
|
|
|
return 0, err
|
2021-05-15 18:08:08 +08:00
|
|
|
}
|
2021-11-15 19:26:49 +08:00
|
|
|
|
|
|
|
log.Debug("CallBuildIndex finished", zap.String("index name", idxInfo.IndexName),
|
|
|
|
zap.String("field name", field.Name), zap.Int64("segment id", segID), zap.Int64("num rows", rows))
|
2021-05-15 18:08:08 +08:00
|
|
|
}
|
2021-05-24 14:19:52 +08:00
|
|
|
return bldID, nil
|
2021-05-15 18:08:08 +08:00
|
|
|
}
|
|
|
|
|
2021-11-23 23:01:15 +08:00
|
|
|
// RemoveIndex will call drop index service
|
|
|
|
func (c *Core) RemoveIndex(ctx context.Context, collName string, indexName string) error {
|
|
|
|
_, indexInfos, err := c.MetaTable.GetIndexByName(collName, indexName)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("GetIndexByName failed,", zap.String("collection name", collName),
|
|
|
|
zap.String("index name", indexName), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, indexInfo := range indexInfos {
|
|
|
|
if err = c.CallDropIndexService(ctx, indexInfo.IndexID); err != nil {
|
|
|
|
log.Error("CallDropIndexService failed,", zap.String("collection name", collName), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExpireMetaCache will call invalidate collection meta cache
|
|
|
|
func (c *Core) ExpireMetaCache(ctx context.Context, collNames []string, ts typeutil.Timestamp) {
|
|
|
|
for _, collName := range collNames {
|
|
|
|
req := proxypb.InvalidateCollMetaCacheRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: 0, //TODO, msg type
|
|
|
|
MsgID: 0, //TODO, msg id
|
|
|
|
Timestamp: ts,
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
|
|
|
CollectionName: collName,
|
|
|
|
}
|
|
|
|
c.proxyClientManager.InvalidateCollectionMetaCache(ctx, &req)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-17 16:47:57 +08:00
|
|
|
// Register register rootcoord at etcd
|
2021-05-25 15:06:05 +08:00
|
|
|
func (c *Core) Register() error {
|
2021-12-15 11:47:10 +08:00
|
|
|
c.session.Register()
|
|
|
|
go c.session.LivenessCheck(c.ctx, func() {
|
|
|
|
log.Error("Root Coord disconnected from etcd, process will exit", zap.Int64("Server Id", c.session.ServerID))
|
|
|
|
if err := c.Stop(); err != nil {
|
|
|
|
log.Fatal("failed to stop server", zap.Error(err))
|
|
|
|
}
|
|
|
|
// manually send signal to starter goroutine
|
2021-12-29 14:35:21 +08:00
|
|
|
if c.session.TriggerKill {
|
2022-03-17 17:17:22 +08:00
|
|
|
if p, err := os.FindProcess(os.Getpid()); err == nil {
|
|
|
|
p.Signal(syscall.SIGINT)
|
|
|
|
}
|
2021-12-29 14:35:21 +08:00
|
|
|
}
|
2021-12-15 11:47:10 +08:00
|
|
|
})
|
2022-01-18 12:09:37 +08:00
|
|
|
|
|
|
|
c.UpdateStateCode(internalpb.StateCode_Healthy)
|
|
|
|
log.Debug("RootCoord start successfully ", zap.String("State Code", internalpb.StateCode_Healthy.String()))
|
2021-12-15 11:47:10 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-31 14:23:55 +08:00
|
|
|
// SetEtcdClient sets the etcdCli of Core
|
2021-12-29 14:35:21 +08:00
|
|
|
func (c *Core) SetEtcdClient(etcdClient *clientv3.Client) {
|
|
|
|
c.etcdCli = etcdClient
|
|
|
|
}
|
|
|
|
|
2021-12-15 11:47:10 +08:00
|
|
|
func (c *Core) initSession() error {
|
2022-02-07 10:09:45 +08:00
|
|
|
c.session = sessionutil.NewSession(c.ctx, Params.EtcdCfg.MetaRootPath, c.etcdCli)
|
2021-06-03 19:01:33 +08:00
|
|
|
if c.session == nil {
|
2021-10-13 10:50:41 +08:00
|
|
|
return fmt.Errorf("session is nil, the etcd client connection may have failed")
|
2021-06-03 19:01:33 +08:00
|
|
|
}
|
2021-12-29 14:35:21 +08:00
|
|
|
c.session.Init(typeutil.RootCoordRole, Params.RootCoordCfg.Address, true, true)
|
2022-02-07 10:09:45 +08:00
|
|
|
Params.SetLogger(c.session.ServerID)
|
2021-05-25 15:06:05 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// Init initialize routine
|
2021-01-24 20:26:35 +08:00
|
|
|
func (c *Core) Init() error {
|
2021-12-14 15:31:07 +08:00
|
|
|
var initError error
|
2021-09-15 22:05:49 +08:00
|
|
|
if c.kvBaseCreate == nil {
|
|
|
|
c.kvBaseCreate = func(root string) (kv.TxnKV, error) {
|
2021-12-29 14:35:21 +08:00
|
|
|
return etcdkv.NewEtcdKV(c.etcdCli, root), nil
|
2021-09-15 22:05:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-03-25 11:03:25 +08:00
|
|
|
if c.metaKVCreate == nil {
|
|
|
|
c.metaKVCreate = func(root string) (kv.MetaKv, error) {
|
|
|
|
return etcdkv.NewEtcdKV(c.etcdCli, root), nil
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 14:44:03 +08:00
|
|
|
c.initOnce.Do(func() {
|
2021-12-15 11:47:10 +08:00
|
|
|
if err := c.initSession(); err != nil {
|
|
|
|
initError = err
|
|
|
|
log.Error("RootCoord init session failed", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
2021-02-26 15:17:47 +08:00
|
|
|
connectEtcdFn := func() error {
|
2022-02-07 10:09:45 +08:00
|
|
|
if c.kvBase, initError = c.kvBaseCreate(Params.EtcdCfg.KvRootPath); initError != nil {
|
2022-03-25 11:03:25 +08:00
|
|
|
log.Error("RootCoord failed to new EtcdKV for kvBase", zap.Any("reason", initError))
|
|
|
|
return initError
|
|
|
|
}
|
|
|
|
if c.impTaskKv, initError = c.metaKVCreate(Params.EtcdCfg.KvRootPath); initError != nil {
|
|
|
|
log.Error("RootCoord failed to new EtcdKV for MetaKV", zap.Any("reason", initError))
|
2021-09-15 22:05:49 +08:00
|
|
|
return initError
|
|
|
|
}
|
|
|
|
var metaKV kv.TxnKV
|
2022-02-07 10:09:45 +08:00
|
|
|
metaKV, initError = c.kvBaseCreate(Params.EtcdCfg.MetaRootPath)
|
2021-05-18 14:18:02 +08:00
|
|
|
if initError != nil {
|
2021-11-19 12:11:12 +08:00
|
|
|
log.Error("RootCoord failed to new EtcdKV", zap.Any("reason", initError))
|
2021-05-18 14:18:02 +08:00
|
|
|
return initError
|
|
|
|
}
|
2021-09-15 22:05:49 +08:00
|
|
|
var ss *suffixSnapshot
|
2022-02-07 10:09:45 +08:00
|
|
|
if ss, initError = newSuffixSnapshot(metaKV, "_ts", Params.EtcdCfg.MetaRootPath, "snapshots"); initError != nil {
|
2021-11-19 12:11:12 +08:00
|
|
|
log.Error("RootCoord failed to new suffixSnapshot", zap.Error(initError))
|
2021-02-26 15:17:47 +08:00
|
|
|
return initError
|
|
|
|
}
|
2021-10-21 14:04:36 +08:00
|
|
|
if c.MetaTable, initError = NewMetaTable(metaKV, ss); initError != nil {
|
2021-11-19 12:11:12 +08:00
|
|
|
log.Error("RootCoord failed to new MetaTable", zap.Any("reason", initError))
|
2021-08-13 11:04:09 +08:00
|
|
|
return initError
|
|
|
|
}
|
|
|
|
|
2021-02-26 15:17:47 +08:00
|
|
|
return nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2022-02-07 10:09:45 +08:00
|
|
|
log.Debug("RootCoord, Connecting to Etcd", zap.String("kv root", Params.EtcdCfg.KvRootPath), zap.String("meta root", Params.EtcdCfg.MetaRootPath))
|
2021-06-23 09:24:10 +08:00
|
|
|
err := retry.Do(c.ctx, connectEtcdFn, retry.Attempts(300))
|
2021-02-26 15:17:47 +08:00
|
|
|
if err != nil {
|
2021-01-19 14:44:03 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-13 10:50:41 +08:00
|
|
|
log.Debug("RootCoord, Setting TSO and ID Allocator")
|
2022-02-07 10:09:45 +08:00
|
|
|
kv := tsoutil.NewTSOKVBase(c.etcdCli, Params.EtcdCfg.KvRootPath, "gid")
|
2021-08-13 11:04:09 +08:00
|
|
|
idAllocator := allocator.NewGlobalIDAllocator("idTimestamp", kv)
|
2021-04-08 17:31:39 +08:00
|
|
|
if initError = idAllocator.Initialize(); initError != nil {
|
2021-01-19 14:44:03 +08:00
|
|
|
return
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
c.IDAllocator = func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return idAllocator.Alloc(count)
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
c.IDAllocatorUpdate = func() error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return idAllocator.UpdateID()
|
|
|
|
}
|
|
|
|
|
2022-02-07 10:09:45 +08:00
|
|
|
kv = tsoutil.NewTSOKVBase(c.etcdCli, Params.EtcdCfg.KvRootPath, "tso")
|
2021-08-13 11:04:09 +08:00
|
|
|
tsoAllocator := tso.NewGlobalTSOAllocator("timestamp", kv)
|
2021-04-08 17:31:39 +08:00
|
|
|
if initError = tsoAllocator.Initialize(); initError != nil {
|
2021-01-19 14:44:03 +08:00
|
|
|
return
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
c.TSOAllocator = func(count uint32) (typeutil.Timestamp, error) {
|
2021-04-08 17:31:39 +08:00
|
|
|
return tsoAllocator.Alloc(count)
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
c.TSOAllocatorUpdate = func() error {
|
2021-04-08 17:31:39 +08:00
|
|
|
return tsoAllocator.UpdateTSO()
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
c.TSOGetLastSavedTime = func() time.Time {
|
|
|
|
return tsoAllocator.GetLastSavedTime()
|
|
|
|
}
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
c.factory.Init(&Params)
|
2021-06-04 15:00:34 +08:00
|
|
|
|
2021-11-02 15:50:30 +08:00
|
|
|
chanMap := c.MetaTable.ListCollectionPhysicalChannels()
|
2022-04-07 22:05:32 +08:00
|
|
|
c.chanTimeTick = newTimeTickSync(c.ctx, c.session.ServerID, c.factory, chanMap)
|
2022-01-18 14:47:36 +08:00
|
|
|
c.chanTimeTick.addSession(c.session)
|
2021-05-26 20:14:30 +08:00
|
|
|
c.proxyClientManager = newProxyClientManager(c)
|
|
|
|
|
2021-06-22 16:08:08 +08:00
|
|
|
log.Debug("RootCoord, set proxy manager")
|
2021-12-29 14:35:21 +08:00
|
|
|
c.proxyManager = newProxyManager(
|
2021-05-26 20:14:30 +08:00
|
|
|
c.ctx,
|
2021-12-29 14:35:21 +08:00
|
|
|
c.etcdCli,
|
2022-01-27 11:25:41 +08:00
|
|
|
c.chanTimeTick.initSessions,
|
2021-05-26 20:14:30 +08:00
|
|
|
c.proxyClientManager.GetProxyClients,
|
|
|
|
)
|
2022-01-27 11:25:41 +08:00
|
|
|
c.proxyManager.AddSessionFunc(c.chanTimeTick.addSession, c.proxyClientManager.AddProxyClient)
|
|
|
|
c.proxyManager.DelSessionFunc(c.chanTimeTick.delSession, c.proxyClientManager.DelProxyClient)
|
2021-05-21 16:08:12 +08:00
|
|
|
|
2021-09-03 17:15:26 +08:00
|
|
|
c.metricsCacheManager = metricsinfo.NewMetricsCacheManager()
|
|
|
|
|
2021-01-20 09:36:50 +08:00
|
|
|
initError = c.setMsgStreams()
|
2021-08-13 11:04:09 +08:00
|
|
|
if initError != nil {
|
|
|
|
return
|
|
|
|
}
|
2022-03-21 15:47:23 +08:00
|
|
|
|
|
|
|
c.importManager = newImportManager(
|
|
|
|
c.ctx,
|
2022-03-25 11:03:25 +08:00
|
|
|
c.impTaskKv,
|
2022-04-24 11:29:45 +08:00
|
|
|
c.IDAllocator,
|
2022-03-21 15:47:23 +08:00
|
|
|
c.CallImportService,
|
|
|
|
)
|
2022-04-24 11:29:45 +08:00
|
|
|
c.importManager.init(c.ctx)
|
2022-04-21 19:57:42 +08:00
|
|
|
|
2022-04-20 13:03:40 +08:00
|
|
|
// init data
|
2022-04-21 19:57:42 +08:00
|
|
|
initError = c.initData()
|
2022-04-20 13:03:40 +08:00
|
|
|
if initError != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-01-19 14:44:03 +08:00
|
|
|
})
|
2021-11-19 12:11:12 +08:00
|
|
|
if initError != nil {
|
2021-06-22 16:08:08 +08:00
|
|
|
log.Debug("RootCoord init error", zap.Error(initError))
|
2021-01-26 19:24:09 +08:00
|
|
|
}
|
2021-11-19 12:11:12 +08:00
|
|
|
log.Debug("RootCoord init done")
|
2021-01-19 14:44:03 +08:00
|
|
|
return initError
|
|
|
|
}
|
|
|
|
|
2022-04-21 19:57:42 +08:00
|
|
|
func (c *Core) initData() error {
|
|
|
|
credInfo, _ := c.MetaTable.getCredential(util.UserRoot)
|
|
|
|
if credInfo == nil {
|
|
|
|
log.Debug("RootCoord init user root")
|
|
|
|
encryptedRootPassword, _ := crypto.PasswordEncrypt(util.DefaultRootPassword)
|
|
|
|
err := c.MetaTable.AddCredential(&internalpb.CredentialInfo{Username: util.UserRoot, EncryptedPassword: encryptedRootPassword})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:16:37 +08:00
|
|
|
func (c *Core) reSendDdMsg(ctx context.Context, force bool) error {
|
|
|
|
if !force {
|
2021-10-21 14:04:36 +08:00
|
|
|
flag, err := c.MetaTable.txn.Load(DDMsgSendPrefix)
|
2022-01-27 11:25:41 +08:00
|
|
|
if err != nil {
|
|
|
|
// TODO, this is super ugly hack but our kv interface does not support loadWithExist
|
|
|
|
// leave it for later
|
|
|
|
if strings.Contains(err.Error(), "there is no value on key") {
|
|
|
|
log.Debug("skip reSendDdMsg with no dd-msg-send key")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
value, err := strconv.ParseBool(flag)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if value {
|
|
|
|
log.Debug("skip reSendDdMsg with dd-msg-send set to true")
|
2021-09-07 11:16:37 +08:00
|
|
|
return nil
|
|
|
|
}
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
|
2021-10-21 14:04:36 +08:00
|
|
|
ddOpStr, err := c.MetaTable.txn.Load(DDOperationPrefix)
|
2021-05-14 21:26:06 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Debug("DdOperation key does not exist")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var ddOp DdOperation
|
|
|
|
if err = json.Unmarshal([]byte(ddOpStr), &ddOp); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-15 08:59:08 +08:00
|
|
|
invalidateCache := false
|
2021-09-07 11:16:37 +08:00
|
|
|
var ts typeutil.Timestamp
|
2021-12-14 19:15:06 +08:00
|
|
|
var collName string
|
2021-09-07 11:16:37 +08:00
|
|
|
|
2021-05-14 21:26:06 +08:00
|
|
|
switch ddOp.Type {
|
2021-09-27 18:10:00 +08:00
|
|
|
// TODO remove create collection resend
|
|
|
|
// since create collection needs a start position to succeed
|
2021-05-14 21:26:06 +08:00
|
|
|
case CreateCollectionDDType:
|
2021-07-06 09:16:03 +08:00
|
|
|
var ddReq = internalpb.CreateCollectionRequest{}
|
2021-09-23 10:37:54 +08:00
|
|
|
if err = proto.Unmarshal(ddOp.Body, &ddReq); err != nil {
|
2021-05-14 21:26:06 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-12-15 08:59:08 +08:00
|
|
|
if _, err := c.MetaTable.GetCollectionByName(ddReq.CollectionName, 0); err != nil {
|
|
|
|
if _, err = c.SendDdCreateCollectionReq(ctx, &ddReq, ddReq.PhysicalChannelNames); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Debug("collection has been created, skip re-send CreateCollection",
|
|
|
|
zap.String("collection name", collName))
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
case DropCollectionDDType:
|
|
|
|
var ddReq = internalpb.DropCollectionRequest{}
|
2021-09-23 10:37:54 +08:00
|
|
|
if err = proto.Unmarshal(ddOp.Body, &ddReq); err != nil {
|
2021-05-14 21:26:06 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
ts = ddReq.Base.Timestamp
|
2021-12-14 19:15:06 +08:00
|
|
|
collName = ddReq.CollectionName
|
2021-12-15 08:59:08 +08:00
|
|
|
if collInfo, err := c.MetaTable.GetCollectionByName(ddReq.CollectionName, 0); err == nil {
|
|
|
|
if err = c.SendDdDropCollectionReq(ctx, &ddReq, collInfo.PhysicalChannelNames); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
invalidateCache = true
|
|
|
|
} else {
|
|
|
|
log.Debug("collection has been removed, skip re-send DropCollection",
|
|
|
|
zap.String("collection name", collName))
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
case CreatePartitionDDType:
|
|
|
|
var ddReq = internalpb.CreatePartitionRequest{}
|
2021-09-23 10:37:54 +08:00
|
|
|
if err = proto.Unmarshal(ddOp.Body, &ddReq); err != nil {
|
2021-05-14 21:26:06 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
ts = ddReq.Base.Timestamp
|
2021-12-14 19:15:06 +08:00
|
|
|
collName = ddReq.CollectionName
|
2021-06-11 16:39:29 +08:00
|
|
|
collInfo, err := c.MetaTable.GetCollectionByName(ddReq.CollectionName, 0)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-12-15 08:59:08 +08:00
|
|
|
if _, err = c.MetaTable.GetPartitionByName(collInfo.ID, ddReq.PartitionName, 0); err != nil {
|
|
|
|
if err = c.SendDdCreatePartitionReq(ctx, &ddReq, collInfo.PhysicalChannelNames); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
invalidateCache = true
|
|
|
|
} else {
|
|
|
|
log.Debug("partition has been created, skip re-send CreatePartition",
|
|
|
|
zap.String("collection name", collName), zap.String("partition name", ddReq.PartitionName))
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
case DropPartitionDDType:
|
|
|
|
var ddReq = internalpb.DropPartitionRequest{}
|
2021-09-23 10:37:54 +08:00
|
|
|
if err = proto.Unmarshal(ddOp.Body, &ddReq); err != nil {
|
2021-05-14 21:26:06 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
ts = ddReq.Base.Timestamp
|
2021-12-14 19:15:06 +08:00
|
|
|
collName = ddReq.CollectionName
|
2021-06-11 16:39:29 +08:00
|
|
|
collInfo, err := c.MetaTable.GetCollectionByName(ddReq.CollectionName, 0)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-12-15 08:59:08 +08:00
|
|
|
if _, err = c.MetaTable.GetPartitionByName(collInfo.ID, ddReq.PartitionName, 0); err == nil {
|
|
|
|
if err = c.SendDdDropPartitionReq(ctx, &ddReq, collInfo.PhysicalChannelNames); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
invalidateCache = true
|
|
|
|
} else {
|
|
|
|
log.Debug("partition has been removed, skip re-send DropPartition",
|
|
|
|
zap.String("collection name", collName), zap.String("partition name", ddReq.PartitionName))
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
default:
|
2021-11-16 14:25:17 +08:00
|
|
|
return fmt.Errorf("invalid DdOperation %s", ddOp.Type)
|
2021-09-07 11:16:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if invalidateCache {
|
2021-12-14 19:15:06 +08:00
|
|
|
c.ExpireMetaCache(ctx, []string{collName}, ts)
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update DDOperation in etcd
|
2022-01-27 11:25:41 +08:00
|
|
|
return c.MetaTable.txn.Save(DDMsgSendPrefix, strconv.FormatBool(true))
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
|
|
|
|
2022-04-03 11:37:29 +08:00
|
|
|
// Start starts RootCoord.
|
2021-01-19 14:44:03 +08:00
|
|
|
func (c *Core) Start() error {
|
|
|
|
if err := c.checkInit(); err != nil {
|
2021-06-17 16:47:57 +08:00
|
|
|
log.Debug("RootCoord Start checkInit failed", zap.Error(err))
|
2021-01-19 14:44:03 +08:00
|
|
|
return err
|
|
|
|
}
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2021-06-17 16:47:57 +08:00
|
|
|
log.Debug(typeutil.RootCoordRole, zap.Int64("node id", c.session.ServerID))
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
c.startOnce.Do(func() {
|
2021-06-22 19:08:03 +08:00
|
|
|
if err := c.proxyManager.WatchProxy(); err != nil {
|
2021-10-27 22:00:27 +08:00
|
|
|
log.Fatal("RootCoord Start WatchProxy failed", zap.Error(err))
|
|
|
|
// you can not just stuck here,
|
|
|
|
panic(err)
|
2021-05-26 20:14:30 +08:00
|
|
|
}
|
2021-09-07 11:16:37 +08:00
|
|
|
if err := c.reSendDdMsg(c.ctx, false); err != nil {
|
2021-10-27 22:00:27 +08:00
|
|
|
log.Fatal("RootCoord Start reSendDdMsg failed", zap.Error(err))
|
|
|
|
panic(err)
|
2021-05-14 21:26:06 +08:00
|
|
|
}
|
2022-04-03 11:37:29 +08:00
|
|
|
c.wg.Add(5)
|
2021-01-19 14:44:03 +08:00
|
|
|
go c.startTimeTickLoop()
|
2021-01-27 16:38:18 +08:00
|
|
|
go c.tsLoop()
|
2021-11-25 10:07:15 +08:00
|
|
|
go c.chanTimeTick.startWatch(&c.wg)
|
2021-07-03 17:54:25 +08:00
|
|
|
go c.checkFlushedSegmentsLoop()
|
2022-04-03 11:37:29 +08:00
|
|
|
go c.importManager.expireOldTasksLoop(&c.wg)
|
2021-12-23 18:39:11 +08:00
|
|
|
Params.RootCoordCfg.CreatedTime = time.Now()
|
|
|
|
Params.RootCoordCfg.UpdatedTime = time.Now()
|
2021-01-19 14:44:03 +08:00
|
|
|
})
|
2021-09-17 21:52:00 +08:00
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-03 11:37:29 +08:00
|
|
|
// Stop stops rootCoord.
|
2021-01-19 14:44:03 +08:00
|
|
|
func (c *Core) Stop() error {
|
2021-12-07 18:39:03 +08:00
|
|
|
c.UpdateStateCode(internalpb.StateCode_Abnormal)
|
|
|
|
|
2021-01-19 14:44:03 +08:00
|
|
|
c.cancel()
|
2021-09-17 12:37:50 +08:00
|
|
|
c.wg.Wait()
|
2021-11-16 22:31:14 +08:00
|
|
|
// wait at most one second to revoke
|
|
|
|
c.session.Revoke(time.Second)
|
2021-01-19 14:44:03 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// GetComponentStates get states of components
|
2021-03-12 14:22:09 +08:00
|
|
|
func (c *Core) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
|
|
|
code := c.stateCode.Load().(internalpb.StateCode)
|
|
|
|
log.Debug("GetComponentStates", zap.String("State Code", internalpb.StateCode_name[int32(code)]))
|
2021-01-26 19:24:09 +08:00
|
|
|
|
2021-11-19 13:57:12 +08:00
|
|
|
nodeID := common.NotRegisteredID
|
|
|
|
if c.session != nil && c.session.Registered() {
|
|
|
|
nodeID = c.session.ServerID
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
return &internalpb.ComponentStates{
|
|
|
|
State: &internalpb.ComponentInfo{
|
2021-11-19 13:57:12 +08:00
|
|
|
// NodeID: c.session.ServerID, // will race with Core.Register()
|
|
|
|
NodeID: nodeID,
|
2021-06-17 16:47:57 +08:00
|
|
|
Role: typeutil.RootCoordRole,
|
2021-01-20 11:02:29 +08:00
|
|
|
StateCode: code,
|
|
|
|
ExtraInfo: nil,
|
2021-01-19 14:44:03 +08:00
|
|
|
},
|
2021-01-26 17:47:38 +08:00
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-01-26 17:47:38 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
2021-03-12 14:22:09 +08:00
|
|
|
SubcomponentStates: []*internalpb.ComponentInfo{
|
2021-01-26 17:47:38 +08:00
|
|
|
{
|
2021-11-19 13:57:12 +08:00
|
|
|
NodeID: nodeID,
|
2021-06-17 16:47:57 +08:00
|
|
|
Role: typeutil.RootCoordRole,
|
2021-01-26 17:47:38 +08:00
|
|
|
StateCode: code,
|
|
|
|
ExtraInfo: nil,
|
|
|
|
},
|
|
|
|
},
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// GetTimeTickChannel get timetick channel name
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-26 17:44:24 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
2022-03-04 11:17:56 +08:00
|
|
|
Value: Params.CommonCfg.RootCoordTimeTick,
|
2021-02-26 17:44:24 +08:00
|
|
|
}, nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// GetStatisticsChannel get statistics channel name
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
return &milvuspb.StringResponse{
|
|
|
|
Status: &commonpb.Status{
|
2021-03-10 22:06:22 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
2021-02-26 17:44:24 +08:00
|
|
|
Reason: "",
|
|
|
|
},
|
2022-03-04 11:17:56 +08:00
|
|
|
Value: Params.CommonCfg.RootCoordStatistics,
|
2021-02-26 17:44:24 +08:00
|
|
|
}, nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// CreateCollection create collection
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) CreateCollection(ctx context.Context, in *milvuspb.CreateCollectionRequest) (*commonpb.Status, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordCreateCollectionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("CreateCollection")
|
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreateCollection", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &CreateCollectionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("CreateCollection failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "CreateCollection failed: "+err.Error()), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreateCollection success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordCreateCollectionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("CreateCollection").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordNumOfCollections.Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DropCollection drop collection
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) DropCollection(ctx context.Context, in *milvuspb.DropCollectionRequest) (*commonpb.Status, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDropCollectionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DropCollection")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropCollection", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &DropCollectionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DropCollection failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "DropCollection failed: "+err.Error()), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropCollection success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDropCollectionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("DropCollection").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordNumOfCollections.Dec()
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// HasCollection check collection existence
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) HasCollection(ctx context.Context, in *milvuspb.HasCollectionRequest) (*milvuspb.BoolResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordHasCollectionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-01-25 18:33:10 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
|
|
|
Value: false,
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("HasCollection")
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("HasCollection", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &HasCollectionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
HasCollection: false,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("HasCollection failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-01-19 14:44:03 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2021-11-22 16:01:14 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "HasCollection failed: "+err.Error()),
|
2021-11-19 12:11:12 +08:00
|
|
|
Value: false,
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("HasCollection success", zap.String("role", typeutil.RootCoordRole),
|
2022-04-27 10:01:47 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID), zap.Bool("hasCollection", t.HasCollection))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordHasCollectionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("HasCollection").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-19 14:44:03 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: succStatus(),
|
|
|
|
Value: t.HasCollection,
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DescribeCollection return collection info
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) DescribeCollection(ctx context.Context, in *milvuspb.DescribeCollectionRequest) (*milvuspb.DescribeCollectionResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDescribeCollectionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-01-25 18:33:10 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode"+internalpb.StateCode_name[int32(code)]),
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DescribeCollection")
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DescribeCollection", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &DescribeCollectionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
Rsp: &milvuspb.DescribeCollectionResponse{},
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DescribeCollection failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-01-19 14:44:03 +08:00
|
|
|
return &milvuspb.DescribeCollectionResponse{
|
2021-11-22 16:01:14 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "DescribeCollection failed: "+err.Error()),
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DescribeCollection success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDescribeCollectionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("DescribeCollection").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
t.Rsp.Status = succStatus()
|
2021-01-19 14:44:03 +08:00
|
|
|
return t.Rsp, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// ShowCollections list all collection names
|
2021-03-12 14:22:09 +08:00
|
|
|
func (c *Core) ShowCollections(ctx context.Context, in *milvuspb.ShowCollectionsRequest) (*milvuspb.ShowCollectionsResponse, error) {
|
2022-04-26 17:29:45 +08:00
|
|
|
metrics.RootCoordShowCollectionsCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowCollectionsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("ShowCollections")
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowCollections", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("dbname", in.DbName), zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &ShowCollectionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
2021-11-19 12:11:12 +08:00
|
|
|
Rsp: &milvuspb.ShowCollectionsResponse{},
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("ShowCollections failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("dbname", in.DbName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowCollectionsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowCollections failed: "+err.Error()),
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowCollections success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("dbname", in.DbName), zap.Int("num of collections", len(t.Rsp.CollectionNames)),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-04-26 17:29:45 +08:00
|
|
|
metrics.RootCoordShowCollectionsCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
t.Rsp.Status = succStatus()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("ShowCollections").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-19 14:44:03 +08:00
|
|
|
return t.Rsp, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// CreatePartition create partition
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) CreatePartition(ctx context.Context, in *milvuspb.CreatePartitionRequest) (*commonpb.Status, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordCreatePartitionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("CreatePartition")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreatePartition", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &CreatePartitionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("CreatePartition failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "CreatePartition failed: "+err.Error()), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreatePartition success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordCreatePartitionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("CreatePartition").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-04-26 17:29:45 +08:00
|
|
|
metrics.RootCoordNumOfPartitions.WithLabelValues().Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DropPartition drop partition
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) DropPartition(ctx context.Context, in *milvuspb.DropPartitionRequest) (*commonpb.Status, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDropPartitionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DropPartition")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropPartition", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &DropPartitionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DropPartition failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "DropPartition failed: "+err.Error()), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropPartition success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDropPartitionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("DropPartition").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2022-04-26 17:29:45 +08:00
|
|
|
metrics.RootCoordNumOfPartitions.WithLabelValues().Dec()
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// HasPartition check partition existence
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) HasPartition(ctx context.Context, in *milvuspb.HasPartitionRequest) (*milvuspb.BoolResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordHasPartitionCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-01-25 18:33:10 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
|
|
|
Value: false,
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("HasPartition")
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("HasPartition", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &HasPartitionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
HasPartition: false,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("HasPartition failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-01-19 14:44:03 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "HasPartition failed: "+err.Error()),
|
|
|
|
Value: false,
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("HasPartition success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("partition name", in.PartitionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordHasPartitionCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("HasPartition").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-19 14:44:03 +08:00
|
|
|
return &milvuspb.BoolResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: succStatus(),
|
|
|
|
Value: t.HasPartition,
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// ShowPartitions list all partition names
|
2021-03-12 14:22:09 +08:00
|
|
|
func (c *Core) ShowPartitions(ctx context.Context, in *milvuspb.ShowPartitionsRequest) (*milvuspb.ShowPartitionsResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordShowPartitionsCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("ShowPartitions")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowPartitions", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID))
|
2021-01-19 14:44:03 +08:00
|
|
|
t := &ShowPartitionReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-19 14:44:03 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
2021-11-19 12:11:12 +08:00
|
|
|
Rsp: &milvuspb.ShowPartitionsResponse{},
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("ShowPartitions failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowPartitionsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowPartitions failed: "+err.Error()),
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowPartitions success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.Int("num of partitions", len(t.Rsp.PartitionNames)),
|
|
|
|
zap.Int64("msgID", t.Req.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordShowPartitionsCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
t.Rsp.Status = succStatus()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("ShowPartitions").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-19 14:44:03 +08:00
|
|
|
return t.Rsp, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// CreateIndex create index
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) CreateIndex(ctx context.Context, in *milvuspb.CreateIndexRequest) (*commonpb.Status, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordCreateIndexCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-01-25 18:33:10 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("CreateIndex")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreateIndex", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-21 10:01:29 +08:00
|
|
|
t := &CreateIndexReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-21 10:01:29 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-21 10:01:29 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("CreateIndex failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "CreateIndex failed: "+err.Error()), nil
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreateIndex success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordCreateIndexCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("CreateIndex").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DescribeIndex return index info
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) DescribeIndex(ctx context.Context, in *milvuspb.DescribeIndexRequest) (*milvuspb.DescribeIndexResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDescribeIndexCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-01-25 18:33:10 +08:00
|
|
|
return &milvuspb.DescribeIndexResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DescribeIndex")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DescribeIndex", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-21 10:01:29 +08:00
|
|
|
t := &DescribeIndexReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-21 10:01:29 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
2021-11-19 12:11:12 +08:00
|
|
|
Rsp: &milvuspb.DescribeIndexResponse{},
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-21 10:01:29 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DescribeIndex failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-01-21 10:01:29 +08:00
|
|
|
return &milvuspb.DescribeIndexResponse{
|
2021-11-22 16:01:14 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "DescribeIndex failed: "+err.Error()),
|
2021-01-21 10:01:29 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-02-24 16:25:40 +08:00
|
|
|
idxNames := make([]string, 0, len(t.Rsp.IndexDescriptions))
|
|
|
|
for _, i := range t.Rsp.IndexDescriptions {
|
|
|
|
idxNames = append(idxNames, i.IndexName)
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DescribeIndex success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.Strings("index names", idxNames), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDescribeIndexCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2021-03-05 20:41:34 +08:00
|
|
|
if len(t.Rsp.IndexDescriptions) == 0 {
|
2021-11-22 16:01:14 +08:00
|
|
|
t.Rsp.Status = failStatus(commonpb.ErrorCode_IndexNotExist, "index not exist")
|
2021-03-05 20:41:34 +08:00
|
|
|
} else {
|
2021-11-19 12:11:12 +08:00
|
|
|
t.Rsp.Status = succStatus()
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("DescribeIndex").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-01-21 10:01:29 +08:00
|
|
|
return t.Rsp, nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DropIndex drop index
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) DropIndex(ctx context.Context, in *milvuspb.DropIndexRequest) (*commonpb.Status, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDropIndexCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DropIndex")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropIndex", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.String("index name", in.IndexName), zap.Int64("msgID", in.Base.MsgID))
|
2021-02-20 15:38:44 +08:00
|
|
|
t := &DropIndexReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-02-20 15:38:44 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-02-20 15:38:44 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DropIndex failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.String("index name", in.IndexName), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "DropIndex failed: "+err.Error()), nil
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropIndex success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection name", in.CollectionName), zap.String("field name", in.FieldName),
|
|
|
|
zap.String("index name", in.IndexName), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDropIndexCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("DropIndex").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-02-20 15:38:44 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DescribeSegment return segment info
|
2021-02-26 17:44:24 +08:00
|
|
|
func (c *Core) DescribeSegment(ctx context.Context, in *milvuspb.DescribeSegmentRequest) (*milvuspb.DescribeSegmentResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDescribeSegmentCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-01-25 18:33:10 +08:00
|
|
|
return &milvuspb.DescribeSegmentResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DescribeSegment")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DescribeSegment", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.CollectionID), zap.Int64("segment id", in.SegmentID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-21 10:01:29 +08:00
|
|
|
t := &DescribeSegmentReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-21 10:01:29 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
2021-11-19 12:11:12 +08:00
|
|
|
Rsp: &milvuspb.DescribeSegmentResponse{},
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-21 10:01:29 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DescribeSegment failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.CollectionID), zap.Int64("segment id", in.SegmentID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-01-21 10:01:29 +08:00
|
|
|
return &milvuspb.DescribeSegmentResponse{
|
2021-11-22 16:01:14 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "DescribeSegment failed: "+err.Error()),
|
2021-01-21 10:01:29 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DescribeSegment success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.CollectionID), zap.Int64("segment id", in.SegmentID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordDescribeSegmentCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("DescribeSegment").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
t.Rsp.Status = succStatus()
|
2021-01-21 10:01:29 +08:00
|
|
|
return t.Rsp, nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2022-03-30 21:11:28 +08:00
|
|
|
func (c *Core) DescribeSegments(ctx context.Context, in *rootcoordpb.DescribeSegmentsRequest) (*rootcoordpb.DescribeSegmentsResponse, error) {
|
|
|
|
metrics.RootCoordDescribeSegmentsCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
|
|
|
|
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
log.Error("failed to describe segments, rootcoord not healthy",
|
|
|
|
zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.Int64("msgID", in.GetBase().GetMsgID()),
|
|
|
|
zap.Int64("collection", in.GetCollectionID()),
|
|
|
|
zap.Int64s("segments", in.GetSegmentIDs()))
|
|
|
|
|
|
|
|
return &rootcoordpb.DescribeSegmentsResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
tr := timerecord.NewTimeRecorder("DescribeSegments")
|
|
|
|
|
|
|
|
log.Debug("received request to describe segments",
|
|
|
|
zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.Int64("msgID", in.GetBase().GetMsgID()),
|
|
|
|
zap.Int64("collection", in.GetCollectionID()),
|
|
|
|
zap.Int64s("segments", in.GetSegmentIDs()))
|
|
|
|
|
|
|
|
t := &DescribeSegmentsReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
|
|
|
ctx: ctx,
|
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
Rsp: &rootcoordpb.DescribeSegmentsResponse{},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := executeTask(t); err != nil {
|
|
|
|
log.Error("failed to describe segments",
|
|
|
|
zap.Error(err),
|
|
|
|
zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.Int64("msgID", in.GetBase().GetMsgID()),
|
|
|
|
zap.Int64("collection", in.GetCollectionID()),
|
|
|
|
zap.Int64s("segments", in.GetSegmentIDs()))
|
|
|
|
|
|
|
|
return &rootcoordpb.DescribeSegmentsResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "DescribeSegments failed: "+err.Error()),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug("succeed to describe segments",
|
|
|
|
zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.Int64("msgID", in.GetBase().GetMsgID()),
|
|
|
|
zap.Int64("collection", in.GetCollectionID()),
|
|
|
|
zap.Int64s("segments", in.GetSegmentIDs()))
|
|
|
|
|
|
|
|
metrics.RootCoordDescribeSegmentsCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("DescribeSegments").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
|
|
|
|
t.Rsp.Status = succStatus()
|
|
|
|
return t.Rsp, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// ShowSegments list all segments
|
2021-03-12 14:22:09 +08:00
|
|
|
func (c *Core) ShowSegments(ctx context.Context, in *milvuspb.ShowSegmentsRequest) (*milvuspb.ShowSegmentsResponse, error) {
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordShowSegmentsCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowSegmentsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-01-25 18:33:10 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("ShowSegments")
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowSegments", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.CollectionID), zap.Int64("partition id", in.PartitionID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-01-21 10:01:29 +08:00
|
|
|
t := &ShowSegmentReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
2021-03-13 14:42:53 +08:00
|
|
|
ctx: ctx,
|
2021-01-21 10:01:29 +08:00
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
2021-11-19 12:11:12 +08:00
|
|
|
Rsp: &milvuspb.ShowSegmentsResponse{},
|
2021-01-21 10:01:29 +08:00
|
|
|
}
|
2021-06-26 09:22:11 +08:00
|
|
|
err := executeTask(t)
|
2021-01-21 10:01:29 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowSegments failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.CollectionID), zap.Int64("partition id", in.PartitionID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-03-12 14:22:09 +08:00
|
|
|
return &milvuspb.ShowSegmentsResponse{
|
2021-11-22 16:01:14 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ShowSegments failed: "+err.Error()),
|
2021-01-21 10:01:29 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("ShowSegments success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.CollectionID), zap.Int64("partition id", in.PartitionID),
|
|
|
|
zap.Int64s("segments ids", t.Rsp.SegmentIDs),
|
2021-11-19 12:11:12 +08:00
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
|
|
|
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordShowSegmentsCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLReadTypeLatency.WithLabelValues("ShowSegments").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
t.Rsp.Status = succStatus()
|
2021-01-21 10:01:29 +08:00
|
|
|
return t.Rsp, nil
|
2021-01-19 14:44:03 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// AllocTimestamp alloc timestamp
|
2021-06-22 16:14:09 +08:00
|
|
|
func (c *Core) AllocTimestamp(ctx context.Context, in *rootcoordpb.AllocTimestampRequest) (*rootcoordpb.AllocTimestampResponse, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-06-22 16:14:09 +08:00
|
|
|
return &rootcoordpb.AllocTimestampResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-05-26 20:14:30 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
ts, err := c.TSOAllocator(in.Count)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("AllocTimestamp failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-06-22 16:14:09 +08:00
|
|
|
return &rootcoordpb.AllocTimestampResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "AllocTimestamp failed: "+err.Error()),
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-07-14 17:11:54 +08:00
|
|
|
|
|
|
|
//return first available time stamp
|
|
|
|
ts = ts - uint64(in.Count) + 1
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordTimestampAllocCounter.Set(float64(ts))
|
2021-06-22 16:14:09 +08:00
|
|
|
return &rootcoordpb.AllocTimestampResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: succStatus(),
|
2021-01-19 14:44:03 +08:00
|
|
|
Timestamp: ts,
|
|
|
|
Count: in.Count,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// AllocID alloc ids
|
2021-06-22 16:14:09 +08:00
|
|
|
func (c *Core) AllocID(ctx context.Context, in *rootcoordpb.AllocIDRequest) (*rootcoordpb.AllocIDResponse, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-06-22 16:14:09 +08:00
|
|
|
return &rootcoordpb.AllocIDResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-05-26 20:14:30 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-05-20 14:14:14 +08:00
|
|
|
start, _, err := c.IDAllocator(in.Count)
|
2021-01-19 14:44:03 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("AllocID failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-06-22 16:14:09 +08:00
|
|
|
return &rootcoordpb.AllocIDResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "AllocID failed: "+err.Error()),
|
|
|
|
Count: in.Count,
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
metrics.RootCoordIDAllocCounter.Add(float64(in.Count))
|
2021-06-22 16:14:09 +08:00
|
|
|
return &rootcoordpb.AllocIDResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: succStatus(),
|
|
|
|
ID: start,
|
|
|
|
Count: in.Count,
|
2021-01-19 14:44:03 +08:00
|
|
|
}, nil
|
|
|
|
}
|
2021-05-21 16:08:12 +08:00
|
|
|
|
|
|
|
// UpdateChannelTimeTick used to handle ChannelTimeTickMsg
|
|
|
|
func (c *Core) UpdateChannelTimeTick(ctx context.Context, in *internalpb.ChannelTimeTickMsg) (*commonpb.Status, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2022-01-15 18:53:34 +08:00
|
|
|
log.Warn("failed to updateTimeTick because rootcoord is not healthy", zap.Any("state", code))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-05-21 16:08:12 +08:00
|
|
|
}
|
|
|
|
if in.Base.MsgType != commonpb.MsgType_TimeTick {
|
2022-01-15 18:53:34 +08:00
|
|
|
log.Warn("failed to updateTimeTick because base messasge is not timetick, state", zap.Any("base message type", in.Base.MsgType))
|
2021-11-19 12:11:12 +08:00
|
|
|
msgTypeName := commonpb.MsgType_name[int32(in.Base.GetMsgType())]
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "invalid message type "+msgTypeName), nil
|
2021-05-21 16:08:12 +08:00
|
|
|
}
|
2021-11-25 10:07:15 +08:00
|
|
|
err := c.chanTimeTick.updateTimeTick(in, "gRPC")
|
2021-05-21 16:08:12 +08:00
|
|
|
if err != nil {
|
2022-01-15 18:53:34 +08:00
|
|
|
log.Warn("failed to updateTimeTick", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "UpdateTimeTick failed: "+err.Error()), nil
|
2021-05-21 16:08:12 +08:00
|
|
|
}
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-05-21 16:08:12 +08:00
|
|
|
}
|
2021-06-17 17:45:56 +08:00
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// ReleaseDQLMessageStream release DQL msgstream
|
2021-06-17 17:45:56 +08:00
|
|
|
func (c *Core) ReleaseDQLMessageStream(ctx context.Context, in *proxypb.ReleaseDQLMessageStreamRequest) (*commonpb.Status, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-06-17 17:45:56 +08:00
|
|
|
}
|
|
|
|
return c.proxyClientManager.ReleaseDQLMessageStream(ctx, in)
|
|
|
|
}
|
2021-07-01 14:58:17 +08:00
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// SegmentFlushCompleted check whether segment flush has completed
|
2021-07-02 11:16:20 +08:00
|
|
|
func (c *Core) SegmentFlushCompleted(ctx context.Context, in *datapb.SegmentFlushCompletedMsg) (*commonpb.Status, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
|
|
|
if in.Base.MsgType != commonpb.MsgType_SegmentFlushDone {
|
2021-11-22 16:01:14 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "invalid msg type "+commonpb.MsgType_name[int32(in.Base.MsgType)]), nil
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
2021-07-02 11:16:20 +08:00
|
|
|
segID := in.Segment.GetID()
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("SegmentFlushCompleted", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.Segment.CollectionID), zap.Int64("partition id", in.Segment.PartitionID),
|
|
|
|
zap.Int64("segment id", segID), zap.Int64("msgID", in.Base.MsgID))
|
2021-07-01 14:58:17 +08:00
|
|
|
|
2021-07-03 14:36:18 +08:00
|
|
|
coll, err := c.MetaTable.GetCollectionByID(in.Segment.CollectionID, 0)
|
2021-07-01 14:58:17 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("GetCollectionByID failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "GetCollectionByID failed: "+err.Error()), nil
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(coll.FieldIndexes) == 0 {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("no index params on collection", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection_name", coll.Schema.Name), zap.Int64("msgID", in.Base.MsgID))
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range coll.FieldIndexes {
|
|
|
|
fieldSch, err := GetFieldSchemaByID(coll, f.FiledID)
|
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Warn("field schema not found", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection_name", coll.Schema.Name), zap.Int64("field id", f.FiledID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-07-01 14:58:17 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
idxInfo, err := c.MetaTable.GetIndexByID(f.IndexID)
|
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Warn("index not found", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection_name", coll.Schema.Name), zap.Int64("field id", f.FiledID),
|
|
|
|
zap.Int64("index id", f.IndexID), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-07-01 14:58:17 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
info := etcdpb.SegmentIndexInfo{
|
2021-07-05 10:08:02 +08:00
|
|
|
CollectionID: in.Segment.CollectionID,
|
|
|
|
PartitionID: in.Segment.PartitionID,
|
|
|
|
SegmentID: segID,
|
|
|
|
FieldID: fieldSch.FieldID,
|
|
|
|
IndexID: idxInfo.IndexID,
|
|
|
|
EnableIndex: false,
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
|
|
|
info.BuildID, err = c.BuildIndex(ctx, segID, fieldSch, idxInfo, true)
|
|
|
|
if err == nil && info.BuildID != 0 {
|
|
|
|
info.EnableIndex = true
|
|
|
|
} else {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("BuildIndex failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection_name", coll.Schema.Name), zap.Int64("field id", f.FiledID),
|
|
|
|
zap.Int64("index id", f.IndexID), zap.Int64("build id", info.BuildID),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-07-03 14:36:18 +08:00
|
|
|
continue
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
2021-10-21 14:04:36 +08:00
|
|
|
err = c.MetaTable.AddIndex(&info)
|
2021-07-01 14:58:17 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("AddIndex failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("collection_name", coll.Schema.Name), zap.Int64("field id", f.FiledID),
|
|
|
|
zap.Int64("index id", f.IndexID), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
continue
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("SegmentFlushCompleted success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("collection id", in.Segment.CollectionID), zap.Int64("partition id", in.Segment.PartitionID),
|
|
|
|
zap.Int64("segment id", segID), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-07-01 14:58:17 +08:00
|
|
|
}
|
2021-08-31 11:45:59 +08:00
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// GetMetrics get metrics
|
2021-11-22 16:01:14 +08:00
|
|
|
func (c *Core) GetMetrics(ctx context.Context, in *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
2021-08-31 11:45:59 +08:00
|
|
|
return &milvuspb.GetMetricsResponse{
|
2021-11-22 16:01:14 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
2021-08-31 11:45:59 +08:00
|
|
|
Response: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-11-22 16:01:14 +08:00
|
|
|
metricType, err := metricsinfo.ParseMetricType(in.Request)
|
2021-08-31 11:45:59 +08:00
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("ParseMetricType failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("node_id", c.session.ServerID), zap.String("req", in.Request), zap.Error(err))
|
2021-08-31 11:45:59 +08:00
|
|
|
return &milvuspb.GetMetricsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "ParseMetricType failed: "+err.Error()),
|
2021-08-31 11:45:59 +08:00
|
|
|
Response: "",
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("GetMetrics success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("metric_type", metricType), zap.Int64("msgID", in.Base.MsgID))
|
2021-08-31 11:45:59 +08:00
|
|
|
|
|
|
|
if metricType == metricsinfo.SystemInfoMetrics {
|
2021-09-03 17:15:26 +08:00
|
|
|
ret, err := c.metricsCacheManager.GetSystemInfoMetrics()
|
|
|
|
if err == nil && ret != nil {
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Warn("GetSystemInfoMetrics from cache failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-08-31 11:45:59 +08:00
|
|
|
|
2021-11-22 16:01:14 +08:00
|
|
|
systemInfoMetrics, err := c.getSystemInfoMetrics(ctx, in)
|
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("GetSystemInfoMetrics failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("metric_type", metricType), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-08-31 11:45:59 +08:00
|
|
|
|
2021-09-03 17:15:26 +08:00
|
|
|
c.metricsCacheManager.UpdateSystemInfoMetrics(systemInfoMetrics)
|
2021-08-31 11:45:59 +08:00
|
|
|
return systemInfoMetrics, err
|
|
|
|
}
|
|
|
|
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("GetMetrics failed, metric type not implemented", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("metric_type", metricType), zap.Int64("msgID", in.Base.MsgID))
|
2021-08-31 11:45:59 +08:00
|
|
|
|
|
|
|
return &milvuspb.GetMetricsResponse{
|
2021-11-19 12:11:12 +08:00
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, metricsinfo.MsgUnimplementedMetric),
|
2021-08-31 11:45:59 +08:00
|
|
|
Response: "",
|
|
|
|
}, nil
|
|
|
|
}
|
2021-09-18 11:13:51 +08:00
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// CreateAlias create collection alias
|
2021-09-18 11:13:51 +08:00
|
|
|
func (c *Core) CreateAlias(ctx context.Context, in *milvuspb.CreateAliasRequest) (*commonpb.Status, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("CreateAlias")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreateAlias", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.String("collection name", in.CollectionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-09-18 11:13:51 +08:00
|
|
|
t := &CreateAliasReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
|
|
|
ctx: ctx,
|
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
|
|
|
err := executeTask(t)
|
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("CreateAlias failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.String("collection name", in.CollectionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "CreateAlias failed: "+err.Error()), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("CreateAlias success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.String("collection name", in.CollectionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("CreateAlias").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// DropAlias drop collection alias
|
2021-09-18 11:13:51 +08:00
|
|
|
func (c *Core) DropAlias(ctx context.Context, in *milvuspb.DropAliasRequest) (*commonpb.Status, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("DropAlias")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropAlias", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.Int64("msgID", in.Base.MsgID))
|
2021-09-18 11:13:51 +08:00
|
|
|
t := &DropAliasReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
|
|
|
ctx: ctx,
|
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
|
|
|
err := executeTask(t)
|
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("DropAlias failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "DropAlias failed: "+err.Error()), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("DropAlias success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("DropAlias").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
|
|
|
|
2021-09-23 15:10:00 +08:00
|
|
|
// AlterAlias alter collection alias
|
2021-09-18 11:13:51 +08:00
|
|
|
func (c *Core) AlterAlias(ctx context.Context, in *milvuspb.AlterAliasRequest) (*commonpb.Status, error) {
|
2021-11-19 12:11:12 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2022-03-02 21:11:57 +08:00
|
|
|
tr := timerecord.NewTimeRecorder("AlterAlias")
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("AlterAlias", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.String("collection name", in.CollectionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-09-18 11:13:51 +08:00
|
|
|
t := &AlterAliasReqTask{
|
|
|
|
baseReqTask: baseReqTask{
|
|
|
|
ctx: ctx,
|
|
|
|
core: c,
|
|
|
|
},
|
|
|
|
Req: in,
|
|
|
|
}
|
|
|
|
err := executeTask(t)
|
|
|
|
if err != nil {
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Error("AlterAlias failed", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.String("collection name", in.CollectionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
2021-11-19 12:11:12 +08:00
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "AlterAlias failed: "+err.Error()), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2021-12-13 09:59:27 +08:00
|
|
|
log.Debug("AlterAlias success", zap.String("role", typeutil.RootCoordRole),
|
2021-11-22 16:01:14 +08:00
|
|
|
zap.String("alias", in.Alias), zap.String("collection name", in.CollectionName),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID))
|
2021-11-19 12:11:12 +08:00
|
|
|
|
2022-03-15 21:51:21 +08:00
|
|
|
metrics.RootCoordDDLWriteTypeLatency.WithLabelValues("AlterAlias").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
2021-11-19 12:11:12 +08:00
|
|
|
return succStatus(), nil
|
2021-09-18 11:13:51 +08:00
|
|
|
}
|
2022-03-11 17:13:59 +08:00
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
// Import imports large files (json, numpy, etc.) on MinIO/S3 storage into Milvus storage.
|
2022-03-11 17:13:59 +08:00
|
|
|
func (c *Core) Import(ctx context.Context, req *milvuspb.ImportRequest) (*milvuspb.ImportResponse, error) {
|
2022-03-21 15:47:23 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return &milvuspb.ImportResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
|
|
|
}, nil
|
2022-03-11 17:13:59 +08:00
|
|
|
}
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
// Get collection/partition ID from collection/partition name.
|
|
|
|
var cID int64
|
|
|
|
var ok bool
|
|
|
|
if cID, ok = c.MetaTable.collName2ID[req.GetCollectionName()]; !ok {
|
|
|
|
log.Error("failed to find collection ID for collection name",
|
|
|
|
zap.String("collection name", req.GetCollectionName()))
|
|
|
|
return nil, fmt.Errorf("collection ID not found for collection name %s", req.GetCollectionName())
|
|
|
|
}
|
2022-04-20 14:03:40 +08:00
|
|
|
var pID int64
|
|
|
|
var err error
|
|
|
|
if pID, err = c.MetaTable.getPartitionByName(cID, req.GetPartitionName(), 0); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Info("receive import request",
|
|
|
|
zap.String("collection name", req.GetCollectionName()),
|
|
|
|
zap.Int64("collection ID", cID),
|
|
|
|
zap.String("partition name", req.GetPartitionName()),
|
2022-04-20 14:03:40 +08:00
|
|
|
zap.Int64("partition ID", pID),
|
2022-03-31 13:51:28 +08:00
|
|
|
zap.Int("# of files = ", len(req.GetFiles())),
|
2022-04-20 14:03:40 +08:00
|
|
|
zap.Bool("row-based", req.GetRowBased()),
|
2022-03-31 13:51:28 +08:00
|
|
|
)
|
2022-04-20 14:03:40 +08:00
|
|
|
resp := c.importManager.importJob(ctx, req, cID, pID)
|
2022-03-11 17:13:59 +08:00
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-04-03 11:37:29 +08:00
|
|
|
// GetImportState returns the current state of an import task.
|
2022-03-11 17:13:59 +08:00
|
|
|
func (c *Core) GetImportState(ctx context.Context, req *milvuspb.GetImportStateRequest) (*milvuspb.GetImportStateResponse, error) {
|
2022-03-21 15:47:23 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return &milvuspb.GetImportStateResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
|
|
|
}, nil
|
|
|
|
}
|
2022-04-06 15:33:32 +08:00
|
|
|
return c.importManager.getTaskState(req.GetTask()), nil
|
2022-03-11 17:13:59 +08:00
|
|
|
}
|
|
|
|
|
2022-04-25 17:37:46 +08:00
|
|
|
// ListImportTasks returns id array of all import tasks.
|
|
|
|
func (c *Core) ListImportTasks(ctx context.Context, req *milvuspb.ListImportTasksRequest) (*milvuspb.ListImportTasksResponse, error) {
|
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return &milvuspb.ListImportTasksResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &milvuspb.ListImportTasksResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
|
|
|
Tasks: c.importManager.listAllTasks(),
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
// ReportImport reports import task state to RootCoord.
|
2022-04-01 11:33:28 +08:00
|
|
|
func (c *Core) ReportImport(ctx context.Context, ir *rootcoordpb.ImportResult) (*commonpb.Status, error) {
|
2022-04-06 15:33:32 +08:00
|
|
|
log.Info("receive import state report",
|
|
|
|
zap.Int64("task ID", ir.GetTaskId()),
|
|
|
|
zap.Any("import state", ir.GetState()))
|
2022-03-21 15:47:23 +08:00
|
|
|
if code, ok := c.checkHealthy(); !ok {
|
|
|
|
return failStatus(commonpb.ErrorCode_UnexpectedError, "StateCode="+internalpb.StateCode_name[int32(code)]), nil
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
// Upon receiving ReportImport request, update the related task's state in task store.
|
2022-04-01 11:33:28 +08:00
|
|
|
ti, err := c.importManager.updateTaskState(ir)
|
2022-03-21 15:47:23 +08:00
|
|
|
if err != nil {
|
|
|
|
return &commonpb.Status{
|
2022-03-31 13:51:28 +08:00
|
|
|
ErrorCode: commonpb.ErrorCode_UpdateImportTaskFailure,
|
2022-03-21 15:47:23 +08:00
|
|
|
Reason: err.Error(),
|
|
|
|
}, nil
|
2022-03-11 17:13:59 +08:00
|
|
|
}
|
2022-04-03 11:37:29 +08:00
|
|
|
|
|
|
|
// That's all for reporting, if task hasn't reached persisted or completed status yet.
|
|
|
|
if ti.GetState().GetStateCode() != commonpb.ImportState_ImportPersisted &&
|
|
|
|
ti.GetState().GetStateCode() != commonpb.ImportState_ImportCompleted {
|
|
|
|
log.Debug("transitional import state received, return immediately", zap.Any("import result", ir))
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-03-31 13:51:28 +08:00
|
|
|
// Reverse look up collection name on collection ID.
|
|
|
|
var colName string
|
|
|
|
for k, v := range c.MetaTable.collName2ID {
|
|
|
|
if v == ti.GetCollectionId() {
|
|
|
|
colName = k
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if colName == "" {
|
|
|
|
log.Error("Collection name not found for collection ID", zap.Int64("collection ID", ti.GetCollectionId()))
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_CollectionNameNotFound,
|
|
|
|
Reason: "Collection name not found for collection ID" + strconv.FormatInt(ti.GetCollectionId(), 10),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2022-04-01 11:33:28 +08:00
|
|
|
// When DataNode has done its thing, remove it from the busy node list.
|
2022-04-03 11:37:29 +08:00
|
|
|
func() {
|
|
|
|
c.importManager.busyNodesLock.Lock()
|
|
|
|
defer c.importManager.busyNodesLock.Unlock()
|
|
|
|
delete(c.importManager.busyNodes, ir.GetDatanodeId())
|
|
|
|
log.Info("dataNode is no longer busy",
|
|
|
|
zap.Int64("dataNode ID", ir.GetDatanodeId()),
|
|
|
|
zap.Int64("task ID", ir.GetTaskId()))
|
|
|
|
}()
|
2022-04-01 11:33:28 +08:00
|
|
|
|
2022-04-20 14:03:40 +08:00
|
|
|
// TODO: Resurrect index check when ready.
|
2022-04-25 11:07:47 +08:00
|
|
|
c.CallFlushOnCollection(ctx, ti.GetCollectionId(), ir.GetSegments())
|
2022-03-11 17:13:59 +08:00
|
|
|
|
2022-03-21 15:47:23 +08:00
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}, nil
|
2022-03-11 17:13:59 +08:00
|
|
|
}
|
2022-03-28 16:41:28 +08:00
|
|
|
|
|
|
|
// CountCompleteIndex checks indexing status of the given segments, and returns the # of segments that has complete index.
|
|
|
|
func (c *Core) CountCompleteIndex(ctx context.Context, collectionName string, collectionID UniqueID,
|
|
|
|
allSegmentIDs []UniqueID) (int, error) {
|
|
|
|
// Note: Index name is always Params.CommonCfg.DefaultIndexName in current Milvus design as of today.
|
|
|
|
indexName := Params.CommonCfg.DefaultIndexName
|
|
|
|
|
|
|
|
// Retrieve index status and detailed index information.
|
|
|
|
describeIndexReq := &milvuspb.DescribeIndexRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeIndex,
|
|
|
|
},
|
|
|
|
CollectionName: collectionName,
|
|
|
|
IndexName: indexName,
|
|
|
|
}
|
|
|
|
indexDescriptionResp, err := c.DescribeIndex(ctx, describeIndexReq)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug("got index description", zap.String("index_description", indexDescriptionResp.String()))
|
2022-03-28 16:41:28 +08:00
|
|
|
|
|
|
|
// Check if the target index name exists.
|
|
|
|
matchIndexID := int64(-1)
|
|
|
|
foundIndexID := false
|
|
|
|
for _, desc := range indexDescriptionResp.IndexDescriptions {
|
|
|
|
if desc.IndexName == indexName {
|
|
|
|
matchIndexID = desc.IndexID
|
|
|
|
foundIndexID = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !foundIndexID {
|
|
|
|
return 0, fmt.Errorf("no index is created")
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug("found match index ID", zap.Int64("match index ID", matchIndexID))
|
2022-03-28 16:41:28 +08:00
|
|
|
|
|
|
|
getIndexStatesRequest := &indexpb.GetIndexStatesRequest{
|
|
|
|
IndexBuildIDs: make([]UniqueID, 0),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch index build IDs from segments.
|
|
|
|
for _, segmentID := range allSegmentIDs {
|
|
|
|
describeSegmentRequest := &milvuspb.DescribeSegmentRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeSegment,
|
|
|
|
},
|
|
|
|
CollectionID: collectionID,
|
|
|
|
SegmentID: segmentID,
|
|
|
|
}
|
|
|
|
segmentDesc, err := c.DescribeSegment(ctx, describeSegmentRequest)
|
|
|
|
if err != nil {
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Error("Failed to describe segment",
|
|
|
|
zap.Int64("collection ID", collectionID),
|
|
|
|
zap.Int64("segment ID", segmentID))
|
2022-03-28 16:41:28 +08:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if segmentDesc.IndexID == matchIndexID {
|
|
|
|
if segmentDesc.EnableIndex {
|
|
|
|
getIndexStatesRequest.IndexBuildIDs = append(getIndexStatesRequest.IndexBuildIDs, segmentDesc.BuildID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Debug("proxy GetIndexState", zap.Int("# of IndexBuildIDs", len(getIndexStatesRequest.IndexBuildIDs)), zap.Error(err))
|
2022-03-28 16:41:28 +08:00
|
|
|
|
|
|
|
if len(getIndexStatesRequest.IndexBuildIDs) == 0 {
|
2022-04-03 11:37:29 +08:00
|
|
|
log.Info("empty index build IDs returned",
|
|
|
|
zap.String("collection name", collectionName),
|
|
|
|
zap.Int64("collection ID", collectionID))
|
2022-03-28 16:41:28 +08:00
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
states, err := c.CallGetIndexStatesService(ctx, getIndexStatesRequest.IndexBuildIDs)
|
|
|
|
if err != nil {
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Error("failed to get index state in checkSegmentIndexStates", zap.Error(err))
|
2022-03-28 16:41:28 +08:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count the # of segments with finished index.
|
|
|
|
ct := 0
|
|
|
|
for _, s := range states {
|
|
|
|
if s.State == commonpb.IndexState_Finished {
|
|
|
|
ct++
|
|
|
|
}
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
log.Info("segment indexing state checked",
|
2022-03-28 16:41:28 +08:00
|
|
|
zap.Int("# of checked segment", len(states)),
|
|
|
|
zap.Int("# of segments with complete index", ct),
|
|
|
|
zap.String("collection name", collectionName),
|
|
|
|
zap.Int64("collection ID", collectionID),
|
|
|
|
)
|
|
|
|
return ct, nil
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
|
2022-04-01 11:33:28 +08:00
|
|
|
// checkCompleteIndexLoop checks index build states for an import task's segments and bring these segments online when
|
|
|
|
// the criteria are met. checkCompleteIndexLoop does the check every CheckCompleteIndexInterval and exits if:
|
2022-04-03 11:37:29 +08:00
|
|
|
// (1) a certain percent of indices are built, (2) when context is done or (3) when `ImportIndexWaitLimit` has passed.
|
2022-04-01 11:33:28 +08:00
|
|
|
func (c *Core) checkCompleteIndexLoop(ctx context.Context, ti *datapb.ImportTaskInfo, colName string, segIDs []UniqueID) {
|
2022-03-31 13:51:28 +08:00
|
|
|
defer c.wg.Done()
|
2022-04-03 11:37:29 +08:00
|
|
|
ticker := time.NewTicker(time.Duration(Params.RootCoordCfg.ImportIndexCheckInterval*1000) * time.Millisecond)
|
|
|
|
defer ticker.Stop()
|
|
|
|
expireTicker := time.NewTicker(time.Duration(Params.RootCoordCfg.ImportIndexWaitLimit*1000) * time.Millisecond)
|
|
|
|
defer expireTicker.Stop()
|
2022-03-31 13:51:28 +08:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-c.ctx.Done():
|
2022-04-06 15:33:32 +08:00
|
|
|
log.Info("(in check complete index loop) context done, exiting checkCompleteIndexLoop",
|
2022-04-03 11:37:29 +08:00
|
|
|
zap.Int64("task ID", ti.GetId()))
|
2022-03-31 13:51:28 +08:00
|
|
|
return
|
|
|
|
case <-ticker.C:
|
2022-04-06 15:33:32 +08:00
|
|
|
log.Info("(in check complete index loop) check segments' index states", zap.Int64("task ID", ti.GetId()))
|
2022-03-31 13:51:28 +08:00
|
|
|
if ct, err := c.CountCompleteIndex(ctx, colName, ti.GetCollectionId(), segIDs); err == nil &&
|
|
|
|
segmentsOnlineReady(ct, len(segIDs)) {
|
2022-04-06 15:33:32 +08:00
|
|
|
log.Info("segment indices are ready",
|
2022-03-31 13:51:28 +08:00
|
|
|
zap.Int64("task ID", ti.GetId()),
|
|
|
|
zap.Int("total # of segments", len(segIDs)),
|
|
|
|
zap.Int("# of segments with index ready", ct))
|
2022-04-06 15:33:32 +08:00
|
|
|
c.bringSegmentsOnline(ctx, segIDs)
|
2022-03-31 13:51:28 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
case <-expireTicker.C:
|
2022-04-06 15:33:32 +08:00
|
|
|
log.Info("(in check complete index loop) waited for sufficiently long time, bring segments online",
|
2022-04-03 11:37:29 +08:00
|
|
|
zap.Int64("task ID", ti.GetId()))
|
2022-04-06 15:33:32 +08:00
|
|
|
c.bringSegmentsOnline(ctx, segIDs)
|
2022-03-31 13:51:28 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 15:33:32 +08:00
|
|
|
// bringSegmentsOnline brings the segments online so that data in these segments become searchable
|
|
|
|
// it is done by changing segments' states from `importing` to `flushed`.
|
|
|
|
func (c *Core) bringSegmentsOnline(ctx context.Context, segIDs []UniqueID) {
|
|
|
|
log.Info("bringing import task's segments online!", zap.Any("segment IDs", segIDs))
|
|
|
|
// TODO: Make update on segment states atomic.
|
|
|
|
for _, id := range segIDs {
|
2022-04-20 14:03:40 +08:00
|
|
|
// Explicitly mark segment states `flushing`.
|
|
|
|
c.CallUpdateSegmentStateService(ctx, id, commonpb.SegmentState_Flushing)
|
2022-04-06 15:33:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// segmentsOnlineReady returns true if segments are ready to go up online (a.k.a. become searchable).
|
2022-03-31 13:51:28 +08:00
|
|
|
func segmentsOnlineReady(idxBuilt, segCount int) bool {
|
|
|
|
// Consider segments are ready when:
|
|
|
|
// (1) all but up to 2 segments have indices ready, or
|
|
|
|
// (2) over 85% of segments have indices ready.
|
|
|
|
if segCount-idxBuilt <= 2 || float64(idxBuilt)/float64(segCount) > 0.85 {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-04-11 19:49:34 +08:00
|
|
|
|
|
|
|
// ExpireCredCache will call invalidate credential cache
|
|
|
|
func (c *Core) ExpireCredCache(ctx context.Context, username string) error {
|
|
|
|
req := proxypb.InvalidateCredCacheRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: 0, //TODO, msg type
|
|
|
|
MsgID: 0, //TODO, msg id
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
|
|
|
Username: username,
|
|
|
|
}
|
|
|
|
return c.proxyClientManager.InvalidateCredentialCache(ctx, &req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateCredCache will call update credential cache
|
|
|
|
func (c *Core) UpdateCredCache(ctx context.Context, credInfo *internalpb.CredentialInfo) error {
|
|
|
|
req := proxypb.UpdateCredCacheRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: 0, //TODO, msg type
|
|
|
|
MsgID: 0, //TODO, msg id
|
|
|
|
SourceID: c.session.ServerID,
|
|
|
|
},
|
|
|
|
Username: credInfo.Username,
|
|
|
|
Password: credInfo.EncryptedPassword,
|
|
|
|
}
|
|
|
|
return c.proxyClientManager.UpdateCredentialCache(ctx, &req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearCredUsersCache will call clear credential usernames cache
|
|
|
|
func (c *Core) ClearCredUsersCache(ctx context.Context) error {
|
|
|
|
req := internalpb.ClearCredUsersCacheRequest{}
|
|
|
|
return c.proxyClientManager.ClearCredUsersCache(ctx, &req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateCredential create new user and password
|
|
|
|
// 1. decode ciphertext password to raw password
|
|
|
|
// 2. encrypt raw password
|
|
|
|
// 3. save in to etcd
|
|
|
|
func (c *Core) CreateCredential(ctx context.Context, credInfo *internalpb.CredentialInfo) (*commonpb.Status, error) {
|
|
|
|
metrics.RootCoordCreateCredentialCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
|
|
|
tr := timerecord.NewTimeRecorder("CreateCredential")
|
|
|
|
log.Debug("CreateCredential", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username))
|
|
|
|
|
|
|
|
if cred, _ := c.MetaTable.getCredential(credInfo.Username); cred != nil {
|
|
|
|
return failStatus(commonpb.ErrorCode_CreateCredentialFailure, "user already exists:"+credInfo.Username), nil
|
|
|
|
}
|
|
|
|
// update proxy's local cache
|
|
|
|
err := c.ClearCredUsersCache(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("CreateCredential clear credential username list cache failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordCreateCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return failStatus(commonpb.ErrorCode_CreateCredentialFailure, "CreateCredential failed: "+err.Error()), nil
|
|
|
|
}
|
|
|
|
// insert to db
|
|
|
|
err = c.MetaTable.AddCredential(credInfo)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("CreateCredential save credential failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordCreateCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return failStatus(commonpb.ErrorCode_CreateCredentialFailure, "CreateCredential failed: "+err.Error()), nil
|
|
|
|
}
|
|
|
|
log.Debug("CreateCredential success", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username))
|
|
|
|
|
|
|
|
metrics.RootCoordCreateCredentialCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
|
|
|
metrics.RootCoordCredentialWriteTypeLatency.WithLabelValues("CreateCredential").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
metrics.RootCoordNumOfCredentials.Inc()
|
|
|
|
return succStatus(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetCredential get credential by username
|
|
|
|
func (c *Core) GetCredential(ctx context.Context, in *rootcoordpb.GetCredentialRequest) (*rootcoordpb.GetCredentialResponse, error) {
|
|
|
|
metrics.RootCoordGetCredentialCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
|
|
|
tr := timerecord.NewTimeRecorder("GetCredential")
|
|
|
|
log.Debug("GetCredential", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username))
|
|
|
|
|
|
|
|
credInfo, err := c.MetaTable.getCredential(in.Username)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("GetCredential query credential failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordGetCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return &rootcoordpb.GetCredentialResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_GetCredentialFailure, "GetCredential failed: "+err.Error()),
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
log.Debug("GetCredential success", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username))
|
|
|
|
|
|
|
|
metrics.RootCoordGetCredentialCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
|
|
|
metrics.RootCoordCredentialReadTypeLatency.WithLabelValues("GetCredential", in.Username).Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return &rootcoordpb.GetCredentialResponse{
|
|
|
|
Status: succStatus(),
|
|
|
|
Username: credInfo.Username,
|
|
|
|
Password: credInfo.EncryptedPassword,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateCredential update password for a user
|
|
|
|
func (c *Core) UpdateCredential(ctx context.Context, credInfo *internalpb.CredentialInfo) (*commonpb.Status, error) {
|
|
|
|
metrics.RootCoordUpdateCredentialCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
|
|
|
tr := timerecord.NewTimeRecorder("UpdateCredential")
|
|
|
|
log.Debug("UpdateCredential", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username))
|
|
|
|
// update proxy's local cache
|
|
|
|
err := c.UpdateCredCache(ctx, credInfo)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("UpdateCredential update credential cache failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordUpdateCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return failStatus(commonpb.ErrorCode_UpdateCredentialFailure, "UpdateCredential failed: "+err.Error()), nil
|
|
|
|
}
|
|
|
|
// update data on storage
|
|
|
|
err = c.MetaTable.AddCredential(credInfo)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("UpdateCredential save credential failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordUpdateCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return failStatus(commonpb.ErrorCode_UpdateCredentialFailure, "UpdateCredential failed: "+err.Error()), nil
|
|
|
|
}
|
|
|
|
log.Debug("UpdateCredential success", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", credInfo.Username))
|
|
|
|
|
|
|
|
metrics.RootCoordUpdateCredentialCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
|
|
|
metrics.RootCoordCredentialWriteTypeLatency.WithLabelValues("UpdateCredential").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return succStatus(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteCredential delete a user
|
|
|
|
func (c *Core) DeleteCredential(ctx context.Context, in *milvuspb.DeleteCredentialRequest) (*commonpb.Status, error) {
|
|
|
|
metrics.RootCoordDeleteCredentialCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
|
|
|
tr := timerecord.NewTimeRecorder("DeleteCredential")
|
|
|
|
|
|
|
|
log.Debug("DeleteCredential", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username))
|
|
|
|
// invalidate proxy's local cache
|
|
|
|
err := c.ExpireCredCache(ctx, in.Username)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("DeleteCredential expire credential cache failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordDeleteCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return failStatus(commonpb.ErrorCode_DeleteCredentialFailure, "DeleteCredential failed: "+err.Error()), nil
|
|
|
|
}
|
|
|
|
// delete data on storage
|
|
|
|
err = c.MetaTable.DeleteCredential(in.Username)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("DeleteCredential remove credential failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username), zap.Error(err))
|
|
|
|
metrics.RootCoordDeleteCredentialCounter.WithLabelValues(metrics.FailLabel).Inc()
|
|
|
|
return failStatus(commonpb.ErrorCode_DeleteCredentialFailure, "DeleteCredential failed: "+err.Error()), err
|
|
|
|
}
|
|
|
|
log.Debug("DeleteCredential success", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.String("username", in.Username))
|
|
|
|
|
|
|
|
metrics.RootCoordDeleteCredentialCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
|
|
|
metrics.RootCoordCredentialWriteTypeLatency.WithLabelValues("DeleteCredential").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
metrics.RootCoordNumOfCredentials.Dec()
|
|
|
|
return succStatus(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListCredUsers list all usernames
|
|
|
|
func (c *Core) ListCredUsers(ctx context.Context, in *milvuspb.ListCredUsersRequest) (*milvuspb.ListCredUsersResponse, error) {
|
|
|
|
metrics.RootCoordListCredUsersCounter.WithLabelValues(metrics.TotalLabel).Inc()
|
|
|
|
tr := timerecord.NewTimeRecorder("ListCredUsers")
|
|
|
|
|
|
|
|
credInfo, err := c.MetaTable.ListCredentialUsernames()
|
|
|
|
if err != nil {
|
|
|
|
log.Error("ListCredUsers query usernames failed", zap.String("role", typeutil.RootCoordRole),
|
|
|
|
zap.Int64("msgID", in.Base.MsgID), zap.Error(err))
|
|
|
|
return &milvuspb.ListCredUsersResponse{
|
|
|
|
Status: failStatus(commonpb.ErrorCode_ListCredUsersFailure, "ListCredUsers failed: "+err.Error()),
|
|
|
|
}, err
|
|
|
|
}
|
|
|
|
log.Debug("ListCredUsers success", zap.String("role", typeutil.RootCoordRole))
|
|
|
|
|
|
|
|
metrics.RootCoordListCredUsersCounter.WithLabelValues(metrics.SuccessLabel).Inc()
|
|
|
|
metrics.RootCoordCredentialReadTypeLatency.WithLabelValues("ListCredUsers", "ALL.API").Observe(float64(tr.ElapseSpan().Milliseconds()))
|
|
|
|
return &milvuspb.ListCredUsersResponse{
|
|
|
|
Status: succStatus(),
|
|
|
|
Usernames: credInfo.Usernames,
|
|
|
|
}, nil
|
|
|
|
}
|