mdbx: add trace info to open error (#2305)

* add stack info to open error

* add stack info to open error
This commit is contained in:
Alex Sharov 2021-07-06 01:53:11 +07:00 committed by GitHub
parent a68b5ba361
commit ea5abbe0b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -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{

View File

@ -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)