Skip single compaction if there's no delta log in a segment (#11806)

Signed-off-by: sunby <bingyi.sun@zilliz.com>

Co-authored-by: sunby <bingyi.sun@zilliz.com>
pull/11876/head
Bingyi Sun 2021-11-16 11:23:11 +08:00 committed by GitHub
parent f2e720a77c
commit 8b60aa8c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -23,13 +23,17 @@ func (f singleCompactionFunc) generatePlan(segment *SegmentInfo, timetravel *tim
}
func chooseAllBinlogs(segment *SegmentInfo, timetravel *timetravel) *datapb.CompactionPlan {
deltaLogs := make([]*datapb.DeltaLogInfo, 0)
var deltaLogs []*datapb.DeltaLogInfo
for _, l := range segment.GetDeltalogs() {
if l.TimestampTo < timetravel.time {
deltaLogs = append(deltaLogs, l)
}
}
if len(deltaLogs) == 0 {
return nil
}
return &datapb.CompactionPlan{
SegmentBinlogs: []*datapb.CompactionSegmentBinlogs{
{

View File

@ -108,3 +108,34 @@ func Test_greedyMergeCompaction(t *testing.T) {
})
}
}
func Test_chooseAllBinlogs(t *testing.T) {
type args struct {
segment *SegmentInfo
timetravel *timetravel
}
tests := []struct {
name string
args args
want *datapb.CompactionPlan
}{
{
"test no delta logs",
args{
segment: &SegmentInfo{
SegmentInfo: &datapb.SegmentInfo{
ID: 1,
Deltalogs: nil,
},
},
},
nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := chooseAllBinlogs(tt.args.segment, tt.args.timetravel)
assert.EqualValues(t, tt.want, got)
})
}
}