2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
2021-01-21 09:55:25 +08:00
|
|
|
"log"
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
"github.com/uber/jaeger-client-go"
|
|
|
|
"github.com/uber/jaeger-client-go/config"
|
2021-01-22 09:36:40 +08:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/datapb"
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb2"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type DataNode struct {
|
2021-01-22 09:36:40 +08:00
|
|
|
ctx context.Context
|
|
|
|
DataNodeID uint64
|
|
|
|
dataSyncService *dataSyncService
|
|
|
|
metaService *metaService
|
|
|
|
|
|
|
|
replica collectionReplica
|
2021-01-21 09:55:25 +08:00
|
|
|
|
|
|
|
tracer opentracing.Tracer
|
|
|
|
closer io.Closer
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDataNode(ctx context.Context, dataNodeID uint64) *DataNode {
|
|
|
|
|
|
|
|
collections := make([]*Collection, 0)
|
|
|
|
|
|
|
|
var replica collectionReplica = &collectionReplicaImpl{
|
|
|
|
collections: collections,
|
|
|
|
}
|
|
|
|
|
|
|
|
node := &DataNode{
|
2021-01-22 09:36:40 +08:00
|
|
|
ctx: ctx,
|
|
|
|
DataNodeID: dataNodeID,
|
|
|
|
dataSyncService: nil,
|
|
|
|
// metaService: nil,
|
|
|
|
replica: replica,
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
2021-01-22 09:36:40 +08:00
|
|
|
func (node *DataNode) Init() error {
|
2021-01-19 11:37:16 +08:00
|
|
|
Params.Init()
|
2021-01-22 09:36:40 +08:00
|
|
|
return nil
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) Start() error {
|
|
|
|
cfg := &config.Configuration{
|
|
|
|
ServiceName: "data_node",
|
|
|
|
Sampler: &config.SamplerConfig{
|
|
|
|
Type: "const",
|
|
|
|
Param: 1,
|
|
|
|
},
|
|
|
|
Reporter: &config.ReporterConfig{
|
|
|
|
LogSpans: true,
|
|
|
|
},
|
|
|
|
}
|
2021-01-21 09:55:25 +08:00
|
|
|
|
2021-01-19 11:37:16 +08:00
|
|
|
var err error
|
|
|
|
node.tracer, node.closer, err = cfg.NewTracer(config.Logger(jaeger.StdLogger))
|
|
|
|
if err != nil {
|
2021-01-21 09:55:25 +08:00
|
|
|
log.Printf("ERROR: cannot init Jaeger: %v\n", err)
|
|
|
|
} else {
|
|
|
|
opentracing.SetGlobalTracer(node.tracer)
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO GOOSE Init Size??
|
|
|
|
chanSize := 100
|
2021-01-22 09:36:40 +08:00
|
|
|
flushChan := make(chan *flushMsg, chanSize)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2021-01-22 09:36:40 +08:00
|
|
|
node.dataSyncService = newDataSyncService(node.ctx, flushChan, node.replica)
|
2021-01-19 11:37:16 +08:00
|
|
|
node.metaService = newMetaService(node.ctx, node.replica)
|
|
|
|
|
|
|
|
go node.dataSyncService.start()
|
2021-01-22 09:36:40 +08:00
|
|
|
// go node.flushSyncService.start()
|
2021-01-19 11:37:16 +08:00
|
|
|
node.metaService.start()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-22 09:36:40 +08:00
|
|
|
func (node *DataNode) WatchDmChannels(in *datapb.WatchDmChannelRequest) error {
|
|
|
|
// GOOSE TODO: Implement me
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) GetComponentStates() (*internalpb2.ComponentStates, error) {
|
|
|
|
// GOOSE TODO: Implement me
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) FlushSegments(in *datapb.FlushSegRequest) error {
|
|
|
|
// GOOSE TODO: Implement me
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (node *DataNode) Stop() error {
|
2021-01-19 11:37:16 +08:00
|
|
|
<-node.ctx.Done()
|
|
|
|
|
|
|
|
// close services
|
|
|
|
if node.dataSyncService != nil {
|
|
|
|
(*node.dataSyncService).close()
|
|
|
|
}
|
|
|
|
|
|
|
|
if node.closer != nil {
|
|
|
|
node.closer.Close()
|
|
|
|
}
|
2021-01-22 09:36:40 +08:00
|
|
|
return nil
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
}
|