diff --git a/ethdb/kv/kv_mdbx.go b/ethdb/kv/kv_mdbx.go index b8d181337..08716a4b4 100644 --- a/ethdb/kv/kv_mdbx.go +++ b/ethdb/kv/kv_mdbx.go @@ -169,7 +169,7 @@ func (opts MdbxOpts) Open() (ethdb.RwKV, error) { err = env.Open(opts.path, opts.flags, 0664) if err != nil { - return nil, fmt.Errorf("%w, path: %s", err, opts.path) + return nil, fmt.Errorf("%w, label: %s, trace: %s", err, opts.label.String(), debug.Callers(10)) } defaultDirtyPagesLimit, err := env.GetOption(mdbx.OptTxnDpLimit) @@ -327,7 +327,7 @@ func (db *MdbxKV) Close() { db.log.Warn("failed to remove in-mem db file", "err", err) } } else { - db.log.Info("database closed (MDBX)") + db.log.Info("database closed (MDBX)", "label", db.opts.label.String(), "exclusive", db.opts.flags&mdbx.Exclusive != 0) } } @@ -343,7 +343,7 @@ func (db *MdbxKV) BeginRo(_ context.Context) (txn ethdb.Tx, err error) { tx, err := db.env.BeginTxn(nil, mdbx.Readonly) if err != nil { - return nil, fmt.Errorf("%w, trace: %s", err, debug.Callers(10)) + return nil, fmt.Errorf("%w, label: %s, trace: %s", err, db.opts.label.String(), debug.Callers(10)) } tx.RawRead = true return &MdbxTx{ @@ -367,7 +367,7 @@ func (db *MdbxKV) BeginRw(_ context.Context) (txn ethdb.RwTx, err error) { tx, err := db.env.BeginTxn(nil, 0) if err != nil { runtime.UnlockOSThread() // unlock only in case of error. normal flow is "defer .Rollback()" - return nil, fmt.Errorf("%w, trace: %s", err, debug.Callers(10)) + return nil, fmt.Errorf("%w, lable: %s, trace: %s", err, db.opts.label.String(), debug.Callers(10)) } tx.RawRead = true return &MdbxTx{ diff --git a/ethdb/kv_interface.go b/ethdb/kv_interface.go index 41a87c19f..416bc1a4f 100644 --- a/ethdb/kv_interface.go +++ b/ethdb/kv_interface.go @@ -72,6 +72,19 @@ const ( Sentry Label = 2 ) +func (l Label) String() string { + switch l { + case Chain: + return "chaindata" + case TxPool: + return "txpool" + case Sentry: + return "sentry" + default: + return "unknown" + } +} + type Has interface { // Has indicates whether a key exists in the database. Has(bucket string, key []byte) (bool, error)