2021-04-19 15:16:33 +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.
|
|
|
|
|
2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/log"
|
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
2021-05-25 15:35:37 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
2021-02-26 10:13:36 +08:00
|
|
|
|
|
|
|
"go.uber.org/zap"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type dataSyncService struct {
|
2021-05-25 15:35:37 +08:00
|
|
|
ctx context.Context
|
|
|
|
fg *flowgraph.TimeTickedFlowGraph
|
|
|
|
flushChan <-chan *flushMsg
|
|
|
|
replica Replica
|
|
|
|
idAllocator allocatorInterface
|
|
|
|
msFactory msgstream.Factory
|
|
|
|
collectionID UniqueID
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
2021-05-25 15:35:37 +08:00
|
|
|
func newDataSyncService(ctx context.Context,
|
|
|
|
flushChan <-chan *flushMsg,
|
|
|
|
replica Replica,
|
|
|
|
alloc allocatorInterface,
|
|
|
|
factory msgstream.Factory,
|
|
|
|
vchanPair *datapb.VchannelPair) *dataSyncService {
|
|
|
|
|
2021-02-03 17:30:10 +08:00
|
|
|
service := &dataSyncService{
|
2021-05-25 15:35:37 +08:00
|
|
|
ctx: ctx,
|
|
|
|
fg: nil,
|
|
|
|
flushChan: flushChan,
|
|
|
|
replica: replica,
|
|
|
|
idAllocator: alloc,
|
|
|
|
msFactory: factory,
|
|
|
|
collectionID: vchanPair.GetCollectionID(),
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
2021-05-25 15:35:37 +08:00
|
|
|
|
|
|
|
service.initNodes(vchanPair)
|
2021-02-03 17:30:10 +08:00
|
|
|
return service
|
2021-02-03 15:18:05 +08:00
|
|
|
}
|
|
|
|
|
2021-02-03 17:30:10 +08:00
|
|
|
func (dsService *dataSyncService) start() {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Debug("Data Sync Service Start Successfully")
|
2021-05-08 14:07:04 +08:00
|
|
|
if dsService.fg != nil {
|
|
|
|
dsService.fg.Start()
|
|
|
|
} else {
|
|
|
|
log.Debug("Data Sync Service flowgraph nil")
|
|
|
|
}
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dsService *dataSyncService) close() {
|
|
|
|
if dsService.fg != nil {
|
|
|
|
dsService.fg.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:35:37 +08:00
|
|
|
func (dsService *dataSyncService) initNodes(vchanPair *datapb.VchannelPair) {
|
2021-01-19 11:37:16 +08:00
|
|
|
// TODO: add delete pipeline support
|
|
|
|
dsService.fg = flowgraph.NewTimeTickedFlowGraph(dsService.ctx)
|
|
|
|
|
2021-02-08 14:30:54 +08:00
|
|
|
m := map[string]interface{}{
|
|
|
|
"PulsarAddress": Params.PulsarAddress,
|
|
|
|
"ReceiveBufSize": 1024,
|
2021-05-25 15:35:37 +08:00
|
|
|
"PulsarBufSize": 1024,
|
|
|
|
}
|
|
|
|
|
2021-05-28 14:54:31 +08:00
|
|
|
err := dsService.msFactory.SetParams(m)
|
2021-02-08 14:30:54 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-05-25 15:35:37 +08:00
|
|
|
var dmStreamNode Node = newDmInputNode(dsService.ctx, dsService.msFactory, vchanPair.GetDmlVchannelName(), vchanPair.GetDmlPosition())
|
|
|
|
var ddStreamNode Node = newDDInputNode(dsService.ctx, dsService.msFactory, vchanPair.GetDdlVchannelName(), vchanPair.GetDdlPosition())
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
var filterDmNode Node = newFilteredDmNode()
|
2021-05-28 14:54:31 +08:00
|
|
|
var ddNode Node = newDDNode(dsService.ctx, dsService.flushChan, dsService.replica, dsService.idAllocator)
|
|
|
|
var insertBufferNode Node = newInsertBufferNode(dsService.ctx, dsService.replica, dsService.msFactory, dsService.idAllocator)
|
2021-01-19 11:37:16 +08:00
|
|
|
var gcNode Node = newGCNode(dsService.replica)
|
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(dmStreamNode)
|
|
|
|
dsService.fg.AddNode(ddStreamNode)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(filterDmNode)
|
|
|
|
dsService.fg.AddNode(ddNode)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(insertBufferNode)
|
|
|
|
dsService.fg.AddNode(gcNode)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
// dmStreamNode
|
2021-01-22 09:36:40 +08:00
|
|
|
err = dsService.fg.SetEdges(dmStreamNode.Name(),
|
2021-01-19 11:37:16 +08:00
|
|
|
[]string{},
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", dmStreamNode.Name()), zap.Error(err))
|
|
|
|
panic("set edges faild in the node")
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ddStreamNode
|
|
|
|
err = dsService.fg.SetEdges(ddStreamNode.Name(),
|
|
|
|
[]string{},
|
|
|
|
[]string{ddNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", ddStreamNode.Name()), zap.Error(err))
|
|
|
|
panic("set edges faild in the node")
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// filterDmNode
|
|
|
|
err = dsService.fg.SetEdges(filterDmNode.Name(),
|
|
|
|
[]string{dmStreamNode.Name(), ddNode.Name()},
|
|
|
|
[]string{insertBufferNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", filterDmNode.Name()), zap.Error(err))
|
|
|
|
panic("set edges faild in the node")
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ddNode
|
|
|
|
err = dsService.fg.SetEdges(ddNode.Name(),
|
|
|
|
[]string{ddStreamNode.Name()},
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", ddNode.Name()), zap.Error(err))
|
|
|
|
panic("set edges faild in the node")
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// insertBufferNode
|
|
|
|
err = dsService.fg.SetEdges(insertBufferNode.Name(),
|
|
|
|
[]string{filterDmNode.Name()},
|
|
|
|
[]string{gcNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", insertBufferNode.Name()), zap.Error(err))
|
|
|
|
panic("set edges faild in the node")
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// gcNode
|
|
|
|
err = dsService.fg.SetEdges(gcNode.Name(),
|
|
|
|
[]string{insertBufferNode.Name()},
|
|
|
|
[]string{})
|
|
|
|
if err != nil {
|
2021-02-26 10:13:36 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", gcNode.Name()), zap.Error(err))
|
|
|
|
panic("set edges faild in the node")
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
}
|