aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/database.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/storage/database.go')
-rw-r--r--swarm/storage/database.go37
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()
}