mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-12 13:15:09 +08:00
9b371067d2
- Add Compaction l0 views - Add Compaction scheduler - Add Compaction triggerv2 - Add Compaction view manager See also: #27606 --------- Signed-off-by: yangxuan <xuan.yang@zilliz.com>
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package datacoord
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/samber/lo"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
|
)
|
|
|
|
// The LevelZeroSegments keeps the min group
|
|
type LevelZeroSegmentsView struct {
|
|
label *CompactionGroupLabel
|
|
segments []*SegmentView
|
|
earliestGrowingSegmentPos *msgpb.MsgPosition
|
|
}
|
|
|
|
var _ CompactionView = (*LevelZeroSegmentsView)(nil)
|
|
|
|
func (v *LevelZeroSegmentsView) String() string {
|
|
l0strings := lo.Map(v.segments, func(v *SegmentView, _ int) string {
|
|
return v.LevelZeroString()
|
|
})
|
|
return fmt.Sprintf("label=<%s>, posT=<%v>, l0 segments=%v",
|
|
v.label.String(),
|
|
v.earliestGrowingSegmentPos.GetTimestamp(),
|
|
l0strings)
|
|
}
|
|
|
|
func (v *LevelZeroSegmentsView) GetGroupLabel() *CompactionGroupLabel {
|
|
if v == nil {
|
|
return &CompactionGroupLabel{}
|
|
}
|
|
return v.label
|
|
}
|
|
|
|
func (v *LevelZeroSegmentsView) GetSegmentsView() []*SegmentView {
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
|
|
return v.segments
|
|
}
|
|
|
|
func (v *LevelZeroSegmentsView) Equal(others []*SegmentView) bool {
|
|
if len(v.segments) != len(others) {
|
|
return false
|
|
}
|
|
|
|
IDSelector := func(v *SegmentView, _ int) int64 {
|
|
return v.ID
|
|
}
|
|
|
|
diffLeft, diffRight := lo.Difference(lo.Map(others, IDSelector), lo.Map(v.segments, IDSelector))
|
|
|
|
diffCount := len(diffLeft) + len(diffRight)
|
|
return diffCount == 0
|
|
}
|
|
|
|
// Trigger triggers all qualified LevelZeroSegments according to views
|
|
func (v *LevelZeroSegmentsView) Trigger() CompactionView {
|
|
// Only choose segments with position less than the earliest growing segment position
|
|
validSegments := lo.Filter(v.segments, func(view *SegmentView, _ int) bool {
|
|
return view.dmlPos.GetTimestamp() < v.earliestGrowingSegmentPos.GetTimestamp()
|
|
})
|
|
|
|
var (
|
|
minDeltaSize = Params.DataCoordCfg.LevelZeroCompactionTriggerMinSize.GetAsFloat()
|
|
minDeltaCount = Params.DataCoordCfg.LevelZeroCompactionTriggerDeltalogMinNum.GetAsInt()
|
|
|
|
curDeltaSize float64
|
|
curDeltaCount int
|
|
)
|
|
|
|
for _, segView := range validSegments {
|
|
curDeltaSize += segView.DeltaSize
|
|
curDeltaCount += segView.DeltalogCount
|
|
}
|
|
|
|
if curDeltaSize < minDeltaSize && curDeltaCount < minDeltaCount {
|
|
return nil
|
|
}
|
|
|
|
return &LevelZeroSegmentsView{
|
|
label: v.label,
|
|
segments: validSegments,
|
|
earliestGrowingSegmentPos: v.earliestGrowingSegmentPos,
|
|
}
|
|
}
|