From 9b3217db6176ca2435375a1ea0df76e75be234b7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 23 Jan 2024 16:08:38 +0200 Subject: [PATCH] lib/storage: do not sort metricIDs passed to Storage.prefetchMetricNames, since the caller is responsible for the sorting --- lib/storage/storage.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index d9c0abc9be..ae2d218b5d 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -1204,11 +1204,13 @@ func (s *Storage) SearchMetricNames(qt *querytracer.Tracer, tfss []*TagFilters, return metricNames, nil } -// prefetchMetricNames pre-fetches metric names for the given metricIDs into metricID->metricName cache. +// prefetchMetricNames pre-fetches metric names for the given srcMetricIDs into metricID->metricName cache. // // It is expected that all the metricIDs belong to the same (accountID, projectID) // // This should speed-up further searchMetricNameWithCache calls for srcMetricIDs from tsids. +// +// It is expected that srcMetricIDs are already sorted by the caller. Otherwise the pre-fetching may be slow. func (s *Storage) prefetchMetricNames(qt *querytracer.Tracer, accountID, projectID uint32, srcMetricIDs []uint64, deadline uint64) error { qt = qt.NewChild("prefetch metric names for %d metricIDs", len(srcMetricIDs)) defer qt.Done() @@ -1218,7 +1220,7 @@ func (s *Storage) prefetchMetricNames(qt *querytracer.Tracer, accountID, project return nil } - var metricIDs uint64Sorter + var metricIDs []uint64 s.prefetchedMetricIDsLock.Lock() prefetchedMetricIDs := s.prefetchedMetricIDs for _, metricID := range srcMetricIDs { @@ -1238,7 +1240,6 @@ func (s *Storage) prefetchMetricNames(qt *querytracer.Tracer, accountID, project atomic.AddUint64(&s.slowMetricNameLoads, uint64(len(metricIDs))) // Pre-fetch metricIDs. - sort.Sort(metricIDs) var missingMetricIDs []uint64 var metricName []byte var err error