lib/storage: code clarification: remove caching the found metricName in searchMetricName

This commit is contained in:
Aliaksandr Valialkin 2021-04-13 10:20:35 +03:00
parent 663a91bb82
commit 251747e253
2 changed files with 23 additions and 8 deletions

View file

@ -1516,9 +1516,15 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt
}
is := db.getIndexSearch(noDeadline)
dst, err := is.searchMetricName(dst, metricID)
var err error
dst, err = is.searchMetricName(dst, metricID)
db.putIndexSearch(is)
if err == nil {
// There is no need in verifying whether the given metricID is deleted,
// since the filtering must be performed before calling this func.
db.putMetricNameToCache(metricID, dst)
return dst, nil
}
if err != io.EOF {
return dst, err
}
@ -1528,6 +1534,11 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt
is := extDB.getIndexSearch(noDeadline)
dst, err = is.searchMetricName(dst, metricID)
extDB.putIndexSearch(is)
if err == nil {
// There is no need in verifying whether the given metricID is deleted,
// since the filtering must be performed before calling this func.
extDB.putMetricNameToCache(metricID, dst)
}
}) {
return dst, err
}
@ -1769,7 +1780,15 @@ func (is *indexSearch) searchMetricNameWithCache(dst []byte, metricID uint64) ([
if len(metricName) > len(dst) {
return metricName, nil
}
return is.searchMetricName(dst, metricID)
var err error
dst, err = is.searchMetricName(dst, metricID)
if err == nil {
// There is no need in verifying whether the given metricID is deleted,
// since the filtering must be performed before calling this func.
is.db.putMetricNameToCache(metricID, dst)
return dst, nil
}
return dst, err
}
func (is *indexSearch) searchMetricName(dst []byte, metricID uint64) ([]byte, error) {
@ -1785,10 +1804,6 @@ func (is *indexSearch) searchMetricName(dst []byte, metricID uint64) ([]byte, er
}
v := ts.Item[len(kb.B):]
dst = append(dst, v...)
// There is no need in verifying whether the given metricID is deleted,
// since the filtering must be performed before calling this func.
is.db.putMetricNameToCache(metricID, dst)
return dst, nil
}

View file

@ -199,7 +199,7 @@ func (s *Search) NextMetricBlock() bool {
if err != nil {
if err == io.EOF {
// Skip missing metricName for tsid.MetricID.
// It should be automatically fixed. See indexDB.searchMetricName for details.
// It should be automatically fixed. See indexDB.searchMetricNameWithCache for details.
continue
}
s.err = err