TEMP HACK to return memory to leveldb buffer pool

This commit is contained in:
Felix Lange 2016-10-19 22:49:31 +02:00
parent f2ae2f7eef
commit 0fcdcb950a
5 changed files with 17 additions and 0 deletions

View file

@ -1017,6 +1017,10 @@ func (db *DB) SizeOf(ranges []util.Range) (Sizes, error) {
return sizes, nil return sizes, nil
} }
func (db *DB) ReturnBuffer(b []byte) {
db.s.tops.bpool.Put(b)
}
// Close closes the DB. This will also releases any outstanding snapshot, // Close closes the DB. This will also releases any outstanding snapshot,
// abort any in-flight compaction and discard open transaction. // abort any in-flight compaction and discard open transaction.
// //

View file

@ -142,6 +142,10 @@ func (self *LDBDatabase) Get(key []byte) ([]byte, error) {
//return rle.Decompress(dat) //return rle.Decompress(dat)
} }
func (self *LDBDatabase) ReturnBuffer(b []byte) {
self.db.ReturnBuffer(b)
}
// Delete deletes the key from the queue and database // Delete deletes the key from the queue and database
func (self *LDBDatabase) Delete(key []byte) error { func (self *LDBDatabase) Delete(key []byte) error {
// Measure the database delete latency, if requested // Measure the database delete latency, if requested

View file

@ -22,6 +22,8 @@ type Database interface {
Delete(key []byte) error Delete(key []byte) error
Close() Close()
NewBatch() Batch NewBatch() Batch
ReturnBuffer([]byte)
} }
type Batch interface { type Batch interface {

View file

@ -62,6 +62,9 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) {
return nil, errors.New("not found") return nil, errors.New("not found")
} }
func (db *MemDatabase) ReturnBuffer(b []byte) {
}
func (db *MemDatabase) Keys() [][]byte { func (db *MemDatabase) Keys() [][]byte {
db.lock.RLock() db.lock.RLock()
defer db.lock.RUnlock() defer db.lock.RUnlock()

View file

@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/logger/glog"
"github.com/rcrowley/go-metrics" "github.com/rcrowley/go-metrics"
@ -453,6 +454,9 @@ func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
} }
} }
dec := mustDecodeNode(n, enc, t.cachegen) dec := mustDecodeNode(n, enc, t.cachegen)
if edb, ok := t.db.(*ethdb.LDBDatabase); ok {
edb.ReturnBuffer(enc)
}
return dec, nil return dec, nil
} }