From 4e386be914e098849594be58805a8ebc2c80d002 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Fri, 18 Oct 2019 23:16:12 +0300 Subject: [PATCH] mdbx: don't hold dbi-lock during tree deletion inside mdbx_drop(). Change-Id: I29824271ba09a4443196bc1207279a257a8e26c0 --- src/elements/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/elements/core.c b/src/elements/core.c index 0698b07b..65d261cd 100644 --- a/src/elements/core.c +++ b/src/elements/core.c @@ -14350,13 +14350,6 @@ int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del) { if (unlikely(rc != MDBX_SUCCESS)) return rc; - MDBX_env *env = txn->mt_env; - rc = mdbx_fastmutex_acquire(&env->me_dbi_lock); - if (unlikely(rc != MDBX_SUCCESS)) { - mdbx_cursor_close(mc); - return rc; - } - if (unlikely(!TXN_DBI_EXIST(txn, dbi, DB_USRVALID))) { rc = MDBX_EINVAL; goto bailout; @@ -14377,9 +14370,17 @@ int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del) { /* Can't delete the main DB */ if (del && dbi >= CORE_DBS) { rc = mdbx_del0(txn, MAIN_DBI, &mc->mc_dbx->md_name, NULL, F_SUBDATA); - if (likely(!rc)) { + if (likely(rc == MDBX_SUCCESS)) { txn->mt_dbflags[dbi] = DB_STALE; + MDBX_env *env = txn->mt_env; + rc = mdbx_fastmutex_acquire(&env->me_dbi_lock); + if (unlikely(rc != MDBX_SUCCESS)) { + txn->mt_flags |= MDBX_TXN_ERROR; + goto bailout; + } mdbx_dbi_close_locked(env, dbi); + mdbx_ensure(env, + mdbx_fastmutex_release(&env->me_dbi_lock) == MDBX_SUCCESS); } else { txn->mt_flags |= MDBX_TXN_ERROR; } @@ -14398,7 +14399,6 @@ int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, int del) { bailout: mdbx_cursor_close(mc); - mdbx_ensure(env, mdbx_fastmutex_release(&env->me_dbi_lock) == MDBX_SUCCESS); return rc; }