2023-10-31 02:30:16 +08:00
|
|
|
package syncmgr
|
|
|
|
|
|
|
|
import (
|
2023-12-26 10:40:47 +08:00
|
|
|
"github.com/samber/lo"
|
|
|
|
|
2023-10-31 02:30:16 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
|
|
|
"github.com/milvus-io/milvus/internal/datanode/metacache"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/storage"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/retry"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewSyncTask() *SyncTask {
|
|
|
|
return &SyncTask{
|
|
|
|
isFlush: false,
|
2023-11-17 14:40:26 +08:00
|
|
|
insertBinlogs: make(map[int64]*datapb.FieldBinlog),
|
|
|
|
statsBinlogs: make(map[int64]*datapb.FieldBinlog),
|
|
|
|
deltaBinlog: &datapb.FieldBinlog{},
|
2023-10-31 02:30:16 +08:00
|
|
|
segmentData: make(map[string][]byte),
|
2023-12-26 10:40:47 +08:00
|
|
|
binlogBlobs: make(map[int64]*storage.Blob),
|
2023-10-31 02:30:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithChunkManager(cm storage.ChunkManager) *SyncTask {
|
|
|
|
t.chunkManager = cm
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithAllocator(allocator allocator.Interface) *SyncTask {
|
|
|
|
t.allocator = allocator
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
func (t *SyncTask) WithStartPosition(start *msgpb.MsgPosition) *SyncTask {
|
|
|
|
t.startPosition = start
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-10-31 02:30:16 +08:00
|
|
|
func (t *SyncTask) WithCheckpoint(cp *msgpb.MsgPosition) *SyncTask {
|
|
|
|
t.checkpoint = cp
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithCollectionID(collID int64) *SyncTask {
|
|
|
|
t.collectionID = collID
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithPartitionID(partID int64) *SyncTask {
|
|
|
|
t.partitionID = partID
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithSegmentID(segID int64) *SyncTask {
|
|
|
|
t.segmentID = segID
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithChannelName(chanName string) *SyncTask {
|
|
|
|
t.channelName = chanName
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithSchema(schema *schemapb.CollectionSchema) *SyncTask {
|
|
|
|
t.schema = schema
|
2023-12-26 10:40:47 +08:00
|
|
|
t.pkField = lo.FindOrElse(schema.GetFields(), nil, func(field *schemapb.FieldSchema) bool {
|
|
|
|
return field.GetIsPrimaryKey()
|
|
|
|
})
|
2023-10-31 02:30:16 +08:00
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithTimeRange(from, to typeutil.Timestamp) *SyncTask {
|
|
|
|
t.tsFrom, t.tsTo = from, to
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithFlush() *SyncTask {
|
|
|
|
t.isFlush = true
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-11-04 12:10:17 +08:00
|
|
|
func (t *SyncTask) WithDrop() *SyncTask {
|
|
|
|
t.isDrop = true
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-10-31 02:30:16 +08:00
|
|
|
func (t *SyncTask) WithMetaCache(metacache metacache.MetaCache) *SyncTask {
|
|
|
|
t.metacache = metacache
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithMetaWriter(metaWriter MetaWriter) *SyncTask {
|
|
|
|
t.metaWriter = metaWriter
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithWriteRetryOptions(opts ...retry.Option) *SyncTask {
|
|
|
|
t.writeRetryOpts = opts
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *SyncTask) WithFailureCallback(callback func(error)) *SyncTask {
|
|
|
|
t.failureCallback = callback
|
|
|
|
return t
|
|
|
|
}
|
2023-11-15 15:24:18 +08:00
|
|
|
|
|
|
|
func (t *SyncTask) WithBatchSize(batchSize int64) *SyncTask {
|
|
|
|
t.batchSize = batchSize
|
|
|
|
return t
|
|
|
|
}
|
2023-11-17 21:46:20 +08:00
|
|
|
|
|
|
|
func (t *SyncTask) WithLevel(level datapb.SegmentLevel) *SyncTask {
|
|
|
|
t.level = level
|
|
|
|
return t
|
|
|
|
}
|