mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/storage: simplify indexDB.doExtDB() usage by removing the returned value
Previously indexDB.doExtDB() was returning boolean value, which was indicating whether f callback was called. There is no need in returning this boolean value, since the f callback can determine on itself whether it was called. This simplifies the code a bit. While at it, document indexDB.doExtDB().
This commit is contained in:
parent
218c533874
commit
6f61e9d49d
2 changed files with 12 additions and 10 deletions
|
@ -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()
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue