2020-11-09 08:27:11 +00:00
|
|
|
package flowgraph
|
|
|
|
|
|
|
|
import (
|
2021-01-11 10:35:54 +00:00
|
|
|
"fmt"
|
2020-11-12 04:04:12 +00:00
|
|
|
"log"
|
2020-11-12 09:58:05 +00:00
|
|
|
|
2021-01-16 07:06:19 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
2021-01-11 10:35:54 +00:00
|
|
|
|
2021-01-16 07:06:19 +00:00
|
|
|
"github.com/opentracing/opentracing-go"
|
2020-11-12 09:58:05 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
2020-11-09 08:27:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type InputNode struct {
|
|
|
|
BaseNode
|
|
|
|
inStream *msgstream.MsgStream
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (inNode *InputNode) IsInputNode() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (inNode *InputNode) Name() string {
|
|
|
|
return inNode.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (inNode *InputNode) InStream() *msgstream.MsgStream {
|
|
|
|
return inNode.inStream
|
|
|
|
}
|
|
|
|
|
|
|
|
// empty input and return one *Msg
|
2021-01-11 10:35:54 +00:00
|
|
|
func (inNode *InputNode) Operate([]*Msg) []*Msg {
|
2020-11-12 04:04:12 +00:00
|
|
|
//fmt.Println("Do InputNode operation")
|
2021-01-06 03:17:35 +00:00
|
|
|
|
2021-01-06 08:44:12 +00:00
|
|
|
msgPack := (*inNode.inStream).Consume()
|
2021-01-06 06:45:50 +00:00
|
|
|
|
2021-01-11 10:35:54 +00:00
|
|
|
var childs []opentracing.Span
|
|
|
|
tracer := opentracing.GlobalTracer()
|
|
|
|
if tracer != nil && msgPack != nil {
|
|
|
|
for _, msg := range msgPack.Msgs {
|
2021-01-16 07:06:19 +00:00
|
|
|
if msg.Type() == commonpb.MsgType_kInsert {
|
2021-01-11 10:35:54 +00:00
|
|
|
var child opentracing.Span
|
|
|
|
ctx := msg.GetMsgContext()
|
|
|
|
if parent := opentracing.SpanFromContext(ctx); parent != nil {
|
|
|
|
child = tracer.StartSpan(fmt.Sprintf("through msg input node, start time = %d", msg.BeginTs()),
|
|
|
|
opentracing.FollowsFrom(parent.Context()))
|
|
|
|
} else {
|
|
|
|
child = tracer.StartSpan(fmt.Sprintf("through msg input node, start time = %d", msg.BeginTs()))
|
|
|
|
}
|
|
|
|
child.SetTag("hash keys", msg.HashKeys())
|
|
|
|
child.SetTag("start time", msg.BeginTs())
|
|
|
|
child.SetTag("end time", msg.EndTs())
|
|
|
|
msg.SetMsgContext(opentracing.ContextWithSpan(ctx, child))
|
|
|
|
childs = append(childs, child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 04:04:12 +00:00
|
|
|
// TODO: add status
|
|
|
|
if msgPack == nil {
|
|
|
|
log.Println("null msg pack")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-09 08:27:11 +00:00
|
|
|
var msgStreamMsg Msg = &MsgStreamMsg{
|
|
|
|
tsMessages: msgPack.Msgs,
|
|
|
|
timestampMin: msgPack.BeginTs,
|
|
|
|
timestampMax: msgPack.EndTs,
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:35:54 +00:00
|
|
|
for _, child := range childs {
|
|
|
|
child.Finish()
|
|
|
|
}
|
|
|
|
|
2020-11-09 08:27:11 +00:00
|
|
|
return []*Msg{&msgStreamMsg}
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:46:17 +00:00
|
|
|
func NewInputNode(inStream *msgstream.MsgStream, nodeName string, maxQueueLength int32, maxParallelism int32) *InputNode {
|
2020-11-09 08:27:11 +00:00
|
|
|
baseNode := BaseNode{}
|
2020-11-18 09:32:52 +00:00
|
|
|
baseNode.SetMaxQueueLength(maxQueueLength)
|
|
|
|
baseNode.SetMaxParallelism(maxParallelism)
|
2020-11-09 08:27:11 +00:00
|
|
|
|
|
|
|
return &InputNode{
|
|
|
|
BaseNode: baseNode,
|
|
|
|
inStream: inStream,
|
|
|
|
name: nodeName,
|
|
|
|
}
|
|
|
|
}
|