diff --git a/internal/datacoord/compaction_policy.go b/internal/datacoord/compaction_policy.go index 52349025c4..2db83811af 100644 --- a/internal/datacoord/compaction_policy.go +++ b/internal/datacoord/compaction_policy.go @@ -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{ { diff --git a/internal/datacoord/compaction_policy_test.go b/internal/datacoord/compaction_policy_test.go index 7a0e6fd626..78e4452d16 100644 --- a/internal/datacoord/compaction_policy_test.go +++ b/internal/datacoord/compaction_policy_test.go @@ -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) + }) + } +}