diff options
author | Viktor TrĂ³n <viktor.tron@gmail.com> | 2018-06-22 05:00:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-22 05:00:43 +0800 |
commit | eaff89291ce998ba4bf9b9816ca8a15c8b85f440 (patch) | |
tree | c77d7a06627a1a7f578d0fec8e39788e66672e53 /swarm/storage/database.go | |
parent | d926bf2c7e3182d694c15829a37a0ca7331cd03c (diff) | |
parent | e187711c6545487d4cac3701f0f506bb536234e2 (diff) | |
download | dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.tar dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.tar.gz dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.tar.bz2 dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.tar.lz dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.tar.xz dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.tar.zst dexon-eaff89291ce998ba4bf9b9816ca8a15c8b85f440.zip |
Merge pull request #17041 from ethersphere/swarm-network-rewrite-merge
Swarm POC3 - happy solstice
Diffstat (limited to 'swarm/storage/database.go')
-rw-r--r-- | swarm/storage/database.go | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/swarm/storage/database.go b/swarm/storage/database.go index f2ceb94e4..3b5d003de 100644 --- a/swarm/storage/database.go +++ b/swarm/storage/database.go @@ -22,6 +22,7 @@ package storage import ( "fmt" + "github.com/ethereum/go-ethereum/metrics" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/opt" @@ -45,27 +46,31 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) { return database, nil } -func (self *LDBDatabase) Put(key []byte, value []byte) { - err := self.db.Put(key, value, nil) +func (db *LDBDatabase) Put(key []byte, value []byte) { + metrics.GetOrRegisterCounter("ldbdatabase.put", nil).Inc(1) + + err := db.db.Put(key, value, nil) if err != nil { fmt.Println("Error put", err) } } -func (self *LDBDatabase) Get(key []byte) ([]byte, error) { - dat, err := self.db.Get(key, nil) +func (db *LDBDatabase) Get(key []byte) ([]byte, error) { + metrics.GetOrRegisterCounter("ldbdatabase.get", nil).Inc(1) + + dat, err := db.db.Get(key, nil) if err != nil { return nil, err } return dat, nil } -func (self *LDBDatabase) Delete(key []byte) error { - return self.db.Delete(key, nil) +func (db *LDBDatabase) Delete(key []byte) error { + return db.db.Delete(key, nil) } -func (self *LDBDatabase) LastKnownTD() []byte { - data, _ := self.Get([]byte("LTD")) +func (db *LDBDatabase) LastKnownTD() []byte { + data, _ := db.Get([]byte("LTD")) if len(data) == 0 { data = []byte{0x0} @@ -74,15 +79,19 @@ func (self *LDBDatabase) LastKnownTD() []byte { return data } -func (self *LDBDatabase) NewIterator() iterator.Iterator { - return self.db.NewIterator(nil, nil) +func (db *LDBDatabase) NewIterator() iterator.Iterator { + metrics.GetOrRegisterCounter("ldbdatabase.newiterator", nil).Inc(1) + + return db.db.NewIterator(nil, nil) } -func (self *LDBDatabase) Write(batch *leveldb.Batch) error { - return self.db.Write(batch, nil) +func (db *LDBDatabase) Write(batch *leveldb.Batch) error { + metrics.GetOrRegisterCounter("ldbdatabase.write", nil).Inc(1) + + return db.db.Write(batch, nil) } -func (self *LDBDatabase) Close() { +func (db *LDBDatabase) Close() { // Close the leveldb database - self.db.Close() + db.db.Close() } |