Skip to content

Commit

Permalink
enhance: remove unnecessary clone in meta cache (#36628)
Browse files Browse the repository at this point in the history
See #36627

---------

Signed-off-by: Ted Xu <[email protected]>
  • Loading branch information
tedxu authored Oct 10, 2024
1 parent 3685edb commit 62679ef
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions internal/datacoord/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,33 +347,34 @@ func (m *meta) GetClonedCollectionInfo(collectionID UniqueID) *collectionInfo {
func (m *meta) GetSegmentsChanPart(selector SegmentInfoSelector) []*chanPartSegments {
m.RLock()
defer m.RUnlock()
mDimEntry := make(map[string]*chanPartSegments)
type dim struct {
partitionID int64
channelName string
}

mDimEntry := make(map[dim]*chanPartSegments)

log.Debug("GetSegmentsChanPart segment number", zap.Int("length", len(m.segments.GetSegments())))
for _, segmentInfo := range m.segments.segments {
if !selector(segmentInfo) {
for _, si := range m.segments.segments {
if !selector(si) {
continue
}

cloned := segmentInfo.Clone()

dim := fmt.Sprintf("%d-%s", cloned.PartitionID, cloned.InsertChannel)
entry, ok := mDimEntry[dim]
d := dim{si.PartitionID, si.InsertChannel}
entry, ok := mDimEntry[d]
if !ok {
entry = &chanPartSegments{
collectionID: cloned.CollectionID,
partitionID: cloned.PartitionID,
channelName: cloned.InsertChannel,
collectionID: si.CollectionID,
partitionID: si.PartitionID,
channelName: si.InsertChannel,
}
mDimEntry[dim] = entry
mDimEntry[d] = entry
}
entry.segments = append(entry.segments, cloned)
entry.segments = append(entry.segments, si)
}

result := make([]*chanPartSegments, 0, len(mDimEntry))
for _, entry := range mDimEntry {
result = append(result, entry)
}
log.Debug("GetSegmentsChanPart", zap.Int("length", len(result)))
return result
}

Expand Down

0 comments on commit 62679ef

Please sign in to comment.