Skip to content

Commit

Permalink
enhance: decrease CPU overhead when calculating index file size
Browse files Browse the repository at this point in the history
Signed-off-by: jaime <yun.zhang@zilliz.com>
  • Loading branch information
jaime0815 committed Sep 27, 2024
1 parent e5a6c5b commit 3df82e2
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 @@ -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()
Expand Down
13 changes: 1 addition & 12 deletions internal/datacoord/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3df82e2

Please # to comment.