2021-12-01 22:28:08 +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-06-09 11:37:55 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-12-01 22:28:08 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-06-09 11:37:55 +08:00
|
|
|
//
|
2021-12-01 22:28:08 +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-06-09 11:37:55 +08:00
|
|
|
|
|
|
|
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-11-21 07:33:14 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/mqclient"
|
2021-06-09 11:37:55 +08:00
|
|
|
)
|
|
|
|
|
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
|
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,
|
|
|
|
collectionID UniqueID,
|
|
|
|
streamingReplica ReplicaInterface,
|
|
|
|
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,
|
|
|
|
channel: channel,
|
|
|
|
flowGraph: flowgraph.NewTimeTickedFlowGraph(ctx1),
|
|
|
|
}
|
|
|
|
|
|
|
|
var dmStreamNode node = q.newDmInputNode(ctx1, factory)
|
2021-12-17 20:12:42 +08:00
|
|
|
var filterDmNode node = newFilteredDmNode(streamingReplica, collectionID)
|
2021-11-09 09:27:04 +08:00
|
|
|
var insertNode node = newInsertNode(streamingReplica)
|
2021-12-17 20:12:42 +08:00
|
|
|
var serviceTimeNode node = newServiceTimeNode(ctx1, tSafeReplica, collectionID, 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
|
|
|
|
}
|
|
|
|
|
2021-11-06 11:02:58 +08:00
|
|
|
func newQueryNodeDeltaFlowGraph(ctx context.Context,
|
|
|
|
collectionID UniqueID,
|
|
|
|
historicalReplica ReplicaInterface,
|
|
|
|
tSafeReplica TSafeReplicaInterface,
|
|
|
|
channel Channel,
|
|
|
|
factory msgstream.Factory) *queryNodeFlowGraph {
|
|
|
|
|
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
|
|
|
|
|
|
q := &queryNodeFlowGraph{
|
|
|
|
ctx: ctx1,
|
|
|
|
cancel: cancel,
|
|
|
|
collectionID: collectionID,
|
|
|
|
channel: channel,
|
|
|
|
flowGraph: flowgraph.NewTimeTickedFlowGraph(ctx1),
|
|
|
|
}
|
|
|
|
|
|
|
|
var dmStreamNode node = q.newDmInputNode(ctx1, factory)
|
2021-12-17 20:12:42 +08:00
|
|
|
var filterDeleteNode node = newFilteredDeleteNode(historicalReplica, collectionID)
|
2021-11-06 11:02:58 +08:00
|
|
|
var deleteNode node = newDeleteNode(historicalReplica)
|
2021-12-17 20:12:42 +08:00
|
|
|
var serviceTimeNode node = newServiceTimeNode(ctx1, tSafeReplica, collectionID, channel, factory)
|
2021-11-06 11:02:58 +08:00
|
|
|
|
|
|
|
q.flowGraph.AddNode(dmStreamNode)
|
|
|
|
q.flowGraph.AddNode(filterDeleteNode)
|
|
|
|
q.flowGraph.AddNode(deleteNode)
|
|
|
|
q.flowGraph.AddNode(serviceTimeNode)
|
|
|
|
|
|
|
|
// dmStreamNode
|
|
|
|
var err = q.flowGraph.SetEdges(dmStreamNode.Name(),
|
|
|
|
[]string{},
|
|
|
|
[]string{filterDeleteNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", dmStreamNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// filterDmNode
|
|
|
|
err = q.flowGraph.SetEdges(filterDeleteNode.Name(),
|
|
|
|
[]string{dmStreamNode.Name()},
|
|
|
|
[]string{deleteNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", filterDeleteNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// insertNode
|
|
|
|
err = q.flowGraph.SetEdges(deleteNode.Name(),
|
|
|
|
[]string{filterDeleteNode.Name()},
|
|
|
|
[]string{serviceTimeNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", deleteNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// serviceTimeNode
|
|
|
|
err = q.flowGraph.SetEdges(serviceTimeNode.Name(),
|
|
|
|
[]string{deleteNode.Name()},
|
|
|
|
[]string{},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node:", zap.String("node name", serviceTimeNode.Name()))
|
|
|
|
}
|
|
|
|
|
|
|
|
return q
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:37:55 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-11-21 07:33:14 +08:00
|
|
|
func (q *queryNodeFlowGraph) consumerFlowGraphLatest(channel Channel, subName ConsumeSubName) error {
|
|
|
|
if q.dmlStream == nil {
|
|
|
|
return errors.New("null dml message stream in flow graph")
|
|
|
|
}
|
|
|
|
q.dmlStream.AsConsumerWithPosition([]string{channel}, subName, mqclient.SubscriptionPositionLatest)
|
|
|
|
log.Debug("query node flow graph consumes from pChannel",
|
|
|
|
zap.Any("collectionID", q.collectionID),
|
|
|
|
zap.Any("channel", channel),
|
|
|
|
zap.Any("subName", subName),
|
|
|
|
)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:37:55 +08:00
|
|
|
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("channel", q.channel),
|
|
|
|
)
|
|
|
|
}
|