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-06-09 11:37:55 +08:00
|
|
|
|
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/util/flowgraph"
|
2021-11-23 22:57:17 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/tsoutil"
|
|
|
|
"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-06-19 18:38:07 +08:00
|
|
|
loadType loadType
|
2021-06-15 12:41:40 +08:00
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
2021-06-15 20:06:10 +08:00
|
|
|
vChannel Channel
|
2021-06-15 12:41:40 +08:00
|
|
|
tSafeReplica TSafeReplicaInterface
|
|
|
|
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() {
|
2021-08-12 14:16:08 +08:00
|
|
|
// `Close` needs to be invoked to close producers
|
|
|
|
stNode.timeTickMsgStream.Close()
|
2021-03-26 18:40:04 +08:00
|
|
|
}
|
|
|
|
|
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-07-23 20:09:33 +08:00
|
|
|
log.Warn("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-06-15 12:41:40 +08:00
|
|
|
var id UniqueID
|
2021-06-19 18:38:07 +08:00
|
|
|
if stNode.loadType == loadTypePartition {
|
2021-06-15 12:41:40 +08:00
|
|
|
id = stNode.partitionID
|
|
|
|
} else {
|
|
|
|
id = stNode.collectionID
|
|
|
|
}
|
2021-09-24 13:57:54 +08:00
|
|
|
err := stNode.tSafeReplica.setTSafe(stNode.vChannel, id, serviceTimeMsg.timeRange.timestampMax)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn(err.Error())
|
|
|
|
}
|
2021-11-23 22:57:17 +08:00
|
|
|
p, _ := tsoutil.ParseTS(serviceTimeMsg.timeRange.timestampMax)
|
|
|
|
log.Debug("update tSafe:",
|
|
|
|
zap.Any("collectionID", stNode.collectionID),
|
|
|
|
zap.Any("tSafe", serviceTimeMsg.timeRange.timestampMax),
|
|
|
|
zap.Any("tSafe_p", p),
|
|
|
|
zap.Any("id", id),
|
|
|
|
zap.Any("channel", stNode.vChannel),
|
|
|
|
)
|
2021-01-06 16:44:12 +08:00
|
|
|
|
2021-06-09 11:37:55 +08:00
|
|
|
//if err := stNode.sendTimeTick(serviceTimeMsg.timeRange.timestampMax); err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
// log.Warn("Error: send time tick into pulsar channel failed", zap.Error(err))
|
2021-06-09 11:37:55 +08:00
|
|
|
//}
|
2021-01-21 15:20:23 +08:00
|
|
|
|
2021-09-08 17:10:15 +08:00
|
|
|
return []Msg{}
|
2020-11-02 19:30:12 +08:00
|
|
|
}
|
|
|
|
|
2021-06-09 11:37:55 +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},
|
|
|
|
// },
|
|
|
|
// TimeTickMsg: internalpb.TimeTickMsg{
|
|
|
|
// Base: &commonpb.MsgBase{
|
|
|
|
// MsgType: commonpb.MsgType_TimeTick,
|
|
|
|
// MsgID: 0,
|
|
|
|
// Timestamp: ts,
|
|
|
|
// SourceID: Params.QueryNodeID,
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// msgPack.Msgs = append(msgPack.Msgs, &timeTickMsg)
|
|
|
|
// return stNode.timeTickMsgStream.Produce(&msgPack)
|
|
|
|
//}
|
2021-01-21 15:20:23 +08:00
|
|
|
|
2021-05-28 15:40:32 +08:00
|
|
|
func newServiceTimeNode(ctx context.Context,
|
|
|
|
tSafeReplica TSafeReplicaInterface,
|
2021-06-19 18:38:07 +08:00
|
|
|
loadType loadType,
|
2021-06-09 11:37:55 +08:00
|
|
|
collectionID UniqueID,
|
2021-06-15 12:41:40 +08:00
|
|
|
partitionID UniqueID,
|
2021-06-15 20:06:10 +08:00
|
|
|
channel Channel,
|
2021-06-09 11:37:55 +08:00
|
|
|
factory msgstream.Factory) *serviceTimeNode {
|
2021-05-28 15:40:32 +08:00
|
|
|
|
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-06-15 12:41:40 +08:00
|
|
|
timeTimeMsgStream, err := factory.NewMsgStream(ctx)
|
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn(err.Error())
|
2021-06-15 12:41:40 +08:00
|
|
|
} else {
|
|
|
|
// TODO: use param table
|
|
|
|
timeTickChannel := "query-node-time-tick-0"
|
|
|
|
timeTimeMsgStream.AsProducer([]string{timeTickChannel})
|
|
|
|
log.Debug("query node AsProducer: " + timeTickChannel)
|
|
|
|
}
|
2021-01-21 15:20:23 +08:00
|
|
|
|
2020-11-02 19:30:12 +08:00
|
|
|
return &serviceTimeNode{
|
2021-06-15 12:41:40 +08:00
|
|
|
baseNode: baseNode,
|
2021-06-19 18:38:07 +08:00
|
|
|
loadType: loadType,
|
2021-06-15 12:41:40 +08:00
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
vChannel: channel,
|
|
|
|
tSafeReplica: tSafeReplica,
|
|
|
|
timeTickMsgStream: timeTimeMsgStream,
|
2020-11-02 19:30:12 +08:00
|
|
|
}
|
|
|
|
}
|