flow_graph_dmstream_input_node.go 3.0 KB
Newer Older
1 2 3 4 5 6
// 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
X
XuanYang-cn 已提交
7 8
// with the License. You may obtain a copy of the License at
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
X
XuanYang-cn 已提交
10
//
11 12 13 14 15
// 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.
X
XuanYang-cn 已提交
16

X
XuanYang-cn 已提交
17 18 19 20
package datanode

import (
	"context"
C
congqixia 已提交
21
	"fmt"
X
Xiaofan 已提交
22
	"time"
X
XuanYang-cn 已提交
23

X
Xiangyu Wang 已提交
24
	"github.com/milvus-io/milvus/internal/log"
X
XuanYang-cn 已提交
25
	"github.com/milvus-io/milvus/internal/proto/internalpb"
26
	"github.com/milvus-io/milvus/internal/rootcoord"
X
Xiangyu Wang 已提交
27
	"github.com/milvus-io/milvus/internal/util/flowgraph"
C
congqixia 已提交
28
	"go.uber.org/zap"
X
XuanYang-cn 已提交
29 30
)

31 32 33
// DmInputNode receives messages from message streams, packs messages between two timeticks, and passes all
//  messages between two timeticks to the following flowgraph node. In DataNode, the following flow graph node is
//  flowgraph ddNode.
X
XuanYang-cn 已提交
34
func newDmInputNode(ctx context.Context, seekPos *internalpb.MsgPosition, dmNodeConfig *nodeConfig) (*flowgraph.InputNode, error) {
35
	// subName should be unique, since pchannelName is shared among several collections
C
congqixia 已提交
36
	//	consumeSubName := Params.MsgChannelSubName + "-" + strconv.FormatInt(collID, 10)
37
	consumeSubName := fmt.Sprintf("%s-%d-%d", Params.MsgChannelCfg.DataNodeSubName, Params.DataNodeCfg.NodeID, dmNodeConfig.collectionID)
X
XuanYang-cn 已提交
38
	insertStream, err := dmNodeConfig.msFactory.NewTtMsgStream(ctx)
39 40 41
	if err != nil {
		return nil, err
	}
X
XuanYang-cn 已提交
42

43 44
	// MsgStream needs a physical channel name, but the channel name in seek position from DataCoord
	//  is virtual channel name, so we need to convert vchannel name into pchannel neme here.
X
XuanYang-cn 已提交
45
	pchannelName := rootcoord.ToPhysicalChannel(dmNodeConfig.vChannelName)
46
	insertStream.AsConsumer([]string{pchannelName}, consumeSubName)
47
	log.Debug("datanode AsConsumer", zap.String("physical channel", pchannelName), zap.String("subName", consumeSubName), zap.Int64("collection ID", dmNodeConfig.collectionID))
S
sunby 已提交
48 49

	if seekPos != nil {
50
		seekPos.ChannelName = pchannelName
X
Xiaofan 已提交
51
		start := time.Now()
52
		log.Debug("datanode begin to seek", zap.String("physical channel", seekPos.GetChannelName()), zap.Int64("collection ID", dmNodeConfig.collectionID))
53 54 55 56
		err = insertStream.Seek([]*internalpb.MsgPosition{seekPos})
		if err != nil {
			return nil, err
		}
57
		log.Debug("datanode seek successfully", zap.String("physical channel", seekPos.GetChannelName()), zap.Int64("collection ID", dmNodeConfig.collectionID), zap.Duration("elapse", time.Since(start)))
S
sunby 已提交
58
	}
X
XuanYang-cn 已提交
59

60 61
	name := fmt.Sprintf("dmInputNode-%d-%s", dmNodeConfig.collectionID, dmNodeConfig.vChannelName)
	node := flowgraph.NewInputNode(insertStream, name, dmNodeConfig.maxQueueLength, dmNodeConfig.maxParallelism)
62
	return node, nil
X
XuanYang-cn 已提交
63
}