diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 0e6ea2a92..4d9ec3cd5 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -258,19 +258,20 @@ func (db *indexDB) UpdateMetrics(m *IndexDBMetrics) { }) } -func (db *indexDB) doExtDB(f func(extDB *indexDB)) bool { +// doExtDB calls f for non-nil db.extDB. +// +// f isn't called if db.extDB is nil. +func (db *indexDB) doExtDB(f func(extDB *indexDB)) { db.extDBLock.Lock() extDB := db.extDB if extDB != nil { extDB.incRef() } db.extDBLock.Unlock() - if extDB == nil { - return false + if extDB != nil { + f(extDB) + extDB.decRef() } - f(extDB) - extDB.decRef() - return true } // SetExtDB sets external db to search. @@ -1505,7 +1506,7 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt } // Try searching in the external indexDB. - if db.doExtDB(func(extDB *indexDB) { + db.doExtDB(func(extDB *indexDB) { is := extDB.getIndexSearch(noDeadline) dst, ok = is.searchMetricName(dst, metricID) extDB.putIndexSearch(is) @@ -1514,7 +1515,8 @@ func (db *indexDB) searchMetricNameWithCache(dst []byte, metricID uint64) ([]byt // since the filtering must be performed before calling this func. extDB.putMetricNameToCache(metricID, dst) } - }) && ok { + }) + if ok { return dst, true } diff --git a/lib/storage/storage.go b/lib/storage/storage.go index c3996f137..bf0e3a233 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -389,11 +389,11 @@ func (s *Storage) CreateSnapshot() (string, error) { dirsToRemoveOnError = append(dirsToRemoveOnError, idbSnapshot) var err error - ok := idb.doExtDB(func(extDB *indexDB) { + idb.doExtDB(func(extDB *indexDB) { prevSnapshot := filepath.Join(idbSnapshot, extDB.name) err = extDB.tb.CreateSnapshotAt(prevSnapshot) }) - if ok && err != nil { + if err != nil { return "", fmt.Errorf("cannot create prev indexDB snapshot: %w", err) } dstIdbDir := filepath.Join(dstDir, indexdbDirname)