diff --git a/internal/datacoord/index_meta.go b/internal/datacoord/index_meta.go index d7d0652f87de3..977397d38a86f 100644 --- a/internal/datacoord/index_meta.go +++ b/internal/datacoord/index_meta.go @@ -789,6 +789,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() diff --git a/internal/datacoord/meta.go b/internal/datacoord/meta.go index 75a7a0e93ff6e..e0369ffba5d29 100644 --- a/internal/datacoord/meta.go +++ b/internal/datacoord/meta.go @@ -462,18 +462,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 {