fix: Fix GetCompactionTo return empty results when segment was GCed (#44270)

issue: #44269

---------

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
This commit is contained in:
cai.zhang 2025-09-12 18:11:58 +08:00 committed by GitHub
parent bfc9e80e14
commit f135dff94d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 8 deletions

View File

@ -200,26 +200,24 @@ func (s *SegmentsInfo) GetRealSegmentsForChannel(channel string) []*SegmentInfo
}
// GetCompactionTo returns the segment that the provided segment is compacted to.
// Return (nil, false) if given segmentID can not found in the meta.
// Return (nil, false) if given segmentID can not found in the meta and compact to is nil.
// Return (nil, true) if given segmentID can be found with no compaction to.
// Return (notnil, true) if given segmentID can be found and has compaction to.
func (s *SegmentsInfo) GetCompactionTo(fromSegmentID int64) ([]*SegmentInfo, bool) {
if _, ok := s.segments[fromSegmentID]; !ok {
return nil, false
}
_, exist := s.segments[fromSegmentID]
if compactTos, ok := s.compactionTo[fromSegmentID]; ok {
result := []*SegmentInfo{}
for _, compactTo := range compactTos {
to, ok := s.segments[compactTo]
if !ok {
log.Warn("compactionTo relation is broken", zap.Int64("from", fromSegmentID), zap.Int64("to", compactTo))
return nil, true
return nil, exist
}
result = append(result, to)
}
return result, true
return result, exist
}
return nil, true
return nil, exist
}
// DropSegment deletes provided segmentID

View File

@ -51,7 +51,7 @@ func TestCompactionTo(t *testing.T) {
segments.DropSegment(1)
compactTos, ok = segments.GetCompactionTo(1)
assert.False(t, ok)
assert.Nil(t, compactTos)
assert.NotNil(t, compactTos)
compactTos, ok = segments.GetCompactionTo(2)
assert.True(t, ok)
assert.NotNil(t, compactTos)