Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

enhance: decrease CPU overhead when calculating index file size #36580

Open
wants to merge 1 commit into
base: 2.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading