lib/storage: do not reload metricName for the same metricID in Search.NextMetricBlock

This should speed up Search.NextMetricBlock a bit
This commit is contained in:
Aliaksandr Valialkin 2021-03-23 17:56:47 +02:00
parent 2041008d64
commit 9947c65df3

View File

@ -144,6 +144,8 @@ type Search struct {
needClosing bool
loops int
prevMetricID uint64
}
func (s *Search) reset() {
@ -158,6 +160,7 @@ func (s *Search) reset() {
s.err = nil
s.needClosing = false
s.loops = 0
s.prevMetricID = 0
}
// Init initializes s from the given storage, tfss and tr.
@ -225,16 +228,19 @@ func (s *Search) NextMetricBlock() bool {
}
s.loops++
tsid := &s.ts.BlockRef.bh.TSID
var err error
s.MetricBlockRef.MetricName, err = s.idb.searchMetricNameWithCache(s.MetricBlockRef.MetricName[:0], tsid.MetricID, tsid.AccountID, tsid.ProjectID)
if err != nil {
if err == io.EOF {
// Skip missing metricName for tsid.MetricID.
// It should be automatically fixed. See indexDB.searchMetricName for details.
continue
if tsid.MetricID != s.prevMetricID {
var err error
s.MetricBlockRef.MetricName, err = s.idb.searchMetricNameWithCache(s.MetricBlockRef.MetricName[:0], tsid.MetricID, tsid.AccountID, tsid.ProjectID)
if err != nil {
if err == io.EOF {
// Skip missing metricName for tsid.MetricID.
// It should be automatically fixed. See indexDB.searchMetricName for details.
continue
}
s.err = err
return false
}
s.err = err
return false
s.prevMetricID = tsid.MetricID
}
s.MetricBlockRef.BlockRef = s.ts.BlockRef
return true