2021-10-15 18:01:38 +08:00
|
|
|
// 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
|
2021-04-19 15:16:33 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-15 18:01:38 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-04-19 15:16:33 +08:00
|
|
|
//
|
2021-10-15 18:01:38 +08:00
|
|
|
// 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-04-19 15:16:33 +08:00
|
|
|
|
2021-01-19 11:37:16 +08:00
|
|
|
package datanode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-02-28 19:11:55 +08:00
|
|
|
"fmt"
|
2023-01-06 14:49:36 +08:00
|
|
|
"sync"
|
2021-01-19 11:37:16 +08:00
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2022-04-07 22:05:32 +08:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-03-23 19:43:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/allocator"
|
2021-05-25 15:35:37 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2022-03-17 18:03:23 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
2021-06-04 19:20:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/flowgraph"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgdispatcher"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/conc"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/funcutil"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/retry"
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
|
2021-09-15 21:25:49 +08:00
|
|
|
// dataSyncService controls a flowgraph for a specific collection
|
2021-01-19 11:37:16 +08:00
|
|
|
type dataSyncService struct {
|
2021-06-19 15:18:06 +08:00
|
|
|
ctx context.Context
|
|
|
|
cancelFn context.CancelFunc
|
2021-11-05 22:59:04 +08:00
|
|
|
fg *flowgraph.TimeTickedFlowGraph // internal flowgraph processes insert/delta messages
|
2023-01-06 14:49:36 +08:00
|
|
|
flushCh chan flushMsg
|
2023-03-23 19:43:57 +08:00
|
|
|
resendTTCh chan resendTTMsg // chan to ask for resending DataNode time tick message.
|
|
|
|
channel Channel // channel stores meta of channel
|
|
|
|
idAllocator allocator.Allocator // id/timestamp allocator
|
2023-02-13 16:38:33 +08:00
|
|
|
dispClient msgdispatcher.Client
|
2021-06-19 15:18:06 +08:00
|
|
|
msFactory msgstream.Factory
|
2021-11-25 09:43:15 +08:00
|
|
|
collectionID UniqueID // collection id of vchan for which this data sync service serves
|
|
|
|
vchannelName string
|
2021-11-05 22:59:04 +08:00
|
|
|
dataCoord types.DataCoord // DataCoord instance to interact with
|
2021-11-25 09:43:15 +08:00
|
|
|
clearSignal chan<- string // signal channel to notify flowgraph close for collection/partition drop msg consumed
|
2021-09-09 15:36:01 +08:00
|
|
|
|
2023-04-10 18:42:30 +08:00
|
|
|
delBufferManager *DeltaBufferManager
|
2021-11-05 22:59:04 +08:00
|
|
|
flushingSegCache *Cache // a guarding cache stores currently flushing segment ids
|
|
|
|
flushManager flushManager // flush manager handles flush process
|
2022-03-17 18:03:23 +08:00
|
|
|
chunkManager storage.ChunkManager
|
2021-12-02 16:39:33 +08:00
|
|
|
compactor *compactionExecutor // reference to compaction executor
|
2023-01-06 14:49:36 +08:00
|
|
|
|
2023-01-12 19:49:40 +08:00
|
|
|
serverID int64
|
2023-01-06 14:49:36 +08:00
|
|
|
stopOnce sync.Once
|
|
|
|
flushListener chan *segmentFlushPack // chan to listen flush event
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
2021-05-25 15:35:37 +08:00
|
|
|
func newDataSyncService(ctx context.Context,
|
2021-10-18 12:34:34 +08:00
|
|
|
flushCh chan flushMsg,
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTCh chan resendTTMsg,
|
2022-10-18 15:33:26 +08:00
|
|
|
channel Channel,
|
2023-03-23 19:43:57 +08:00
|
|
|
alloc allocator.Allocator,
|
2023-02-13 16:38:33 +08:00
|
|
|
dispClient msgdispatcher.Client,
|
2021-05-25 15:35:37 +08:00
|
|
|
factory msgstream.Factory,
|
2021-06-07 11:25:37 +08:00
|
|
|
vchan *datapb.VchannelInfo,
|
2021-11-25 09:43:15 +08:00
|
|
|
clearSignal chan<- string,
|
2021-06-21 18:22:13 +08:00
|
|
|
dataCoord types.DataCoord,
|
2021-09-23 16:03:54 +08:00
|
|
|
flushingSegCache *Cache,
|
2022-03-17 18:03:23 +08:00
|
|
|
chunkManager storage.ChunkManager,
|
2021-12-02 16:39:33 +08:00
|
|
|
compactor *compactionExecutor,
|
2023-02-15 16:20:34 +08:00
|
|
|
tickler *tickler,
|
2023-01-12 19:49:40 +08:00
|
|
|
serverID int64,
|
2021-06-19 15:18:06 +08:00
|
|
|
) (*dataSyncService, error) {
|
2021-06-07 11:25:37 +08:00
|
|
|
|
2022-10-18 15:33:26 +08:00
|
|
|
if channel == nil {
|
2021-09-09 15:36:01 +08:00
|
|
|
return nil, errors.New("Nil input")
|
|
|
|
}
|
|
|
|
|
2021-06-07 11:25:37 +08:00
|
|
|
ctx1, cancel := context.WithCancel(ctx)
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2023-04-10 18:42:30 +08:00
|
|
|
delBufferManager := &DeltaBufferManager{
|
|
|
|
channel: channel,
|
|
|
|
delBufHeap: &PriorityQueue{},
|
2022-12-13 16:15:21 +08:00
|
|
|
}
|
|
|
|
|
2021-02-03 17:30:10 +08:00
|
|
|
service := &dataSyncService{
|
2021-09-23 16:03:54 +08:00
|
|
|
ctx: ctx1,
|
|
|
|
cancelFn: cancel,
|
|
|
|
fg: nil,
|
2021-10-18 12:34:34 +08:00
|
|
|
flushCh: flushCh,
|
2022-05-25 14:34:00 +08:00
|
|
|
resendTTCh: resendTTCh,
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: channel,
|
2021-09-23 16:03:54 +08:00
|
|
|
idAllocator: alloc,
|
2023-02-13 16:38:33 +08:00
|
|
|
dispClient: dispClient,
|
2021-09-23 16:03:54 +08:00
|
|
|
msFactory: factory,
|
|
|
|
collectionID: vchan.GetCollectionID(),
|
2021-11-25 09:43:15 +08:00
|
|
|
vchannelName: vchan.GetChannelName(),
|
2021-09-23 16:03:54 +08:00
|
|
|
dataCoord: dataCoord,
|
|
|
|
clearSignal: clearSignal,
|
2022-12-13 16:15:21 +08:00
|
|
|
delBufferManager: delBufferManager,
|
2021-09-23 16:03:54 +08:00
|
|
|
flushingSegCache: flushingSegCache,
|
2022-03-17 18:03:23 +08:00
|
|
|
chunkManager: chunkManager,
|
2021-12-02 16:39:33 +08:00
|
|
|
compactor: compactor,
|
2023-01-12 19:49:40 +08:00
|
|
|
serverID: serverID,
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
2021-05-25 15:35:37 +08:00
|
|
|
|
2023-02-15 16:20:34 +08:00
|
|
|
if err := service.initNodes(vchan, tickler); err != nil {
|
2021-06-19 15:18:06 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return service, nil
|
2021-02-03 15:18:05 +08:00
|
|
|
}
|
|
|
|
|
2021-10-13 11:16:32 +08:00
|
|
|
type parallelConfig struct {
|
|
|
|
maxQueueLength int32
|
|
|
|
maxParallelism int32
|
|
|
|
}
|
|
|
|
|
|
|
|
type nodeConfig struct {
|
|
|
|
msFactory msgstream.Factory // msgStream factory
|
|
|
|
collectionID UniqueID
|
|
|
|
vChannelName string
|
2022-10-18 15:33:26 +08:00
|
|
|
channel Channel // Channel info
|
2023-03-23 19:43:57 +08:00
|
|
|
allocator allocator.Allocator
|
2023-01-12 19:49:40 +08:00
|
|
|
serverID int64
|
2021-10-13 11:16:32 +08:00
|
|
|
// defaults
|
|
|
|
parallelConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
func newParallelConfig() parallelConfig {
|
2022-12-07 18:01:19 +08:00
|
|
|
return parallelConfig{Params.DataNodeCfg.FlowGraphMaxQueueLength.GetAsInt32(), Params.DataNodeCfg.FlowGraphMaxParallelism.GetAsInt32()}
|
2021-10-13 11:16:32 +08:00
|
|
|
}
|
|
|
|
|
2023-01-06 14:49:36 +08:00
|
|
|
// start the flow graph in datasyncservice
|
2021-02-03 17:30:10 +08:00
|
|
|
func (dsService *dataSyncService) start() {
|
2021-05-08 14:07:04 +08:00
|
|
|
if dsService.fg != nil {
|
2022-07-21 15:52:27 +08:00
|
|
|
log.Info("dataSyncService starting flow graph", zap.Int64("collectionID", dsService.collectionID),
|
2022-01-04 15:47:18 +08:00
|
|
|
zap.String("vChanName", dsService.vchannelName))
|
2021-05-08 14:07:04 +08:00
|
|
|
dsService.fg.Start()
|
|
|
|
} else {
|
2022-07-21 15:52:27 +08:00
|
|
|
log.Warn("dataSyncService starting flow graph is nil", zap.Int64("collectionID", dsService.collectionID),
|
2022-01-04 15:47:18 +08:00
|
|
|
zap.String("vChanName", dsService.vchannelName))
|
2021-05-08 14:07:04 +08:00
|
|
|
}
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dsService *dataSyncService) close() {
|
2023-01-06 14:49:36 +08:00
|
|
|
dsService.stopOnce.Do(func() {
|
|
|
|
if dsService.fg != nil {
|
|
|
|
log.Info("dataSyncService closing flowgraph", zap.Int64("collectionID", dsService.collectionID),
|
|
|
|
zap.String("vChanName", dsService.vchannelName))
|
2023-02-13 16:38:33 +08:00
|
|
|
dsService.dispClient.Deregister(dsService.vchannelName)
|
2023-01-06 14:49:36 +08:00
|
|
|
dsService.fg.Close()
|
|
|
|
}
|
2022-06-22 10:16:14 +08:00
|
|
|
|
2023-01-06 14:49:36 +08:00
|
|
|
dsService.clearGlobalFlushingCache()
|
|
|
|
close(dsService.flushCh)
|
|
|
|
dsService.flushManager.close()
|
|
|
|
dsService.cancelFn()
|
2023-05-06 15:12:39 +08:00
|
|
|
dsService.channel.close()
|
2023-01-06 14:49:36 +08:00
|
|
|
})
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:16:14 +08:00
|
|
|
func (dsService *dataSyncService) clearGlobalFlushingCache() {
|
2022-10-18 15:33:26 +08:00
|
|
|
segments := dsService.channel.listAllSegmentIDs()
|
2022-06-22 10:16:14 +08:00
|
|
|
dsService.flushingSegCache.Remove(segments...)
|
|
|
|
}
|
|
|
|
|
2021-09-15 21:25:49 +08:00
|
|
|
// initNodes inits a TimetickedFlowGraph
|
2023-02-15 16:20:34 +08:00
|
|
|
func (dsService *dataSyncService) initNodes(vchanInfo *datapb.VchannelInfo, tickler *tickler) error {
|
2021-01-19 11:37:16 +08:00
|
|
|
dsService.fg = flowgraph.NewTimeTickedFlowGraph(dsService.ctx)
|
2021-11-05 22:59:04 +08:00
|
|
|
// initialize flush manager for DataSync Service
|
2022-10-18 15:33:26 +08:00
|
|
|
dsService.flushManager = NewRendezvousFlushManager(dsService.idAllocator, dsService.chunkManager, dsService.channel,
|
2022-11-17 20:37:10 +08:00
|
|
|
flushNotifyFunc(dsService, retry.Attempts(50)), dropVirtualChannelFunc(dsService))
|
2021-09-09 15:36:01 +08:00
|
|
|
|
2023-01-06 14:49:36 +08:00
|
|
|
log.Info("begin to init data sync service", zap.Int64("collection", vchanInfo.CollectionID),
|
|
|
|
zap.String("Chan", vchanInfo.ChannelName),
|
|
|
|
zap.Int64s("unflushed", vchanInfo.GetUnflushedSegmentIds()),
|
|
|
|
zap.Int64s("flushed", vchanInfo.GetFlushedSegmentIds()),
|
|
|
|
)
|
2022-06-16 12:00:10 +08:00
|
|
|
var err error
|
2021-06-08 19:25:37 +08:00
|
|
|
// recover segment checkpoints
|
2022-06-16 12:00:10 +08:00
|
|
|
unflushedSegmentInfos, err := dsService.getSegmentInfos(vchanInfo.GetUnflushedSegmentIds())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-07-07 14:32:21 +08:00
|
|
|
flushedSegmentInfos, err := dsService.getSegmentInfos(vchanInfo.GetFlushedSegmentIds())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-04-17 11:02:30 +08:00
|
|
|
//tickler will update addSegment progress to watchInfo
|
|
|
|
tickler.watch()
|
|
|
|
defer tickler.stop()
|
2023-02-28 14:19:47 +08:00
|
|
|
futures := make([]*conc.Future[any], 0, len(unflushedSegmentInfos)+len(flushedSegmentInfos))
|
2022-07-07 18:26:20 +08:00
|
|
|
|
2022-06-16 12:00:10 +08:00
|
|
|
for _, us := range unflushedSegmentInfos {
|
2021-06-08 19:25:37 +08:00
|
|
|
if us.CollectionID != dsService.collectionID ||
|
|
|
|
us.GetInsertChannel() != vchanInfo.ChannelName {
|
2023-01-06 14:49:36 +08:00
|
|
|
log.Warn("Collection ID or ChannelName not match",
|
2021-06-11 09:24:52 +08:00
|
|
|
zap.Int64("Wanted ID", dsService.collectionID),
|
|
|
|
zap.Int64("Actual ID", us.CollectionID),
|
|
|
|
zap.String("Wanted Channel Name", vchanInfo.ChannelName),
|
|
|
|
zap.String("Actual Channel Name", us.GetInsertChannel()),
|
|
|
|
)
|
2021-06-08 19:25:37 +08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-05-29 10:21:28 +08:00
|
|
|
log.Info("recover growing segments from checkpoints",
|
2022-07-07 18:26:20 +08:00
|
|
|
zap.String("vChannelName", us.GetInsertChannel()),
|
|
|
|
zap.Int64("segmentID", us.GetID()),
|
|
|
|
zap.Int64("numRows", us.GetNumOfRows()),
|
2021-06-11 09:24:52 +08:00
|
|
|
)
|
2022-10-18 15:33:26 +08:00
|
|
|
|
2022-07-07 14:32:21 +08:00
|
|
|
// avoid closure capture iteration variable
|
|
|
|
segment := us
|
2022-10-19 18:23:27 +08:00
|
|
|
future := getOrCreateIOPool().Submit(func() (interface{}, error) {
|
2022-10-18 15:33:26 +08:00
|
|
|
if err := dsService.channel.addSegment(addSegmentReq{
|
2022-09-26 18:06:54 +08:00
|
|
|
segType: datapb.SegmentType_Normal,
|
|
|
|
segID: segment.GetID(),
|
|
|
|
collID: segment.CollectionID,
|
|
|
|
partitionID: segment.PartitionID,
|
|
|
|
numOfRows: segment.GetNumOfRows(),
|
|
|
|
statsBinLogs: segment.Statslogs,
|
2023-05-29 10:21:28 +08:00
|
|
|
binLogs: segment.GetBinlogs(),
|
2022-10-18 15:33:26 +08:00
|
|
|
endPos: segment.GetDmlPosition(),
|
2022-09-26 18:06:54 +08:00
|
|
|
recoverTs: vchanInfo.GetSeekPosition().GetTimestamp()}); err != nil {
|
2022-07-07 14:32:21 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
2023-02-15 16:20:34 +08:00
|
|
|
tickler.inc()
|
2022-07-07 14:32:21 +08:00
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
futures = append(futures, future)
|
2021-06-08 19:25:37 +08:00
|
|
|
}
|
|
|
|
|
2022-06-16 12:00:10 +08:00
|
|
|
for _, fs := range flushedSegmentInfos {
|
2021-10-08 19:09:12 +08:00
|
|
|
if fs.CollectionID != dsService.collectionID ||
|
|
|
|
fs.GetInsertChannel() != vchanInfo.ChannelName {
|
2023-01-06 14:49:36 +08:00
|
|
|
log.Warn("Collection ID or ChannelName not match",
|
2021-10-08 19:09:12 +08:00
|
|
|
zap.Int64("Wanted ID", dsService.collectionID),
|
|
|
|
zap.Int64("Actual ID", fs.CollectionID),
|
|
|
|
zap.String("Wanted Channel Name", vchanInfo.ChannelName),
|
|
|
|
zap.String("Actual Channel Name", fs.GetInsertChannel()),
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
}
|
2022-07-07 18:26:20 +08:00
|
|
|
log.Info("recover sealed segments form checkpoints",
|
|
|
|
zap.String("vChannelName", fs.GetInsertChannel()),
|
|
|
|
zap.Int64("segmentID", fs.GetID()),
|
|
|
|
zap.Int64("numRows", fs.GetNumOfRows()),
|
2021-10-08 19:09:12 +08:00
|
|
|
)
|
2022-07-07 14:32:21 +08:00
|
|
|
// avoid closure capture iteration variable
|
|
|
|
segment := fs
|
2022-10-19 18:23:27 +08:00
|
|
|
future := getOrCreateIOPool().Submit(func() (interface{}, error) {
|
2022-10-18 15:33:26 +08:00
|
|
|
if err := dsService.channel.addSegment(addSegmentReq{
|
2022-09-26 18:06:54 +08:00
|
|
|
segType: datapb.SegmentType_Flushed,
|
|
|
|
segID: segment.GetID(),
|
2023-05-29 10:21:28 +08:00
|
|
|
collID: segment.GetCollectionID(),
|
|
|
|
partitionID: segment.GetPartitionID(),
|
2022-09-26 18:06:54 +08:00
|
|
|
numOfRows: segment.GetNumOfRows(),
|
2023-05-29 10:21:28 +08:00
|
|
|
statsBinLogs: segment.GetStatslogs(),
|
|
|
|
binLogs: segment.GetBinlogs(),
|
2022-09-26 18:06:54 +08:00
|
|
|
recoverTs: vchanInfo.GetSeekPosition().GetTimestamp(),
|
|
|
|
}); err != nil {
|
2022-07-07 14:32:21 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
2023-02-15 16:20:34 +08:00
|
|
|
tickler.inc()
|
2022-07-07 14:32:21 +08:00
|
|
|
return nil, nil
|
|
|
|
})
|
|
|
|
futures = append(futures, future)
|
|
|
|
}
|
|
|
|
|
2023-02-28 14:19:47 +08:00
|
|
|
err = conc.AwaitAll(futures...)
|
2022-07-07 14:32:21 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-10-08 19:09:12 +08:00
|
|
|
}
|
|
|
|
|
2021-11-04 15:56:28 +08:00
|
|
|
c := &nodeConfig{
|
|
|
|
msFactory: dsService.msFactory,
|
|
|
|
collectionID: vchanInfo.GetCollectionID(),
|
|
|
|
vChannelName: vchanInfo.GetChannelName(),
|
2022-10-18 15:33:26 +08:00
|
|
|
channel: dsService.channel,
|
2021-11-04 15:56:28 +08:00
|
|
|
allocator: dsService.idAllocator,
|
|
|
|
|
|
|
|
parallelConfig: newParallelConfig(),
|
2023-01-12 19:49:40 +08:00
|
|
|
serverID: dsService.serverID,
|
2021-11-04 15:56:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var dmStreamNode Node
|
2023-02-13 16:38:33 +08:00
|
|
|
dmStreamNode, err = newDmInputNode(dsService.dispClient, vchanInfo.GetSeekPosition(), c)
|
2021-11-04 15:56:28 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-07 18:26:20 +08:00
|
|
|
var ddNode Node
|
|
|
|
ddNode, err = newDDNode(
|
|
|
|
dsService.ctx,
|
|
|
|
dsService.collectionID,
|
|
|
|
vchanInfo.GetChannelName(),
|
|
|
|
vchanInfo.GetDroppedSegmentIds(),
|
|
|
|
flushedSegmentInfos,
|
|
|
|
unflushedSegmentInfos,
|
|
|
|
dsService.compactor)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-11-04 15:56:28 +08:00
|
|
|
var insertBufferNode Node
|
|
|
|
insertBufferNode, err = newInsertBufferNode(
|
|
|
|
dsService.ctx,
|
2022-02-28 19:11:55 +08:00
|
|
|
dsService.collectionID,
|
2022-12-13 16:15:21 +08:00
|
|
|
dsService.delBufferManager,
|
2021-11-04 15:56:28 +08:00
|
|
|
dsService.flushCh,
|
2022-05-25 14:34:00 +08:00
|
|
|
dsService.resendTTCh,
|
2021-11-04 15:56:28 +08:00
|
|
|
dsService.flushManager,
|
|
|
|
dsService.flushingSegCache,
|
|
|
|
c,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var deleteNode Node
|
2022-12-13 16:15:21 +08:00
|
|
|
deleteNode, err = newDeleteNode(dsService.ctx, dsService.flushManager, dsService.delBufferManager, dsService.clearSignal, c)
|
2021-11-04 15:56:28 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-10 22:13:04 +08:00
|
|
|
var ttNode Node
|
|
|
|
ttNode, err = newTTNode(c, dsService.dataCoord)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-25 17:35:36 +08:00
|
|
|
dsService.fg.AddNode(dmStreamNode)
|
|
|
|
dsService.fg.AddNode(ddNode)
|
|
|
|
dsService.fg.AddNode(insertBufferNode)
|
2021-08-25 11:41:52 +08:00
|
|
|
dsService.fg.AddNode(deleteNode)
|
2022-11-10 22:13:04 +08:00
|
|
|
dsService.fg.AddNode(ttNode)
|
2021-01-19 11:37:16 +08:00
|
|
|
|
|
|
|
// ddStreamNode
|
2021-06-02 15:58:33 +08:00
|
|
|
err = dsService.fg.SetEdges(dmStreamNode.Name(),
|
2021-01-19 11:37:16 +08:00
|
|
|
[]string{ddNode.Name()},
|
|
|
|
)
|
|
|
|
if err != nil {
|
2021-06-02 15:58:33 +08:00
|
|
|
log.Error("set edges failed in node", zap.String("name", dmStreamNode.Name()), zap.Error(err))
|
2021-06-19 15:18:06 +08:00
|
|
|
return err
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ddNode
|
|
|
|
err = dsService.fg.SetEdges(ddNode.Name(),
|
2021-06-02 15:58:33 +08:00
|
|
|
[]string{insertBufferNode.Name()},
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
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))
|
2021-06-19 15:18:06 +08:00
|
|
|
return err
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// insertBufferNode
|
|
|
|
err = dsService.fg.SetEdges(insertBufferNode.Name(),
|
2021-08-25 11:41:52 +08:00
|
|
|
[]string{deleteNode.Name()},
|
2021-01-19 11:37:16 +08:00
|
|
|
)
|
|
|
|
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))
|
2021-06-19 15:18:06 +08:00
|
|
|
return err
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
2021-08-25 11:41:52 +08:00
|
|
|
|
|
|
|
//deleteNode
|
|
|
|
err = dsService.fg.SetEdges(deleteNode.Name(),
|
2022-11-10 22:13:04 +08:00
|
|
|
[]string{ttNode.Name()},
|
2021-08-25 11:41:52 +08:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node", zap.String("name", deleteNode.Name()), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
2022-11-10 22:13:04 +08:00
|
|
|
|
|
|
|
// ttNode
|
|
|
|
err = dsService.fg.SetEdges(ttNode.Name(),
|
|
|
|
[]string{},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("set edges failed in node", zap.String("name", ttNode.Name()), zap.Error(err))
|
|
|
|
return err
|
|
|
|
}
|
2021-06-19 15:18:06 +08:00
|
|
|
return nil
|
2021-01-19 11:37:16 +08:00
|
|
|
}
|
2022-07-07 18:26:20 +08:00
|
|
|
|
|
|
|
// getSegmentInfos return the SegmentInfo details according to the given ids through RPC to datacoord
|
|
|
|
func (dsService *dataSyncService) getSegmentInfos(segmentIDs []int64) ([]*datapb.SegmentInfo, error) {
|
|
|
|
infoResp, err := dsService.dataCoord.GetSegmentInfo(dsService.ctx, &datapb.GetSegmentInfoRequest{
|
2022-10-21 15:57:28 +08:00
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType_SegmentInfo),
|
|
|
|
commonpbutil.WithMsgID(0),
|
2022-11-04 14:25:38 +08:00
|
|
|
commonpbutil.WithSourceID(paramtable.GetNodeID()),
|
2022-10-21 15:57:28 +08:00
|
|
|
),
|
2022-07-07 18:26:20 +08:00
|
|
|
SegmentIDs: segmentIDs,
|
|
|
|
IncludeUnHealthy: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Fail to get datapb.SegmentInfo by ids from datacoord", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if infoResp.GetStatus().ErrorCode != commonpb.ErrorCode_Success {
|
|
|
|
err = errors.New(infoResp.GetStatus().Reason)
|
|
|
|
log.Error("Fail to get datapb.SegmentInfo by ids from datacoord", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-21 15:52:27 +08:00
|
|
|
return infoResp.Infos, nil
|
2022-07-07 18:26:20 +08:00
|
|
|
}
|
2022-09-26 18:06:54 +08:00
|
|
|
|
2022-10-10 10:49:21 +08:00
|
|
|
func (dsService *dataSyncService) getChannelLatestMsgID(ctx context.Context, channelName string, segmentID int64) ([]byte, error) {
|
2022-09-26 18:06:54 +08:00
|
|
|
pChannelName := funcutil.ToPhysicalChannel(channelName)
|
|
|
|
dmlStream, err := dsService.msFactory.NewMsgStream(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-10-31 15:13:33 +08:00
|
|
|
defer dmlStream.Close()
|
|
|
|
|
2022-11-04 14:25:38 +08:00
|
|
|
subName := fmt.Sprintf("datanode-%d-%s-%d", paramtable.GetNodeID(), channelName, segmentID)
|
2022-10-10 10:49:21 +08:00
|
|
|
log.Debug("dataSyncService register consumer for getChannelLatestMsgID",
|
|
|
|
zap.String("pChannelName", pChannelName),
|
|
|
|
zap.String("subscription", subName),
|
|
|
|
)
|
2022-10-25 13:23:30 +08:00
|
|
|
dmlStream.AsConsumer([]string{pChannelName}, subName, mqwrapper.SubscriptionPositionUnknown)
|
2022-09-26 18:06:54 +08:00
|
|
|
id, err := dmlStream.GetLatestMsgID(pChannelName)
|
|
|
|
if err != nil {
|
2023-04-18 17:50:31 +08:00
|
|
|
log.Error("fail to GetLatestMsgID", zap.String("pChannelName", pChannelName), zap.Error(err))
|
2022-09-26 18:06:54 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return id.Serialize(), nil
|
|
|
|
}
|