Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics (Database locking): Added counter #935

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added counter for db locking
freemanzMrojo committed Jan 10, 2025
commit b2462eb2b29a0e87a74938ece7331189e2c58952
2 changes: 2 additions & 0 deletions cmd/thor/node/node.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -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
}
8 changes: 4 additions & 4 deletions muxdb/muxdb.go
Original file line number Diff line number Diff line change
@@ -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
}
@@ -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 {
@@ -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{