2023-11-04 04:10:17 +00:00
|
|
|
package writebuffer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
2024-07-22 03:33:51 +00:00
|
|
|
"github.com/milvus-io/milvus/internal/flushcommon/metacache"
|
|
|
|
"github.com/milvus-io/milvus/internal/flushcommon/syncmgr"
|
2023-11-04 04:10:17 +00:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WriteBufferOption func(opt *writeBufferOption)
|
|
|
|
|
2024-10-14 06:47:22 +00:00
|
|
|
type TaskObserverCallback func(t syncmgr.Task, err error)
|
|
|
|
|
2023-11-04 04:10:17 +00:00
|
|
|
type writeBufferOption struct {
|
|
|
|
idAllocator allocator.Interface
|
|
|
|
syncPolicies []SyncPolicy
|
|
|
|
|
2024-10-14 06:47:22 +00:00
|
|
|
pkStatsFactory metacache.PkStatsFactory
|
|
|
|
metaWriter syncmgr.MetaWriter
|
|
|
|
errorHandler func(error)
|
|
|
|
taskObserverCallback TaskObserverCallback
|
2023-11-04 04:10:17 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 11:48:26 +00:00
|
|
|
func defaultWBOption(metacache metacache.MetaCache) *writeBufferOption {
|
2023-11-04 04:10:17 +00:00
|
|
|
return &writeBufferOption{
|
|
|
|
syncPolicies: []SyncPolicy{
|
2023-11-27 11:48:26 +00:00
|
|
|
GetFullBufferPolicy(),
|
2023-11-04 04:10:17 +00:00
|
|
|
GetSyncStaleBufferPolicy(paramtable.Get().DataNodeCfg.SyncPeriod.GetAsDuration(time.Second)),
|
2024-01-24 06:19:00 +00:00
|
|
|
GetSealedSegmentsPolicy(metacache),
|
2024-06-06 02:25:52 +00:00
|
|
|
GetDroppedSegmentPolicy(metacache),
|
2023-11-04 04:10:17 +00:00
|
|
|
},
|
2024-09-13 02:11:09 +00:00
|
|
|
// default error handler, just panicking
|
|
|
|
errorHandler: func(err error) {
|
|
|
|
panic(err)
|
|
|
|
},
|
2023-11-04 04:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 07:24:18 +00:00
|
|
|
func WithMetaWriter(writer syncmgr.MetaWriter) WriteBufferOption {
|
2023-11-04 04:10:17 +00:00
|
|
|
return func(opt *writeBufferOption) {
|
2023-11-15 07:24:18 +00:00
|
|
|
opt.metaWriter = writer
|
2023-11-04 04:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithSyncPolicy(policy SyncPolicy) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.syncPolicies = append(opt.syncPolicies, policy)
|
|
|
|
}
|
|
|
|
}
|
2024-09-13 02:11:09 +00:00
|
|
|
|
|
|
|
func WithErrorHandler(handler func(err error)) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.errorHandler = handler
|
|
|
|
}
|
|
|
|
}
|
2024-10-14 06:47:22 +00:00
|
|
|
|
|
|
|
// WithTaskObserverCallback sets the callback function for observing task status.
|
|
|
|
// The callback will be called when every task is executed, should be concurrent safe to be called.
|
|
|
|
func WithTaskObserverCallback(callback TaskObserverCallback) WriteBufferOption {
|
|
|
|
return func(opt *writeBufferOption) {
|
|
|
|
opt.taskObserverCallback = callback
|
|
|
|
}
|
|
|
|
}
|