2023-11-04 12:10:17 +08:00
|
|
|
package writebuffer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
|
|
|
"github.com/milvus-io/milvus/internal/datanode/metacache"
|
2023-11-15 15:24:18 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/datanode/syncmgr"
|
2023-11-04 12:10:17 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DeletePolicyBFPKOracle is the const config value for using bf pk oracle as delete policy
|
|
|
|
DeletePolicyBFPkOracle = `bloom_filter_pkoracle`
|
|
|
|
|
|
|
|
// DeletePolicyL0Delta is the const config value for using L0 delta as deleta policy.
|
|
|
|
DeletePolicyL0Delta = `l0_delta`
|
|
|
|
)
|
|
|
|
|
|
|
|
type WriteBufferOption func(opt *writeBufferOption)
|
|
|
|
|
|
|
|
type writeBufferOption struct {
|
|
|
|
deletePolicy string
|
|
|
|
idAllocator allocator.Interface
|
|
|
|
syncPolicies []SyncPolicy
|
|
|
|
|
|
|
|
pkStatsFactory metacache.PkStatsFactory
|
2023-11-15 15:24:18 +08:00
|
|
|
metaWriter syncmgr.MetaWriter
|
2023-11-04 12:10:17 +08:00
|
|
|
}
|
|
|
|
|
2023-11-27 19:48:26 +08:00
|
|
|
func defaultWBOption(metacache metacache.MetaCache) *writeBufferOption {
|
2023-11-28 18:04:26 +08:00
|
|
|
deletePolicy := DeletePolicyBFPkOracle
|
|
|
|
if paramtable.Get().DataCoordCfg.EnableLevelZeroSegment.GetAsBool() {
|
|
|
|
deletePolicy = DeletePolicyL0Delta
|
|
|
|
}
|
|
|
|
|
2023-11-04 12:10:17 +08:00
|
|
|
return &writeBufferOption{
|
|
|
|
// TODO use l0 delta as default after implementation.
|
2023-11-28 18:04:26 +08:00
|
|
|
deletePolicy: deletePolicy,
|
2023-11-04 12:10:17 +08:00
|
|
|
syncPolicies: []SyncPolicy{
|
2023-11-27 19:48:26 +08:00
|
|
|
GetFullBufferPolicy(),
|
2023-11-04 12:10:17 +08:00
|
|
|
GetSyncStaleBufferPolicy(paramtable.Get().DataNodeCfg.SyncPeriod.GetAsDuration(time.Second)),
|
2024-01-24 14:19:00 +08:00
|
|
|
GetSealedSegmentsPolicy(metacache),
|
2024-06-06 10:25:52 +08:00
|
|
|
GetDroppedSegmentPolicy(metacache),
|
2023-11-04 12:10:17 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithDeletePolicy(policy string) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.deletePolicy = policy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithIDAllocator(allocator allocator.Interface) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.idAllocator = allocator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithPKStatsFactory(factory metacache.PkStatsFactory) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.pkStatsFactory = factory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-15 15:24:18 +08:00
|
|
|
func WithMetaWriter(writer syncmgr.MetaWriter) WriteBufferOption {
|
2023-11-04 12:10:17 +08:00
|
|
|
return func(opt *writeBufferOption) {
|
2023-11-15 15:24:18 +08:00
|
|
|
opt.metaWriter = writer
|
2023-11-04 12:10:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithSyncPolicy(policy SyncPolicy) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.syncPolicies = append(opt.syncPolicies, policy)
|
|
|
|
}
|
|
|
|
}
|