diff options
Diffstat (limited to 'swarm/storage/localstore/mode_has.go')
-rw-r--r-- | swarm/storage/localstore/mode_has.go | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/swarm/storage/localstore/mode_has.go b/swarm/storage/localstore/mode_has.go index 90feaceef..a70ee31b2 100644 --- a/swarm/storage/localstore/mode_has.go +++ b/swarm/storage/localstore/mode_has.go @@ -17,23 +17,23 @@ package localstore import ( + "context" + "time" + + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/swarm/chunk" ) -// Hasser provides Has method to retrieve Chunks -// from database. -type Hasser struct { - db *DB -} +// Has returns true if the chunk is stored in database. +func (db *DB) Has(ctx context.Context, addr chunk.Address) (bool, error) { + metricName := "localstore.Has" -// NewHasser returns a new Hasser on database. -func (db *DB) NewHasser() *Hasser { - return &Hasser{ - db: db, - } -} + metrics.GetOrRegisterCounter(metricName, nil).Inc(1) + defer totalTimeMetric(metricName, time.Now()) -// Has returns true if the chunk is stored in database. -func (h *Hasser) Has(addr chunk.Address) (bool, error) { - return h.db.retrievalDataIndex.Has(addressToItem(addr)) + has, err := db.retrievalDataIndex.Has(addressToItem(addr)) + if err != nil { + metrics.GetOrRegisterCounter(metricName+".error", nil).Inc(1) + } + return has, err } |