Files
wehub-resource-sync 498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:17 +08:00

104 lines
3.2 KiB
Go

package writebuffer
import (
"time"
"github.com/milvus-io/milvus-proto/go-api/v3/msgpb"
"github.com/milvus-io/milvus/internal/allocator"
"github.com/milvus-io/milvus/internal/flushcommon/metacache"
"github.com/milvus-io/milvus/internal/flushcommon/syncmgr"
"github.com/milvus-io/milvus/pkg/v3/util/paramtable"
)
type WriteBufferOption func(opt *writeBufferOption)
type TaskObserverCallback func(t syncmgr.Task, err error)
type FlushSourceModeNotifier func(segmentID int64, mode metacache.FlushSourceMode)
// GrowingSourceResolver resolves an optional in-memory growing segment source
// for growing-source flush. GrowingSourcePending means the growing source exists but has not
// caught up to targetOffset yet; WriteBuffer should only be used when the state
// is GrowingSourceUnavailable.
type GrowingSourceResolver func(segmentID int64, targetOffset int64, endPos *msgpb.MsgPosition) (syncmgr.GrowingFlushSource, syncmgr.GrowingSourceState)
type writeBufferOption struct {
idAllocator allocator.Interface
syncPolicies []SyncPolicy
pkStatsFactory metacache.PkStatsFactory
metaWriter syncmgr.MetaWriter
errorHandler func(error)
taskObserverCallback TaskObserverCallback
storageVersion int64
growingSourceResolver GrowingSourceResolver
growingSourceRetryInterval time.Duration
flushSourceModeNotifier FlushSourceModeNotifier
}
func defaultWBOption(metacache metacache.MetaCache) *writeBufferOption {
return &writeBufferOption{
syncPolicies: []SyncPolicy{
GetFullBufferPolicy(),
GetSyncStaleBufferPolicy(paramtable.Get().DataNodeCfg.SyncPeriod.GetAsDuration(time.Second)),
GetSealedSegmentsPolicy(metacache),
GetDroppedSegmentPolicy(metacache),
},
// default error handler, just panicking
errorHandler: func(err error) {
panic(err)
},
}
}
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
}
}
func WithMetaWriter(writer syncmgr.MetaWriter) WriteBufferOption {
return func(opt *writeBufferOption) {
opt.metaWriter = writer
}
}
func WithSyncPolicy(policy SyncPolicy) WriteBufferOption {
return func(opt *writeBufferOption) {
opt.syncPolicies = append(opt.syncPolicies, policy)
}
}
func WithErrorHandler(handler func(err error)) WriteBufferOption {
return func(opt *writeBufferOption) {
opt.errorHandler = handler
}
}
// 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
}
}
func WithGrowingSourceResolver(resolver GrowingSourceResolver) WriteBufferOption {
return func(opt *writeBufferOption) {
opt.growingSourceResolver = resolver
}
}
func WithFlushSourceModeNotifier(notifier FlushSourceModeNotifier) WriteBufferOption {
return func(opt *writeBufferOption) {
opt.flushSourceModeNotifier = notifier
}
}