Skip to content

Commit

Permalink
added counter for db locking
Browse files Browse the repository at this point in the history
  • Loading branch information
freemanzMrojo committed Jan 10, 2025
1 parent 4b6a611 commit b2462eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmd/thor/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/vechain/thor/v2/consensus"
"github.com/vechain/thor/v2/log"
"github.com/vechain/thor/v2/logdb"
"github.com/vechain/thor/v2/muxdb"
"github.com/vechain/thor/v2/packer"
"github.com/vechain/thor/v2/state"
"github.com/vechain/thor/v2/thor"
Expand Down Expand Up @@ -235,6 +236,7 @@ func (n *Node) txStashLoop(ctx context.Context) {

db, err := leveldb.OpenFile(n.txStashPath, nil)
if err != nil {
muxdb.AddMetricsIfLocked(err, "open-file-tx-stash")
logger.Error("create tx stash", "err", err)
return
}
Expand Down
8 changes: 4 additions & 4 deletions muxdb/muxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type MuxDB struct {
}

// Adds metrics if the error is due to file/db lock.
func addMetricsIfLocked(err error, event string) {
func AddMetricsIfLocked(err error, event string) {
if err == nil {
return
}
Expand Down Expand Up @@ -102,10 +102,10 @@ func Open(path string, options *Options) (*MuxDB, error) {

// open leveldb
ldb, err := leveldb.OpenFile(path, &ldbOpts)
addMetricsIfLocked(err, "open-file")
AddMetricsIfLocked(err, "open-file")
if _, corrupted := err.(*dberrors.ErrCorrupted); corrupted {
ldb, err = leveldb.RecoverFile(path, &ldbOpts)
addMetricsIfLocked(err, "recover-file")
AddMetricsIfLocked(err, "recover-file")
}

if err != nil {
Expand Down Expand Up @@ -144,7 +144,7 @@ func Open(path string, options *Options) (*MuxDB, error) {
func NewMem() *MuxDB {
storage := storage.NewMemStorage()
ldb, err := leveldb.Open(storage, nil)
addMetricsIfLocked(err, "open-memory-backed-db")
AddMetricsIfLocked(err, "open-memory-backed-db")

engine := engine.NewLevelEngine(ldb)
return &MuxDB{
Expand Down

0 comments on commit b2462eb

Please sign in to comment.