ethdb/leveldb : sync close meter routine of leveldb

This commit is contained in:
ucwong 2020-04-25 04:55:11 +00:00
parent 1aa83290f5
commit 8d163ae08b

View file

@ -79,6 +79,8 @@ type Database struct {
quitChan chan chan error // Quit channel to stop the metrics collection before closing the database
log log.Logger // Contextual logger tracking the database path
wg sync.WaitGroup
}
// New returns a wrapped LevelDB object. The namespace is the prefix that the
@ -129,7 +131,11 @@ func New(file string, cache int, handles int, namespace string) (*Database, erro
ldb.seekCompGauge = metrics.NewRegisteredGauge(namespace+"compact/seek", nil)
// Start up the metrics gathering and return
go ldb.meter(metricsGatheringInterval)
ldb.wg.Add(1)
go func() {
defer ldb.wg.Done()
ldb.meter(metricsGatheringInterval)
}()
return ldb, nil
}
@ -147,6 +153,7 @@ func (db *Database) Close() error {
}
db.quitChan = nil
}
db.wg.Wait()
return db.db.Close()
}