2021-06-09 11:37:55 +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.
|
|
|
|
|
|
|
|
package querynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
|
|
|
)
|
|
|
|
|
2021-09-27 19:06:07 +08:00
|
|
|
// queryNodeFlowGraph is a TimeTickedFlowGraph in query node
|
2021-06-09 11:37:55 +08:00
|
|
|
type queryNodeFlowGraph struct {
|
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
collectionID UniqueID
|
|
|
|
partitionID UniqueID
|
2021-06-15 20:06:10 +08:00
|
|
|
channel Channel
|
2021-06-09 11:37:55 +08:00
|
|
|
flowGraph *flowgraph.TimeTickedFlowGraph
|
|
|
|
dmlStream msgstream.MsgStream
|
|
|
|
}
|
|
|
|
|
|
|
|
func newQueryNodeFlowGraph(ctx context.Context,
|
2021-06-19 18:38:07 +08:00
|
|
|
loadType loadType,
|
2021-06-09 11:37:55 +08:00
|
|
|
collectionID UniqueID,
|
|
|
|
partitionID UniqueID,
|
|
|
|
streamingReplica ReplicaInterface,
|
2021-10-26 14:46:19 +08:00
|
|
|
historicalReplica ReplicaInterface,
|
2021-06-09 11:37:55 +08:00
|
|
|
tSafeReplica TSafeReplicaInterface,
|
2021-06-15 20:06:10 +08:00
|
|
|
channel Channel,
|
2021-06-09 11:37:55 +08:00
|
|
|
factory msgstream.Factory) *queryNodeFlowGraph {
|
|
|
|
|
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
|
|
|
|
|
|
q := &queryNodeFlowGraph{
|
|
|
|
ctx: ctx1,
|
|
|
|
cancel: cancel,
|
|
|
|
collectionID: collectionID,
|
|
|
|
partitionID: partitionID,
|
|
|
|
channel: channel,
|
|
|
|
flowGraph: flowgraph.NewTimeTickedFlowGraph(ctx1),
|
|
|
|
}
|
|
|
|
|
|
|
|
var dmStreamNode node = q.newDmInputNode(ctx1, factory)
|
2021-06-19 18:38:07 +08:00
|
|
|
var filterDmNode node = newFilteredDmNode(streamingReplica, loadType, collectionID, partitionID)
|
2021-10-26 14:46:19 +08:00
|
|
|
var insertNode node = newInsertNode(streamingReplica, historicalReplica)
|
2021-06-19 18:38:07 +08:00
|
|
|
var serviceTimeNode node = newServiceTimeNode(ctx1, tSafeReplica, loadType, collectionID, partitionID, channel, factory)
|
2021-06-09 11:37:55 +08:00
|
|
|
|
|
|
|
q.flowGraph.AddNode(dmStreamNode)
|
|
|
|
q.flowGraph.AddNode(filterDmNode)
|
|
|
|
q.flowGraph.AddNode(insertNode)
|
|
|
|
q.flowGraph.AddNode(serviceTimeNode)
|
|
|
|
|
|
|
|
// dmStreamNode
|
|
|
|
var err = q.flowGraph.SetEdges(dmStreamNode.Name(),
|
|
|
|
[]string{},
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", dmStreamNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// filterDmNode
|
|
|
|
err = q.flowGraph.SetEdges(filterDmNode.Name(),
|
|
|
|
[]string{dmStreamNode.Name()},
|
|
|
|
[]string{insertNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", filterDmNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// insertNode
|
|
|
|
err = q.flowGraph.SetEdges(insertNode.Name(),
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
[]string{serviceTimeNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", insertNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// serviceTimeNode
|
|
|
|
err = q.flowGraph.SetEdges(serviceTimeNode.Name(),
|
|
|
|
[]string{insertNode.Name()},
|
|
|
|
[]string{},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", serviceTimeNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *queryNodeFlowGraph) newDmInputNode(ctx context.Context, factory msgstream.Factory) *flowgraph.InputNode {
|
|
|
|
insertStream, err := factory.NewTtMsgStream(ctx)
|
|
|
|
if err != nil {
|
2021-07-31 10:47:22 +08:00
|
|
|
log.Warn(err.Error())
|
2021-06-09 11:37:55 +08:00
|
|
|
} else {
|
|
|
|
q.dmlStream = insertStream
|
|
|
|
}
|
|
|
|
|
|
|
|
maxQueueLength := Params.FlowGraphMaxQueueLength
|
|
|
|
maxParallelism := Params.FlowGraphMaxParallelism
|
|
|
|
|
2021-09-29 20:19:59 +08:00
|
|
|
node := flowgraph.NewInputNode(insertStream, "dmlInputNode", maxQueueLength, maxParallelism)
|
2021-06-09 11:37:55 +08:00
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
2021-06-15 20:06:10 +08:00
|
|
|
func (q *queryNodeFlowGraph) consumerFlowGraph(channel Channel, subName ConsumeSubName) error {
|
2021-06-09 11:37:55 +08:00
|
|
|
if q.dmlStream == nil {
|
|
|
|
return errors.New("null dml message stream in flow graph")
|
|
|
|
}
|
|
|
|
q.dmlStream.AsConsumer([]string{channel}, subName)
|
2021-06-15 20:06:10 +08:00
|
|
|
log.Debug("query node flow graph consumes from pChannel",
|
|
|
|
zap.Any("collectionID", q.collectionID),
|
|
|
|
zap.Any("channel", channel),
|
2021-09-18 09:13:50 +08:00
|
|
|
zap.Any("subName", subName),
|
2021-06-15 20:06:10 +08:00
|
|
|
)
|
2021-06-09 11:37:55 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *queryNodeFlowGraph) seekQueryNodeFlowGraph(position *internalpb.MsgPosition) error {
|
2021-06-10 14:32:51 +08:00
|
|
|
q.dmlStream.AsConsumer([]string{position.ChannelName}, position.MsgGroup)
|
2021-06-09 11:37:55 +08:00
|
|
|
err := q.dmlStream.Seek([]*internalpb.MsgPosition{position})
|
2021-06-15 20:06:10 +08:00
|
|
|
log.Debug("query node flow graph seeks from pChannel",
|
|
|
|
zap.Any("collectionID", q.collectionID),
|
|
|
|
zap.Any("channel", position.ChannelName),
|
|
|
|
)
|
2021-06-09 11:37:55 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *queryNodeFlowGraph) close() {
|
|
|
|
q.cancel()
|
|
|
|
q.flowGraph.Close()
|
|
|
|
log.Debug("stop query node flow graph",
|
|
|
|
zap.Any("collectionID", q.collectionID),
|
|
|
|
zap.Any("partitionID", q.partitionID),
|
|
|
|
zap.Any("channel", q.channel),
|
|
|
|
)
|
|
|
|
}
|