2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-09 16:27:11 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-03-05 09:21:35 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/log"
|
2021-01-16 10:12:14 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/msgstream"
|
2021-03-12 14:22:09 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
2020-11-09 16:27:11 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/util/flowgraph"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dataSyncService struct {
|
2021-03-22 16:36:10 +08:00
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
|
|
|
|
collectionID UniqueID
|
|
|
|
fg *flowgraph.TimeTickedFlowGraph
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2021-02-08 14:30:54 +08:00
|
|
|
dmStream msgstream.MsgStream
|
|
|
|
msFactory msgstream.Factory
|
2021-01-16 10:12:14 +08:00
|
|
|
|
2021-03-05 16:52:45 +08:00
|
|
|
replica ReplicaInterface
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
func newDataSyncService(ctx context.Context, replica ReplicaInterface, factory msgstream.Factory, collectionID UniqueID) *dataSyncService {
|
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
|
|
|
|
2021-01-26 09:38:40 +08:00
|
|
|
service := &dataSyncService{
|
2021-03-22 16:36:10 +08:00
|
|
|
ctx: ctx1,
|
|
|
|
cancel: cancel,
|
|
|
|
collectionID: collectionID,
|
|
|
|
fg: nil,
|
|
|
|
replica: replica,
|
|
|
|
msFactory: factory,
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
2021-01-26 09:38:40 +08:00
|
|
|
|
|
|
|
service.initNodes()
|
|
|
|
return service
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dsService *dataSyncService) start() {
|
|
|
|
dsService.fg.Start()
|
|
|
|
}
|
|
|
|
|
2020-11-12 12:04:12 +08:00
|
|
|
func (dsService *dataSyncService) close() {
|
2021-03-22 16:36:10 +08:00
|
|
|
dsService.cancel()
|
2020-11-24 16:12:39 +08:00
|
|
|
if dsService.fg != nil {
|
|
|
|
dsService.fg.Close()
|
|
|
|
}
|
2020-11-12 12:04:12 +08:00
|
|
|
}
|
|
|
|
|
2020-11-09 16:27:11 +08:00
|
|
|
func (dsService *dataSyncService) initNodes() {
|
|
|
|
// TODO: add delete pipeline support
|
|
|
|
|
|
|
|
dsService.fg = flowgraph.NewTimeTickedFlowGraph(dsService.ctx)
|
|
|
|
|
2021-01-16 10:12:14 +08:00
|
|
|
var dmStreamNode node = dsService.newDmInputNode(dsService.ctx)
|
2020-12-10 16:31:09 +08:00
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
var filterDmNode node = newFilteredDmNode(dsService.replica, dsService.collectionID)
|
2020-12-10 16:31:09 +08:00
|
|
|
|
2021-03-22 16:36:10 +08:00
|
|
|
var insertNode node = newInsertNode(dsService.replica, dsService.collectionID)
|
|
|
|
var serviceTimeNode node = newServiceTimeNode(dsService.ctx, dsService.replica, dsService.msFactory, dsService.collectionID)
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(dmStreamNode)
|
2020-12-10 16:31:09 +08:00
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(filterDmNode)
|
2020-12-10 16:31:09 +08:00
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(insertNode)
|
|
|
|
dsService.fg.AddNode(serviceTimeNode)
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
// dmStreamNode
|
2020-11-09 16:27:11 +08:00
|
|
|
var err = dsService.fg.SetEdges(dmStreamNode.Name(),
|
|
|
|
[]string{},
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("set edges failed in node:", zap.String("node name", dmStreamNode.Name()))
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
// filterDmNode
|
2020-11-09 16:27:11 +08:00
|
|
|
err = dsService.fg.SetEdges(filterDmNode.Name(),
|
2021-03-03 16:06:02 +08:00
|
|
|
[]string{dmStreamNode.Name()},
|
2020-11-09 16:27:11 +08:00
|
|
|
[]string{insertNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("set edges failed in node:", zap.String("node name", filterDmNode.Name()))
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
// insertNode
|
2020-11-09 16:27:11 +08:00
|
|
|
err = dsService.fg.SetEdges(insertNode.Name(),
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
[]string{serviceTimeNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("set edges failed in node:", zap.String("node name", insertNode.Name()))
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-12-10 16:31:09 +08:00
|
|
|
// serviceTimeNode
|
2020-11-09 16:27:11 +08:00
|
|
|
err = dsService.fg.SetEdges(serviceTimeNode.Name(),
|
|
|
|
[]string{insertNode.Name()},
|
2021-03-03 16:06:02 +08:00
|
|
|
[]string{},
|
2020-11-09 16:27:11 +08:00
|
|
|
)
|
|
|
|
if err != nil {
|
2021-03-05 09:21:35 +08:00
|
|
|
log.Error("set edges failed in node:", zap.String("node name", serviceTimeNode.Name()))
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
}
|
2021-03-04 14:49:51 +08:00
|
|
|
|
2021-03-12 14:22:09 +08:00
|
|
|
func (dsService *dataSyncService) seekSegment(position *internalpb.MsgPosition) error {
|
2021-03-04 14:49:51 +08:00
|
|
|
err := dsService.dmStream.Seek(position)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|