Skip to content

Commit

Permalink
enhance: decrease CPU overhead when calculating index file size (milv…
Browse files Browse the repository at this point in the history
…us-io#36579)

issue: milvus-io#36578

---------

Signed-off-by: jaime <[email protected]>
  • Loading branch information
jaime0815 authored Oct 8, 2024
1 parent 4e0ea39 commit 1fded42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
19 changes: 19 additions & 0 deletions internal/datacoord/index_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,25 @@ func (m *indexMeta) GetAllSegIndexes() map[int64]*model.SegmentIndex {
return segIndexes
}

// SetStoredIndexFileSizeMetric returns the total index files size of all segment for each collection.
func (m *indexMeta) SetStoredIndexFileSizeMetric(collections map[UniqueID]*collectionInfo) uint64 {
m.RLock()
defer m.RUnlock()

var total uint64
metrics.DataCoordStoredIndexFilesSize.Reset()

for _, segmentIdx := range m.buildID2SegmentIndex {
coll, ok := collections[segmentIdx.CollectionID]
if ok {
metrics.DataCoordStoredIndexFilesSize.WithLabelValues(coll.DatabaseName,
fmt.Sprint(segmentIdx.CollectionID), fmt.Sprint(segmentIdx.SegmentID)).Set(float64(segmentIdx.IndexSize))
total += segmentIdx.IndexSize
}
}
return total
}

func (m *indexMeta) RemoveSegmentIndex(collID, partID, segID, indexID, buildID UniqueID) error {
m.Lock()
defer m.Unlock()
Expand Down
13 changes: 1 addition & 12 deletions internal/datacoord/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,7 @@ func (m *meta) GetQuotaInfo() *metricsinfo.DataCoordQuotaMetrics {
func (m *meta) SetStoredIndexFileSizeMetric() uint64 {
m.RLock()
defer m.RUnlock()
var total uint64

metrics.DataCoordStoredIndexFilesSize.Reset()
for _, segmentIdx := range m.indexMeta.GetAllSegIndexes() {
coll, ok := m.collections[segmentIdx.CollectionID]
if ok {
metrics.DataCoordStoredIndexFilesSize.WithLabelValues(coll.DatabaseName,
fmt.Sprint(segmentIdx.CollectionID), fmt.Sprint(segmentIdx.SegmentID)).Set(float64(segmentIdx.IndexSize))
total += segmentIdx.IndexSize
}
}
return total
return m.indexMeta.SetStoredIndexFileSizeMetric(m.collections)
}

func (m *meta) GetAllCollectionNumRows() map[int64]int64 {
Expand Down

0 comments on commit 1fded42

Please sign in to comment.