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 9c566f7db9
commit 3a3d2165f9

View file

@ -109,6 +109,8 @@ type Search struct {
needClosing bool
loops int
prevMetricID uint64
}
func (s *Search) reset() {
@ -123,6 +125,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.
@ -190,16 +193,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)
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)
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