2021-04-19 13:47:10 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// 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-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-02 19:30:12 +08:00
|
|
|
|
2020-11-05 10:52:50 +08:00
|
|
|
import (
|
2021-01-21 15:20:23 +08:00
|
|
|
"context"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
2021-03-25 14:41:46 +08:00
|
|
|
"go.uber.org/zap"
|
2020-11-05 10:52:50 +08:00
|
|
|
)
|
2020-11-04 16:28:14 +08:00
|
|
|
|
2020-11-02 19:30:12 +08:00
|
|
|
type serviceTimeNode struct {
|
2021-01-15 15:28:54 +08:00
|
|
|
baseNode
|
2021-03-22 16:36:10 +08:00
|
|
|
collectionID UniqueID
|
2021-03-05 16:52:45 +08:00
|
|
|
replica ReplicaInterface
|
2021-02-04 14:37:12 +08:00
|
|
|
timeTickMsgStream msgstream.MsgStream
|
2020-11-02 19:30:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (stNode *serviceTimeNode) Name() string {
|
2020-11-05 10:52:50 +08:00
|
|
|
return "stNode"
|
2020-11-02 19:30:12 +08:00
|
|
|
}
|
|
|
|
|
2021-03-26 18:40:04 +08:00
|
|
|
func (stNode *serviceTimeNode) Close() {
|
|
|
|
stNode.timeTickMsgStream.Close()
|
|
|
|
}
|
|
|
|
|
2021-03-25 14:41:46 +08:00
|
|
|
func (stNode *serviceTimeNode) Operate(in []flowgraph.Msg) []flowgraph.Msg {
|
2021-03-05 09:21:35 +08:00
|
|
|
//log.Debug("Do serviceTimeNode operation")
|
2020-11-05 10:52:50 +08:00
|
|
|
|
2020-11-04 16:28:14 +08:00
|
|
|
if len(in) != 1 {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("Invalid operate message input in serviceTimeNode, input length = ", zap.Int("input node", len(in)))
|
2020-11-04 16:28:14 +08:00
|
|
|
// TODO: add error handling
|
|
|
|
}
|
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
serviceTimeMsg, ok := in[0].(*serviceTimeMsg)
|
2020-11-04 16:28:14 +08:00
|
|
|
if !ok {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("type assertion failed for serviceTimeMsg")
|
2020-11-04 16:28:14 +08:00
|
|
|
// TODO: add error handling
|
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
if serviceTimeMsg == nil {
|
2021-03-25 14:41:46 +08:00
|
|
|
return []Msg{}
|
2021-03-22 16:36:10 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
// update service time
|
2021-03-22 16:36:10 +08:00
|
|
|
ts := stNode.replica.getTSafe(stNode.collectionID)
|
|
|
|
if ts != nil {
|
|
|
|
ts.set(serviceTimeMsg.timeRange.timestampMax)
|
2021-03-23 01:49:50 +08:00
|
|
|
//log.Debug("update tSafe:",
|
|
|
|
// zap.Int64("tSafe", int64(serviceTimeMsg.timeRange.timestampMax)),
|
|
|
|
// zap.Int64("collectionID", stNode.collectionID))
|
2021-03-22 16:36:10 +08:00
|
|
|
}
|
2021-01-06 16:44:12 +08:00
|
|
|
|
2021-01-21 15:20:23 +08:00
|
|
|
if err := stNode.sendTimeTick(serviceTimeMsg.timeRange.timestampMax); err != nil {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("Error: send time tick into pulsar channel failed", zap.Error(err))
|
2021-01-21 15:20:23 +08:00
|
|
|
}
|
|
|
|
|
2021-01-06 16:44:12 +08:00
|
|
|
var res Msg = &gcMsg{
|
|
|
|
gcRecord: serviceTimeMsg.gcRecord,
|
|
|
|
timeRange: serviceTimeMsg.timeRange,
|
|
|
|
}
|
2021-03-25 14:41:46 +08:00
|
|
|
return []Msg{res}
|
2020-11-02 19:30:12 +08:00
|
|
|
}
|
|
|
|
|
2021-01-21 15:20:23 +08:00
|
|
|
func (stNode *serviceTimeNode) sendTimeTick(ts Timestamp) error {
|
|
|
|
msgPack := msgstream.MsgPack{}
|
|
|
|
timeTickMsg := msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: ts,
|
|
|
|
EndTimestamp: ts,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
},
|
2021-03-12 14:22:09 +08:00
|
|
|
TimeTickMsg: internalpb.TimeTickMsg{
|
2021-01-21 15:20:23 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2021-03-10 14:45:35 +08:00
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-01-21 15:20:23 +08:00
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: ts,
|
|
|
|
SourceID: Params.QueryNodeID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msgPack.Msgs = append(msgPack.Msgs, &timeTickMsg)
|
2021-03-25 14:41:46 +08:00
|
|
|
return stNode.timeTickMsgStream.Produce(&msgPack)
|
2021-01-21 15:20:23 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
func newServiceTimeNode(ctx context.Context, replica ReplicaInterface, factory msgstream.Factory, collectionID UniqueID) *serviceTimeNode {
|
2020-12-10 16:31:09 +08:00
|
|
|
maxQueueLength := Params.FlowGraphMaxQueueLength
|
|
|
|
maxParallelism := Params.FlowGraphMaxParallelism
|
2020-11-18 17:32:52 +08:00
|
|
|
|
2021-01-15 15:28:54 +08:00
|
|
|
baseNode := baseNode{}
|
2020-11-02 19:30:12 +08:00
|
|
|
baseNode.SetMaxQueueLength(maxQueueLength)
|
|
|
|
baseNode.SetMaxParallelism(maxParallelism)
|
|
|
|
|
2021-02-04 14:37:12 +08:00
|
|
|
timeTimeMsgStream, _ := factory.NewMsgStream(ctx)
|
|
|
|
timeTimeMsgStream.AsProducer([]string{Params.QueryTimeTickChannelName})
|
2021-03-05 18:16:50 +08:00
|
|
|
log.Debug("querynode AsProducer: " + Params.QueryTimeTickChannelName)
|
2021-01-21 15:20:23 +08:00
|
|
|
|
2020-11-02 19:30:12 +08:00
|
|
|
return &serviceTimeNode{
|
2021-01-21 15:20:23 +08:00
|
|
|
baseNode: baseNode,
|
2021-03-22 16:36:10 +08:00
|
|
|
collectionID: collectionID,
|
2021-01-21 15:20:23 +08:00
|
|
|
replica: replica,
|
|
|
|
timeTickMsgStream: timeTimeMsgStream,
|
2020-11-02 19:30:12 +08:00
|
|
|
}
|
|
|
|
}
|