mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
swarm/storage/localstore: simplify DB.Close
This commit is contained in:
parent
d6c3930ab1
commit
11e62373cc
3 changed files with 4 additions and 13 deletions
|
|
@ -136,7 +136,8 @@ func (db *DB) triggerGarbageCollection() {
|
|||
}
|
||||
|
||||
// incGCSizeInBatch changes gcSize field value
|
||||
// by change which can be negative.
|
||||
// by change which can be negative. This function
|
||||
// must be called under batchMu lock.
|
||||
func (db *DB) incGCSizeInBatch(batch *leveldb.Batch, change int64) (err error) {
|
||||
if change == 0 {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -294,10 +294,7 @@ func TestDB_gcSize(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// DB.Close writes gc size to disk, so
|
||||
// Instead calling Close, close the database
|
||||
// without it.
|
||||
if err := db.closeWithOptions(false); err != nil {
|
||||
if err := db.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -312,21 +312,14 @@ func New(path string, baseKey []byte, o *Options) (db *DB, err error) {
|
|||
|
||||
// Close closes the underlying database.
|
||||
func (db *DB) Close() (err error) {
|
||||
return db.closeWithOptions(true)
|
||||
}
|
||||
|
||||
// closeWithOptions provides a more control which part of closing
|
||||
// is done for tests.
|
||||
func (db *DB) closeWithOptions(writeGCSize bool) (err error) {
|
||||
close(db.close)
|
||||
db.updateGCWG.Wait()
|
||||
|
||||
// wait for gc worker to
|
||||
// return before closing the shed
|
||||
timeout := time.After(5 * time.Second)
|
||||
select {
|
||||
case <-db.collectGarbageWorkerDone:
|
||||
case <-timeout:
|
||||
case <-time.After(5 * time.Second):
|
||||
log.Error("localstore: collect garbage worker did not return after db close")
|
||||
}
|
||||
return db.shed.Close()
|
||||
|
|
|
|||
Loading…
Reference in a new issue