From 1fded42277105a0aa07791baf1ccb0e279d4589d Mon Sep 17 00:00:00 2001 From: jaime Date: Tue, 8 Oct 2024 14:29:25 +0800 Subject: [PATCH] enhance: decrease CPU overhead when calculating index file size (#36579) issue: #36578 --------- Signed-off-by: jaime --- internal/datacoord/index_meta.go | 19 +++++++++++++++++++ internal/datacoord/meta.go | 13 +------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/datacoord/index_meta.go b/internal/datacoord/index_meta.go index 979193f8ab5a2..55b165ecca012 100644 --- a/internal/datacoord/index_meta.go +++ b/internal/datacoord/index_meta.go @@ -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() diff --git a/internal/datacoord/meta.go b/internal/datacoord/meta.go index f0eb451f48d05..0459e120660e8 100644 --- a/internal/datacoord/meta.go +++ b/internal/datacoord/meta.go @@ -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 {