From 50773348d3c6093b97706d5991b0c5fc5270f42d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 9 Nov 2019 13:48:36 +0200 Subject: [PATCH] lib/storage: small code prettifying --- lib/storage/index_db.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index c69815fb7..8407d2dfb 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -92,7 +92,7 @@ type indexDB struct { // The number of successful searches for metric ids by days. 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 // 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 }) - atomic.AddUint64(&is.db.recentHourInvertedIndexSearchCalls, 1) - if is.tryUpdatingMetricIDsForLastHourTimeRange(metricIDs, tfs, tr) { + if is.tryUpdatingMetricIDsForRecentHour(metricIDs, tfs, tr) { // Fast path: found metricIDs in the inmemoryInvertedIndex for the last hour. - atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1) return nil } @@ -1998,7 +1996,8 @@ func (is *indexSearch) getMetricIDsForRecentHours(tr TimeRange, maxMetrics int, 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{ AccountID: tfs.accountID, ProjectID: tfs.projectID, @@ -2010,18 +2009,21 @@ func (is *indexSearch) tryUpdatingMetricIDsForLastHourTimeRange(metricIDs *uint6 if maxHour == hmCurr.hour && minHour == maxHour && hmCurr.isFull { // The tr fits the current hour. hmCurr.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmCurr.byTenant[k], tfs) + atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1) return true } hmPrev := is.db.prevHourMetricIDs.Load().(*hourMetricIDs) if maxHour == hmPrev.hour && minHour == maxHour && hmPrev.isFull { // The tr fits the previous hour. hmPrev.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmPrev.byTenant[k], tfs) + atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1) return true } if maxHour == hmCurr.hour && minHour == hmPrev.hour && hmCurr.isFull && hmPrev.isFull { // The tr spans the previous and the current hours. hmPrev.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmPrev.byTenant[k], tfs) hmCurr.iidx.UpdateMetricIDsForTagFilters(metricIDs, hmCurr.byTenant[k], tfs) + atomic.AddUint64(&is.db.recentHourInvertedIndexSearchHits, 1) return true } return false