lib/storage: small code prettifying

This commit is contained in:
Aliaksandr Valialkin 2019-11-09 13:48:36 +02:00
parent 44fa8226df
commit 50773348d3

View file

@ -92,7 +92,7 @@ type indexDB struct {
// The number of successful searches for metric ids by days. // The number of successful searches for metric ids by days.
dateMetricIDsSearchHits uint64 dateMetricIDsSearchHits uint64
// The number of calls for recent hour serches over inverted index. // The number of calls for recent hour searches over inverted index.
recentHourInvertedIndexSearchCalls uint64 recentHourInvertedIndexSearchCalls uint64
// The number of hits for recent hour searches over inverted index. // The number of hits for recent hour searches over inverted index.
@ -1608,10 +1608,8 @@ func (is *indexSearch) updateMetricIDsForTagFilters(metricIDs *uint64set.Set, tf
return bytes.Compare(a.prefix, b.prefix) < 0 return bytes.Compare(a.prefix, b.prefix) < 0
}) })
atomic.AddUint64(&is.db.recentHourInvertedIndexSearchCalls, 1) if is.tryUpdatingMetricIDsForRecentHour(metricIDs, tfs, tr) {
if is.tryUpdatingMetricIDsForLastHourTimeRange(metricIDs, tfs, tr) {
// Fast path: found metricIDs in the inmemoryInvertedIndex for the last hour. // Fast path: found metricIDs in the inmemoryInvertedIndex for the last hour.
atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1)
return nil return nil
} }
@ -1998,7 +1996,8 @@ func (is *indexSearch) getMetricIDsForRecentHours(tr TimeRange, maxMetrics int,
return nil, false return nil, false
} }
func (is *indexSearch) tryUpdatingMetricIDsForLastHourTimeRange(metricIDs *uint64set.Set, tfs *TagFilters, tr TimeRange) bool { func (is *indexSearch) tryUpdatingMetricIDsForRecentHour(metricIDs *uint64set.Set, tfs *TagFilters, tr TimeRange) bool {
atomic.AddUint64(&is.db.recentHourInvertedIndexSearchCalls, 1)
k := accountProjectKey{ k := accountProjectKey{
AccountID: tfs.accountID, AccountID: tfs.accountID,
ProjectID: tfs.projectID, ProjectID: tfs.projectID,
@ -2010,18 +2009,21 @@ func (is *indexSearch) tryUpdatingMetricIDsForLastHourTimeRange(metricIDs *uint6
if maxHour == hmCurr.hour && minHour == maxHour && hmCurr.isFull { if maxHour == hmCurr.hour && minHour == maxHour && hmCurr.isFull {
// The tr fits the current hour. // The tr fits the current hour.
hmCurr.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmCurr.byTenant[k], tfs) hmCurr.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmCurr.byTenant[k], tfs)
atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1)
return true return true
} }
hmPrev := is.db.prevHourMetricIDs.Load().(*hourMetricIDs) hmPrev := is.db.prevHourMetricIDs.Load().(*hourMetricIDs)
if maxHour == hmPrev.hour && minHour == maxHour && hmPrev.isFull { if maxHour == hmPrev.hour && minHour == maxHour && hmPrev.isFull {
// The tr fits the previous hour. // The tr fits the previous hour.
hmPrev.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmPrev.byTenant[k], tfs) hmPrev.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmPrev.byTenant[k], tfs)
atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1)
return true return true
} }
if maxHour == hmCurr.hour && minHour == hmPrev.hour && hmCurr.isFull && hmPrev.isFull { if maxHour == hmCurr.hour && minHour == hmPrev.hour && hmCurr.isFull && hmPrev.isFull {
// The tr spans the previous and the current hours. // The tr spans the previous and the current hours.
hmPrev.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmPrev.byTenant[k], tfs) hmPrev.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmPrev.byTenant[k], tfs)
hmCurr.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmCurr.byTenant[k], tfs) hmCurr.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmCurr.byTenant[k], tfs)
atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1)
return true return true
} }
return false return false