fix: [2.4] Add defer Unpin when error happens (#36620) (#36665)

Cherry-pick from master
pr: #36620
Resolves: #36619

---------

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2024-10-08 18:29:20 +08:00 committed by GitHub
parent 03fba95284
commit 9073f6281e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,6 +62,11 @@ func validate(ctx context.Context, manager *Manager, collectionID int64, partiti
// validate segment
segments := make([]Segment, 0, len(segmentIDs))
var err error
defer func() {
if err != nil {
manager.Segment.Unpin(segments)
}
}()
if len(segmentIDs) == 0 {
for _, partID := range searchPartIDs {
segments, err = manager.Segment.GetAndPinBy(WithPartition(partID), segmentFilter)
@ -76,7 +81,7 @@ func validate(ctx context.Context, manager *Manager, collectionID int64, partiti
}
for _, segment := range segments {
if !funcutil.SliceContain(searchPartIDs, segment.Partition()) {
err := fmt.Errorf("segment %d belongs to partition %d, which is not in %v", segment.ID(), segment.Partition(), searchPartIDs)
err = fmt.Errorf("segment %d belongs to partition %d, which is not in %v", segment.ID(), segment.Partition(), searchPartIDs)
return nil, err
}
}