diff --git a/mdb.c b/mdb.c index cee98c96..c2eb13be 100644 --- a/mdb.c +++ b/mdb.c @@ -2862,10 +2862,10 @@ mdb_txn_renew(MDB_txn *txn) { int rc; - if (!txn || txn->mt_dbxs) /* A reset txn has mt_dbxs==NULL */ + if (unlikely(!txn || !F_ISSET(txn->mt_flags, MDB_TXN_RDONLY|MDB_TXN_FINISHED))) return EINVAL; - if (txn->mt_env->me_flags & MDB_FATAL_ERROR) { + if (unlikely(txn->mt_env->me_flags & MDB_FATAL_ERROR)) { mdb_debug("environment had fatal error, must shutdown!"); return MDB_PANIC; } @@ -2919,6 +2919,7 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned flags, MDB_txn **ret) mdb_debug("calloc: %s", strerror(errno)); return ENOMEM; } + txn->mt_dbxs = env->me_dbxs; /* static */ txn->mt_dbs = (MDB_db *) ((char *)txn + tsize); txn->mt_dbflags = (unsigned char *)txn + size - env->me_maxdbs; txn->mt_flags = flags; @@ -2945,7 +2946,6 @@ mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned flags, MDB_txn **ret) parent->mt_child = txn; txn->mt_parent = parent; txn->mt_numdbs = parent->mt_numdbs; - txn->mt_dbxs = parent->mt_dbxs; memcpy(txn->mt_dbs, parent->mt_dbs, txn->mt_numdbs * sizeof(MDB_db)); /* Copy parent's mt_dbflags, but clear DB_NEW */ for (i=0; imt_numdbs; i++) @@ -3082,7 +3082,7 @@ mdb_txn_end(MDB_txn *txn, unsigned mode) mdb_coherent_barrier(); txn->mt_numdbs = 0; /* prevent further DBI activity */ txn->mt_flags |= MDB_TXN_FINISHED; - txn->mt_dbxs = NULL; /* mark txn as reset */ + } else if (!F_ISSET(txn->mt_flags, MDB_TXN_FINISHED)) { pgno_t *pghead = env->me_pghead;