swarm/storage/localstore: call writeGCSize on DB Close

This commit is contained in:
Janos Guljas 2018-12-19 14:42:12 +01:00
parent b5a0fd285f
commit 4fca004e86
2 changed files with 11 additions and 1 deletions

View file

@ -278,7 +278,12 @@ func TestDB_gcSize(t *testing.T) {
}
}
err = db.Close()
// DB.Close writes gc size to disk, so
// Instead calling Close, simulate database shutdown
// without it.
close(db.close)
db.updateGCWG.Wait()
err = db.shed.Close()
if err != nil {
t.Fatal(err)
}

View file

@ -21,8 +21,10 @@ import (
"encoding/hex"
"errors"
"sync"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/swarm/shed"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/swarm/storage/mock"
@ -344,6 +346,9 @@ func New(path string, baseKey []byte, o *Options) (db *DB, err error) {
func (db *DB) Close() (err error) {
close(db.close)
db.updateGCWG.Wait()
if err := db.writeGCSize(atomic.LoadInt64(&db.gcSize)); err != nil {
log.Error("localstore: write gc size", "err", err)
}
return db.shed.Close()
}