2021-11-10 15:56:01 +00: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 02:09:43 +00:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-11-10 15:56:01 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 02:09:43 +00:00
|
|
|
//
|
2021-11-10 15:56:01 +00: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 02:09:43 +00:00
|
|
|
|
2021-06-22 06:40:07 +00:00
|
|
|
package proxy
|
2021-01-22 01:36:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-16 01:56:47 +00:00
|
|
|
"fmt"
|
2021-01-22 01:36:18 +00:00
|
|
|
"math/rand"
|
2022-03-17 09:17:22 +00:00
|
|
|
"os"
|
2022-03-02 08:23:55 +00:00
|
|
|
"strconv"
|
2021-01-22 01:36:18 +00:00
|
|
|
"sync"
|
2021-03-04 14:27:12 +00:00
|
|
|
"sync/atomic"
|
2021-12-10 14:09:17 +00:00
|
|
|
"syscall"
|
2021-01-22 01:36:18 +00:00
|
|
|
"time"
|
|
|
|
|
2023-02-26 03:31:49 +00:00
|
|
|
"github.com/cockroachdb/errors"
|
2022-04-07 14:05:32 +00:00
|
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2023-06-08 17:28:37 +00:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-09-21 01:45:27 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2022-11-10 09:09:06 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/proxy/accesslog"
|
2021-04-22 06:45:57 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2023-09-21 01:45:27 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2023-04-06 11:14:32 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/metrics"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/logutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/ratelimitutil"
|
2023-09-21 01:45:27 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/tsoutil"
|
2023-04-06 11:14:32 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2021-01-22 01:36:18 +00:00
|
|
|
)
|
|
|
|
|
2021-10-28 15:56:40 +00:00
|
|
|
// UniqueID is alias of typeutil.UniqueID
|
2021-01-22 01:36:18 +00:00
|
|
|
type UniqueID = typeutil.UniqueID
|
2021-10-28 15:56:40 +00:00
|
|
|
|
|
|
|
// Timestamp is alias of typeutil.Timestamp
|
2021-01-22 01:36:18 +00:00
|
|
|
type Timestamp = typeutil.Timestamp
|
|
|
|
|
2021-12-30 02:29:47 +00:00
|
|
|
// const sendTimeTickMsgInterval = 200 * time.Millisecond
|
|
|
|
// const channelMgrTickerInterval = 100 * time.Millisecond
|
2021-06-15 02:19:38 +00:00
|
|
|
|
2021-10-04 09:28:30 +00:00
|
|
|
// make sure Proxy implements types.Proxy
|
|
|
|
var _ types.Proxy = (*Proxy)(nil)
|
|
|
|
|
2022-11-04 06:25:38 +00:00
|
|
|
var Params *paramtable.ComponentParam = paramtable.Get()
|
2021-12-23 10:39:11 +00:00
|
|
|
|
2022-09-16 01:56:47 +00:00
|
|
|
// rateCol is global rateCollector in Proxy.
|
|
|
|
var rateCol *ratelimitutil.RateCollector
|
|
|
|
|
2021-12-15 13:11:35 +00:00
|
|
|
// Proxy of milvus
|
2021-06-22 06:40:07 +00:00
|
|
|
type Proxy struct {
|
2021-01-22 01:36:18 +00:00
|
|
|
ctx context.Context
|
2023-07-28 02:11:08 +00:00
|
|
|
cancel context.CancelFunc
|
2021-01-22 01:36:18 +00:00
|
|
|
wg sync.WaitGroup
|
|
|
|
|
2021-03-12 06:22:09 +00:00
|
|
|
initParams *internalpb.InitParams
|
2021-01-28 12:51:44 +00:00
|
|
|
ip string
|
|
|
|
port int
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2021-03-04 14:27:12 +00:00
|
|
|
stateCode atomic.Value
|
2021-01-29 01:27:26 +00:00
|
|
|
|
2021-12-29 06:35:21 +00:00
|
|
|
etcdCli *clientv3.Client
|
2022-11-04 06:25:38 +00:00
|
|
|
address string
|
2023-09-26 01:57:25 +00:00
|
|
|
rootCoord types.RootCoordClient
|
|
|
|
dataCoord types.DataCoordClient
|
|
|
|
queryCoord types.QueryCoordClient
|
2021-01-28 12:51:44 +00:00
|
|
|
|
2022-09-16 01:56:47 +00:00
|
|
|
multiRateLimiter *MultiRateLimiter
|
|
|
|
|
2021-05-27 09:09:50 +00:00
|
|
|
chMgr channelsMgr
|
|
|
|
|
2021-09-06 12:49:04 +00:00
|
|
|
sched *taskScheduler
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2021-05-29 01:55:29 +00:00
|
|
|
chTicker channelsTimeTicker
|
|
|
|
|
2022-10-09 02:06:58 +00:00
|
|
|
rowIDAllocator *allocator.IDAllocator
|
|
|
|
tsoAllocator *timestampAllocator
|
|
|
|
segAssigner *segIDAssigner
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2021-09-03 09:15:26 +00:00
|
|
|
metricsCacheManager *metricsinfo.MetricsCacheManager
|
|
|
|
|
2022-06-02 04:16:03 +00:00
|
|
|
session *sessionutil.Session
|
2023-06-13 02:20:37 +00:00
|
|
|
shardMgr shardClientMgr
|
2021-05-21 11:28:52 +00:00
|
|
|
|
2022-04-07 14:05:32 +00:00
|
|
|
factory dependency.Factory
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2022-04-20 08:15:41 +00:00
|
|
|
searchResultCh chan *internalpb.SearchResults
|
2022-01-17 06:41:35 +00:00
|
|
|
|
2021-01-22 01:36:18 +00:00
|
|
|
// Add callback functions at different stages
|
|
|
|
startCallbacks []func()
|
|
|
|
closeCallbacks []func()
|
2023-06-13 02:20:37 +00:00
|
|
|
|
|
|
|
// for load balance in replicas
|
|
|
|
lbPolicy LBPolicy
|
2021-01-22 01:36:18 +00:00
|
|
|
}
|
|
|
|
|
2021-10-07 12:24:40 +00:00
|
|
|
// NewProxy returns a Proxy struct.
|
2022-04-07 14:05:32 +00:00
|
|
|
func NewProxy(ctx context.Context, factory dependency.Factory) (*Proxy, error) {
|
2021-01-22 01:36:18 +00:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
2022-01-17 06:41:35 +00:00
|
|
|
n := 1024 // better to be configurable
|
2023-06-13 02:20:37 +00:00
|
|
|
mgr := newShardClientMgr()
|
2023-06-27 01:52:44 +00:00
|
|
|
lbPolicy := NewLBPolicyImpl(mgr)
|
|
|
|
lbPolicy.Start(ctx)
|
2021-06-22 06:40:07 +00:00
|
|
|
node := &Proxy{
|
2022-09-16 01:56:47 +00:00
|
|
|
ctx: ctx1,
|
|
|
|
cancel: cancel,
|
|
|
|
factory: factory,
|
|
|
|
searchResultCh: make(chan *internalpb.SearchResults, n),
|
2023-06-13 02:20:37 +00:00
|
|
|
shardMgr: mgr,
|
2022-09-16 01:56:47 +00:00
|
|
|
multiRateLimiter: NewMultiRateLimiter(),
|
2023-06-27 01:52:44 +00:00
|
|
|
lbPolicy: lbPolicy,
|
2021-01-22 01:36:18 +00:00
|
|
|
}
|
2022-10-10 07:55:22 +00:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-12-17 11:07:39 +00:00
|
|
|
logutil.Logger(ctx).Debug("create a new Proxy instance", zap.Any("state", node.stateCode.Load()))
|
2021-01-22 01:36:18 +00:00
|
|
|
return node, nil
|
|
|
|
}
|
|
|
|
|
2021-12-06 11:15:48 +00:00
|
|
|
// Register registers proxy at etcd
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) Register() error {
|
2021-12-15 03:47:10 +00:00
|
|
|
node.session.Register()
|
2023-06-26 09:52:44 +00:00
|
|
|
metrics.NumNodes.WithLabelValues(fmt.Sprint(paramtable.GetNodeID()), typeutil.ProxyRole).Inc()
|
|
|
|
log.Info("Proxy Register Finished")
|
2023-04-12 12:12:28 +00:00
|
|
|
node.session.LivenessCheck(node.ctx, func() {
|
2021-10-30 02:24:38 +00:00
|
|
|
log.Error("Proxy disconnected from etcd, process will exit", zap.Int64("Server Id", node.session.ServerID))
|
|
|
|
if err := node.Stop(); err != nil {
|
|
|
|
log.Fatal("failed to stop server", zap.Error(err))
|
|
|
|
}
|
2023-06-26 09:52:44 +00:00
|
|
|
metrics.NumNodes.WithLabelValues(fmt.Sprint(paramtable.GetNodeID()), typeutil.ProxyRole).Dec()
|
2021-12-29 06:35:21 +00:00
|
|
|
if node.session.TriggerKill {
|
2022-03-17 09:17:22 +00:00
|
|
|
if p, err := os.FindProcess(os.Getpid()); err == nil {
|
|
|
|
p.Signal(syscall.SIGINT)
|
|
|
|
}
|
2021-12-29 06:35:21 +00:00
|
|
|
}
|
2021-10-27 13:58:33 +00:00
|
|
|
})
|
2021-09-27 09:37:57 +00:00
|
|
|
// TODO Reset the logger
|
2023-09-21 01:45:27 +00:00
|
|
|
// Params.initLogCfg()
|
2021-05-25 07:06:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-29 06:29:37 +00:00
|
|
|
// initSession initialize the session of Proxy.
|
2021-12-15 03:47:10 +00:00
|
|
|
func (node *Proxy) initSession() error {
|
2022-11-17 10:59:09 +00:00
|
|
|
node.session = sessionutil.NewSession(node.ctx, Params.EtcdCfg.MetaRootPath.GetValue(), node.etcdCli)
|
2021-12-15 03:47:10 +00:00
|
|
|
if node.session == nil {
|
|
|
|
return errors.New("new session failed, maybe etcd cannot be connected")
|
|
|
|
}
|
2022-11-04 06:25:38 +00:00
|
|
|
node.session.Init(typeutil.ProxyRole, node.address, false, true)
|
2021-12-15 03:47:10 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-16 01:56:47 +00:00
|
|
|
// initRateCollector creates and starts rateCollector in Proxy.
|
|
|
|
func (node *Proxy) initRateCollector() error {
|
|
|
|
var err error
|
|
|
|
rateCol, err = ratelimitutil.NewRateCollector(ratelimitutil.DefaultWindow, ratelimitutil.DefaultGranularity)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rateCol.Register(internalpb.RateType_DMLInsert.String())
|
2023-07-11 03:20:34 +00:00
|
|
|
rateCol.Register(internalpb.RateType_DMLUpsert.String())
|
2022-09-16 01:56:47 +00:00
|
|
|
rateCol.Register(internalpb.RateType_DMLDelete.String())
|
|
|
|
// TODO: add bulkLoad rate
|
|
|
|
rateCol.Register(internalpb.RateType_DQLSearch.String())
|
|
|
|
rateCol.Register(internalpb.RateType_DQLQuery.String())
|
2022-10-13 06:57:24 +00:00
|
|
|
rateCol.Register(metricsinfo.ReadResultThroughput)
|
2022-09-16 01:56:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-14 11:14:35 +00:00
|
|
|
// Init initialize proxy.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) Init() error {
|
2022-04-14 12:01:34 +00:00
|
|
|
log.Info("init session for Proxy")
|
2021-12-25 08:10:17 +00:00
|
|
|
if err := node.initSession(); err != nil {
|
|
|
|
log.Warn("failed to init Proxy's session", zap.Error(err))
|
2021-12-15 03:47:10 +00:00
|
|
|
return err
|
|
|
|
}
|
2022-04-14 12:01:34 +00:00
|
|
|
log.Info("init session for Proxy done")
|
2021-01-29 01:27:26 +00:00
|
|
|
|
2022-11-04 06:25:38 +00:00
|
|
|
node.factory.Init(Params)
|
2021-02-08 06:30:54 +00:00
|
|
|
|
2022-11-10 09:09:06 +00:00
|
|
|
accesslog.SetupAccseeLog(&Params.ProxyCfg.AccessLog, &Params.MinioCfg)
|
|
|
|
log.Debug("init access log for Proxy done")
|
|
|
|
|
2022-09-16 01:56:47 +00:00
|
|
|
err := node.initRateCollector()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-04 06:25:38 +00:00
|
|
|
log.Info("Proxy init rateCollector done", zap.Int64("nodeID", paramtable.GetNodeID()))
|
2022-09-16 01:56:47 +00:00
|
|
|
|
2022-11-04 06:25:38 +00:00
|
|
|
idAllocator, err := allocator.NewIDAllocator(node.ctx, node.rootCoord, paramtable.GetNodeID())
|
2021-01-22 01:36:18 +00:00
|
|
|
if err != nil {
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Warn("failed to create id allocator",
|
2023-06-19 05:28:41 +00:00
|
|
|
zap.String("role", typeutil.ProxyRole), zap.Int64("ProxyID", paramtable.GetNodeID()),
|
|
|
|
zap.Error(err))
|
2021-01-22 01:36:18 +00:00
|
|
|
return err
|
|
|
|
}
|
2022-10-09 02:06:58 +00:00
|
|
|
node.rowIDAllocator = idAllocator
|
2022-11-04 06:25:38 +00:00
|
|
|
log.Debug("create id allocator done", zap.String("role", typeutil.ProxyRole), zap.Int64("ProxyID", paramtable.GetNodeID()))
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2023-03-09 10:51:52 +00:00
|
|
|
tsoAllocator, err := newTimestampAllocator(node.rootCoord, paramtable.GetNodeID())
|
2021-01-22 01:36:18 +00:00
|
|
|
if err != nil {
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Warn("failed to create timestamp allocator",
|
2023-06-19 05:28:41 +00:00
|
|
|
zap.String("role", typeutil.ProxyRole), zap.Int64("ProxyID", paramtable.GetNodeID()),
|
|
|
|
zap.Error(err))
|
2021-01-22 01:36:18 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
node.tsoAllocator = tsoAllocator
|
2022-11-04 06:25:38 +00:00
|
|
|
log.Debug("create timestamp allocator done", zap.String("role", typeutil.ProxyRole), zap.Int64("ProxyID", paramtable.GetNodeID()))
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2021-09-28 15:06:15 +00:00
|
|
|
segAssigner, err := newSegIDAssigner(node.ctx, node.dataCoord, node.lastTick)
|
2021-01-22 01:36:18 +00:00
|
|
|
if err != nil {
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Warn("failed to create segment id assigner",
|
2023-06-19 05:28:41 +00:00
|
|
|
zap.String("role", typeutil.ProxyRole), zap.Int64("ProxyID", paramtable.GetNodeID()),
|
|
|
|
zap.Error(err))
|
2021-12-25 08:10:17 +00:00
|
|
|
return err
|
2021-01-22 01:36:18 +00:00
|
|
|
}
|
|
|
|
node.segAssigner = segAssigner
|
2022-11-04 06:25:38 +00:00
|
|
|
node.segAssigner.PeerID = paramtable.GetNodeID()
|
|
|
|
log.Debug("create segment id assigner done", zap.String("role", typeutil.ProxyRole), zap.Int64("ProxyID", paramtable.GetNodeID()))
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2021-09-13 09:12:19 +00:00
|
|
|
dmlChannelsFunc := getDmlChannelsFunc(node.ctx, node.rootCoord)
|
2022-06-02 07:34:04 +00:00
|
|
|
chMgr := newChannelsMgrImpl(dmlChannelsFunc, defaultInsertRepackFunc, node.factory)
|
2021-05-27 09:09:50 +00:00
|
|
|
node.chMgr = chMgr
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("create channels manager done", zap.String("role", typeutil.ProxyRole))
|
2021-05-27 09:09:50 +00:00
|
|
|
|
2022-10-09 02:06:58 +00:00
|
|
|
node.sched, err = newTaskScheduler(node.ctx, node.tsoAllocator, node.factory)
|
2021-01-22 01:36:18 +00:00
|
|
|
if err != nil {
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Warn("failed to create task scheduler", zap.String("role", typeutil.ProxyRole), zap.Error(err))
|
2021-01-22 01:36:18 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("create task scheduler done", zap.String("role", typeutil.ProxyRole))
|
2021-01-22 01:36:18 +00:00
|
|
|
|
2022-12-07 10:01:19 +00:00
|
|
|
syncTimeTickInterval := Params.ProxyCfg.TimeTickInterval.GetAsDuration(time.Millisecond) / 2
|
|
|
|
node.chTicker = newChannelsTimeTicker(node.ctx, Params.ProxyCfg.TimeTickInterval.GetAsDuration(time.Millisecond)/2, []string{}, node.sched.getPChanStatistics, tsoAllocator)
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Debug("create channels time ticker done", zap.String("role", typeutil.ProxyRole), zap.Duration("syncTimeTickInterval", syncTimeTickInterval))
|
2021-05-29 01:55:29 +00:00
|
|
|
|
2021-09-03 09:15:26 +00:00
|
|
|
node.metricsCacheManager = metricsinfo.NewMetricsCacheManager()
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("create metrics cache manager done", zap.String("role", typeutil.ProxyRole))
|
|
|
|
|
2022-08-04 03:04:34 +00:00
|
|
|
if err := InitMetaCache(node.ctx, node.rootCoord, node.queryCoord, node.shardMgr); err != nil {
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Warn("failed to init meta cache", zap.String("role", typeutil.ProxyRole), zap.Error(err))
|
2021-12-25 08:10:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Debug("init meta cache done", zap.String("role", typeutil.ProxyRole))
|
2021-09-03 09:15:26 +00:00
|
|
|
|
2021-01-22 01:36:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-27 10:58:20 +00:00
|
|
|
// sendChannelsTimeTickLoop starts a goroutine that synchronizes the time tick information.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) sendChannelsTimeTickLoop() {
|
2021-05-31 09:28:31 +00:00
|
|
|
node.wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer node.wg.Done()
|
|
|
|
|
2023-02-23 10:59:45 +00:00
|
|
|
ticker := time.NewTicker(Params.ProxyCfg.TimeTickInterval.GetAsDuration(time.Millisecond))
|
|
|
|
defer ticker.Stop()
|
2021-05-31 09:28:31 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-node.ctx.Done():
|
2021-12-30 02:29:47 +00:00
|
|
|
log.Info("send channels time tick loop exit")
|
2021-05-31 09:28:31 +00:00
|
|
|
return
|
2023-02-23 10:59:45 +00:00
|
|
|
case <-ticker.C:
|
2021-11-05 01:14:02 +00:00
|
|
|
stats, ts, err := node.chTicker.getMinTsStatistics()
|
2021-06-18 07:14:08 +00:00
|
|
|
if err != nil {
|
2021-11-05 01:14:02 +00:00
|
|
|
log.Warn("sendChannelsTimeTickLoop.getMinTsStatistics", zap.Error(err))
|
2021-06-18 07:14:08 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-11-05 01:14:02 +00:00
|
|
|
if ts == 0 {
|
|
|
|
log.Warn("sendChannelsTimeTickLoop.getMinTsStatistics default timestamp equal 0")
|
2021-05-31 09:28:31 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-06-08 11:25:37 +00:00
|
|
|
channels := make([]pChan, 0, len(stats))
|
|
|
|
tss := make([]Timestamp, 0, len(stats))
|
|
|
|
|
2021-06-18 07:14:08 +00:00
|
|
|
maxTs := ts
|
2021-06-08 11:25:37 +00:00
|
|
|
for channel, ts := range stats {
|
|
|
|
channels = append(channels, channel)
|
|
|
|
tss = append(tss, ts)
|
2021-06-18 07:14:08 +00:00
|
|
|
if ts > maxTs {
|
|
|
|
maxTs = ts
|
|
|
|
}
|
2021-06-08 11:25:37 +00:00
|
|
|
}
|
2021-06-18 07:14:08 +00:00
|
|
|
|
2021-05-31 09:28:31 +00:00
|
|
|
req := &internalpb.ChannelTimeTickMsg{
|
2022-10-19 02:01:26 +00:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_TimeTick), // todo
|
|
|
|
commonpbutil.WithMsgID(0), // todo
|
|
|
|
commonpbutil.WithSourceID(node.session.ServerID),
|
|
|
|
),
|
2021-06-18 07:14:08 +00:00
|
|
|
ChannelNames: channels,
|
|
|
|
Timestamps: tss,
|
|
|
|
DefaultTimestamp: maxTs,
|
2021-05-31 09:28:31 +00:00
|
|
|
}
|
2023-04-06 07:28:33 +00:00
|
|
|
|
|
|
|
func() {
|
|
|
|
// we should pay more attention to the max lag.
|
|
|
|
minTs := maxTs
|
|
|
|
minTsOfChannel := "default"
|
|
|
|
|
|
|
|
// find the min ts and the related channel.
|
|
|
|
for channel, ts := range stats {
|
|
|
|
if ts < minTs {
|
|
|
|
minTs = ts
|
|
|
|
minTsOfChannel = channel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub := tsoutil.SubByNow(minTs)
|
|
|
|
metrics.ProxySyncTimeTickLag.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), minTsOfChannel).Set(float64(sub))
|
|
|
|
}()
|
|
|
|
|
2021-06-21 09:28:03 +00:00
|
|
|
status, err := node.rootCoord.UpdateChannelTimeTick(node.ctx, req)
|
2021-05-31 09:28:31 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Warn("sendChannelsTimeTickLoop.UpdateChannelTimeTick", zap.Error(err))
|
|
|
|
continue
|
|
|
|
}
|
2023-09-15 02:09:21 +00:00
|
|
|
if status.GetErrorCode() != 0 {
|
2021-05-31 09:28:31 +00:00
|
|
|
log.Warn("sendChannelsTimeTickLoop.UpdateChannelTimeTick",
|
|
|
|
zap.Any("ErrorCode", status.ErrorCode),
|
|
|
|
zap.Any("Reason", status.Reason))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2021-10-16 14:06:57 +00:00
|
|
|
// Start starts a proxy node.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) Start() error {
|
2021-09-09 02:06:29 +00:00
|
|
|
if err := node.sched.Start(); err != nil {
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Warn("failed to start task scheduler", zap.String("role", typeutil.ProxyRole), zap.Error(err))
|
2021-09-09 02:06:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("start task scheduler done", zap.String("role", typeutil.ProxyRole))
|
2021-01-29 09:29:31 +00:00
|
|
|
|
2022-10-09 02:06:58 +00:00
|
|
|
if err := node.rowIDAllocator.Start(); err != nil {
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Warn("failed to start id allocator", zap.String("role", typeutil.ProxyRole), zap.Error(err))
|
2021-09-09 02:06:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("start id allocator done", zap.String("role", typeutil.ProxyRole))
|
2021-01-29 09:29:31 +00:00
|
|
|
|
2021-09-09 02:06:29 +00:00
|
|
|
if err := node.segAssigner.Start(); err != nil {
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Warn("failed to start segment id assigner", zap.String("role", typeutil.ProxyRole), zap.Error(err))
|
2021-09-09 02:06:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("start segment id assigner done", zap.String("role", typeutil.ProxyRole))
|
2021-01-29 09:29:31 +00:00
|
|
|
|
2021-12-25 08:10:17 +00:00
|
|
|
if err := node.chTicker.start(); err != nil {
|
2023-06-19 05:28:41 +00:00
|
|
|
log.Warn("failed to start channels time ticker", zap.String("role", typeutil.ProxyRole), zap.Error(err))
|
2021-05-29 01:55:29 +00:00
|
|
|
return err
|
|
|
|
}
|
2021-12-25 08:10:17 +00:00
|
|
|
log.Debug("start channels time ticker done", zap.String("role", typeutil.ProxyRole))
|
2021-05-29 01:55:29 +00:00
|
|
|
|
2021-05-31 09:28:31 +00:00
|
|
|
node.sendChannelsTimeTickLoop()
|
|
|
|
|
2021-01-22 01:36:18 +00:00
|
|
|
// Start callbacks
|
|
|
|
for _, cb := range node.startCallbacks {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
2022-10-10 07:55:22 +00:00
|
|
|
log.Debug("update state code", zap.String("role", typeutil.ProxyRole), zap.String("State", commonpb.StateCode_Healthy.String()))
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2021-03-04 14:27:12 +00:00
|
|
|
|
2021-01-22 01:36:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-16 14:08:52 +00:00
|
|
|
// Stop stops a proxy node.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) Stop() error {
|
2021-01-22 01:36:18 +00:00
|
|
|
node.cancel()
|
|
|
|
|
2022-10-09 02:06:58 +00:00
|
|
|
if node.rowIDAllocator != nil {
|
|
|
|
node.rowIDAllocator.Close()
|
2021-12-13 02:01:18 +00:00
|
|
|
log.Info("close id allocator", zap.String("role", typeutil.ProxyRole))
|
2021-06-22 09:40:07 +00:00
|
|
|
}
|
2021-12-10 14:09:17 +00:00
|
|
|
|
2021-06-22 09:40:07 +00:00
|
|
|
if node.segAssigner != nil {
|
|
|
|
node.segAssigner.Close()
|
2021-12-13 02:01:18 +00:00
|
|
|
log.Info("close segment id assigner", zap.String("role", typeutil.ProxyRole))
|
2021-06-22 09:40:07 +00:00
|
|
|
}
|
2021-12-10 14:09:17 +00:00
|
|
|
|
2021-06-22 09:40:07 +00:00
|
|
|
if node.sched != nil {
|
|
|
|
node.sched.Close()
|
2021-12-13 02:01:18 +00:00
|
|
|
log.Info("close scheduler", zap.String("role", typeutil.ProxyRole))
|
2021-06-22 09:40:07 +00:00
|
|
|
}
|
2021-12-10 14:09:17 +00:00
|
|
|
|
2021-06-22 09:40:07 +00:00
|
|
|
if node.chTicker != nil {
|
|
|
|
err := node.chTicker.close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-12-13 02:01:18 +00:00
|
|
|
log.Info("close channels time ticker", zap.String("role", typeutil.ProxyRole))
|
2021-05-29 01:55:29 +00:00
|
|
|
}
|
2021-01-22 01:36:18 +00:00
|
|
|
|
|
|
|
node.wg.Wait()
|
|
|
|
|
|
|
|
for _, cb := range node.closeCallbacks {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
2023-04-12 12:12:28 +00:00
|
|
|
if node.session != nil {
|
|
|
|
node.session.Stop()
|
|
|
|
}
|
2021-11-16 14:31:14 +00:00
|
|
|
|
2022-06-02 04:16:03 +00:00
|
|
|
if node.shardMgr != nil {
|
|
|
|
node.shardMgr.Close()
|
|
|
|
}
|
|
|
|
|
2022-09-27 11:18:54 +00:00
|
|
|
if node.chMgr != nil {
|
2022-10-18 11:17:27 +00:00
|
|
|
node.chMgr.removeAllDMLStream()
|
2022-09-27 11:18:54 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 10:38:39 +00:00
|
|
|
if node.lbPolicy != nil {
|
|
|
|
node.lbPolicy.Close()
|
|
|
|
}
|
|
|
|
|
2021-11-26 03:39:16 +00:00
|
|
|
// https://github.com/milvus-io/milvus/issues/12282
|
2022-10-10 07:55:22 +00:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2021-11-26 03:39:16 +00:00
|
|
|
|
2023-05-19 04:51:23 +00:00
|
|
|
GetConnectionManager().stop()
|
|
|
|
|
2021-01-22 01:36:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddStartCallback adds a callback in the startServer phase.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) AddStartCallback(callbacks ...func()) {
|
2021-01-22 01:36:18 +00:00
|
|
|
node.startCallbacks = append(node.startCallbacks, callbacks...)
|
|
|
|
}
|
|
|
|
|
2022-01-10 14:39:54 +00:00
|
|
|
// lastTick returns the last write timestamp of all pchans in this Proxy.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) lastTick() Timestamp {
|
2021-09-26 11:23:56 +00:00
|
|
|
return node.chTicker.getMinTick()
|
2021-01-22 01:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddCloseCallback adds a callback in the Close phase.
|
2021-06-22 06:40:07 +00:00
|
|
|
func (node *Proxy) AddCloseCallback(callbacks ...func()) {
|
2021-01-22 01:36:18 +00:00
|
|
|
node.closeCallbacks = append(node.closeCallbacks, callbacks...)
|
|
|
|
}
|
2021-01-29 01:27:26 +00:00
|
|
|
|
2022-11-04 06:25:38 +00:00
|
|
|
func (node *Proxy) SetAddress(address string) {
|
|
|
|
node.address = address
|
|
|
|
}
|
|
|
|
|
2023-01-12 11:49:40 +00:00
|
|
|
func (node *Proxy) GetAddress() string {
|
|
|
|
return node.address
|
|
|
|
}
|
|
|
|
|
2021-12-29 06:35:21 +00:00
|
|
|
// SetEtcdClient sets etcd client for proxy.
|
|
|
|
func (node *Proxy) SetEtcdClient(client *clientv3.Client) {
|
|
|
|
node.etcdCli = client
|
|
|
|
}
|
|
|
|
|
2021-12-23 07:01:53 +00:00
|
|
|
// SetRootCoordClient sets RootCoord client for proxy.
|
2023-09-26 01:57:25 +00:00
|
|
|
func (node *Proxy) SetRootCoordClient(cli types.RootCoordClient) {
|
2021-06-21 09:28:03 +00:00
|
|
|
node.rootCoord = cli
|
2021-01-29 01:27:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 11:15:48 +00:00
|
|
|
// SetDataCoordClient sets DataCoord client for proxy.
|
2023-09-26 01:57:25 +00:00
|
|
|
func (node *Proxy) SetDataCoordClient(cli types.DataCoordClient) {
|
2021-06-21 10:22:13 +00:00
|
|
|
node.dataCoord = cli
|
2021-01-29 01:27:26 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 11:15:48 +00:00
|
|
|
// SetQueryCoordClient sets QueryCoord client for proxy.
|
2023-09-26 01:57:25 +00:00
|
|
|
func (node *Proxy) SetQueryCoordClient(cli types.QueryCoordClient) {
|
2021-06-22 08:44:09 +00:00
|
|
|
node.queryCoord = cli
|
2021-01-29 01:27:26 +00:00
|
|
|
}
|
2022-09-16 01:56:47 +00:00
|
|
|
|
2023-09-26 01:57:25 +00:00
|
|
|
func (node *Proxy) SetQueryNodeCreator(f func(ctx context.Context, addr string, nodeID int64) (types.QueryNodeClient, error)) {
|
2023-06-13 02:20:37 +00:00
|
|
|
node.shardMgr.SetClientCreatorFunc(f)
|
2023-01-12 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 01:56:47 +00:00
|
|
|
// GetRateLimiter returns the rateLimiter in Proxy.
|
|
|
|
func (node *Proxy) GetRateLimiter() (types.Limiter, error) {
|
|
|
|
if node.multiRateLimiter == nil {
|
|
|
|
return nil, fmt.Errorf("nil rate limiter in Proxy")
|
|
|
|
}
|
|
|
|
return node.multiRateLimiter, nil
|
|
|
|
}
|