mdbx: notify OOM-handler about end of loop.

Change-Id: I71d66e371df869560801e12b8b06c4f4cbf90e98
This commit is contained in:
Leo Yuriev 2016-05-07 03:43:36 +03:00
parent bfc6900b07
commit 14b3afdcff
2 changed files with 36 additions and 28 deletions

4
lmdb.h
View File

@ -1671,12 +1671,14 @@ int mdb_reader_check(MDB_env *env, int *dead);
int mdbx_txn_straggler(MDB_txn *txn, int *percent);
/** @brief A callback function for killing a laggard readers,
* called in case of MDB_MAP_FULL error.
* but also could waiting ones. Called in case of MDB_MAP_FULL error.
*
* @param[in] env An environment handle returned by #mdb_env_create().
* @param[in] pid pid of the reader process.
* @param[in] thread_id thread_id of the reader thread.
* @param[in] txn Transaction number on which stalled.
* @param[in] gap a lag from the last commited txn.
* @param[in] retry a retry number, less that zero for notify end of OOM-loop.
* @return -1 on failure (reader is not killed),
* 0 on a race condition (no such reader),
* 1 on success (reader was killed),

16
mdb.c
View File

@ -1990,13 +1990,14 @@ mdbx_oomkick(MDB_env *env, txnid_t oldest)
break;
snap = mdb_find_oldest(env, &reader);
if (oldest < snap)
if (oldest < snap || reader < 0) {
if (retry && env->me_oom_func) {
/* LY: notify end of oom-loop */
env->me_oom_func(env, 0, 0, oldest, snap - oldest, -retry);
}
return snap;
}
if (reader < 0)
return 0;
{
MDB_reader *r;
pthread_t tid;
pid_t pid;
@ -2025,8 +2026,13 @@ mdbx_oomkick(MDB_env *env, txnid_t oldest)
}
}
}
if (retry && env->me_oom_func) {
/* LY: notify end of oom-loop */
env->me_oom_func(env, 0, 0, oldest, 0, -retry);
}
#else
(void) oldest;
(void) mdb_reader_check(env, NULL);
#endif /* MDBX_MODE_ENABLED */
return mdb_find_oldest(env, NULL);