congqixia eaabe0293b
fix: Update segment compactTo when compactTo segment is compacted (#28755)
Related to #28736 #28748
See also #27675
Previous PR: #28646

This PR fixes `SegmentNotFound` issue when compaction happens multiple
times and the buffer of first generation segment is sync due to stale
policy

Now the `CompactSegments` API of metacache shall update the compactTo
field of segmentInfo if the compactTo segment is also compacted to keep
the bloodline clean

Also, add the `CompactedSegment` SyncPolicy to sync the compacted
segment asap to keep metacache clean

Now the `SyncPolicy` is an interface instead of a function type so that
when it selects some segments to sync, we colud log the reason and
target segment

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2023-11-27 19:48:26 +08:00

73 lines
1.9 KiB
Go

package writebuffer
import (
"time"
"github.com/milvus-io/milvus/internal/allocator"
"github.com/milvus-io/milvus/internal/datanode/metacache"
"github.com/milvus-io/milvus/internal/datanode/syncmgr"
"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
metaWriter syncmgr.MetaWriter
}
func defaultWBOption(metacache metacache.MetaCache) *writeBufferOption {
return &writeBufferOption{
// TODO use l0 delta as default after implementation.
deletePolicy: paramtable.Get().DataNodeCfg.DeltaPolicy.GetValue(),
syncPolicies: []SyncPolicy{
GetFullBufferPolicy(),
GetSyncStaleBufferPolicy(paramtable.Get().DataNodeCfg.SyncPeriod.GetAsDuration(time.Second)),
GetCompactedSegmentsPolicy(metacache),
GetFlushingSegmentsPolicy(metacache),
},
}
}
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
}
}
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)
}
}