LMDB: fix deadlock in resized detection

This commit is contained in:
Howard Chu 2021-09-19 21:12:27 +01:00
parent a39b1d56c8
commit 5f54dea4ec
No known key found for this signature in database
GPG key ID: FD2A70B44AB11BA7
2 changed files with 13 additions and 3 deletions

View file

@ -467,7 +467,12 @@ void mdb_txn_safe::allow_new_txns()
creation_gate.clear(); creation_gate.clear();
} }
void lmdb_resized(MDB_env *env) void mdb_txn_safe::increment_txns(int i)
{
num_active_txns += i;
}
void lmdb_resized(MDB_env *env, int isactive)
{ {
mdb_txn_safe::prevent_new_txns(); mdb_txn_safe::prevent_new_txns();
@ -478,7 +483,11 @@ void lmdb_resized(MDB_env *env)
mdb_env_info(env, &mei); mdb_env_info(env, &mei);
uint64_t old = mei.me_mapsize; uint64_t old = mei.me_mapsize;
if (isactive)
mdb_txn_safe::increment_txns(-1);
mdb_txn_safe::wait_no_active_txns(); mdb_txn_safe::wait_no_active_txns();
if (isactive)
mdb_txn_safe::increment_txns(1);
int result = mdb_env_set_mapsize(env, 0); int result = mdb_env_set_mapsize(env, 0);
if (result) if (result)
@ -496,7 +505,7 @@ inline int lmdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB
{ {
int res = mdb_txn_begin(env, parent, flags, txn); int res = mdb_txn_begin(env, parent, flags, txn);
if (res == MDB_MAP_RESIZED) { if (res == MDB_MAP_RESIZED) {
lmdb_resized(env); lmdb_resized(env, 1);
res = mdb_txn_begin(env, parent, flags, txn); res = mdb_txn_begin(env, parent, flags, txn);
} }
return res; return res;
@ -506,7 +515,7 @@ inline int lmdb_txn_renew(MDB_txn *txn)
{ {
int res = mdb_txn_renew(txn); int res = mdb_txn_renew(txn);
if (res == MDB_MAP_RESIZED) { if (res == MDB_MAP_RESIZED) {
lmdb_resized(mdb_txn_env(txn)); lmdb_resized(mdb_txn_env(txn), 0);
res = mdb_txn_renew(txn); res = mdb_txn_renew(txn);
} }
return res; return res;

View file

@ -154,6 +154,7 @@ struct mdb_txn_safe
static void prevent_new_txns(); static void prevent_new_txns();
static void wait_no_active_txns(); static void wait_no_active_txns();
static void allow_new_txns(); static void allow_new_txns();
static void increment_txns(int);
mdb_threadinfo* m_tinfo; mdb_threadinfo* m_tinfo;
MDB_txn* m_txn; MDB_txn* m_txn;