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); int mdbx_txn_straggler(MDB_txn *txn, int *percent);
/** @brief A callback function for killing a laggard readers, /** @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] env An environment handle returned by #mdb_env_create().
* @param[in] pid pid of the reader process. * @param[in] pid pid of the reader process.
* @param[in] thread_id thread_id of the reader thread. * @param[in] thread_id thread_id of the reader thread.
* @param[in] txn Transaction number on which stalled. * @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), * @return -1 on failure (reader is not killed),
* 0 on a race condition (no such reader), * 0 on a race condition (no such reader),
* 1 on success (reader was killed), * 1 on success (reader was killed),

60
mdb.c
View File

@ -1990,43 +1990,49 @@ mdbx_oomkick(MDB_env *env, txnid_t oldest)
break; break;
snap = mdb_find_oldest(env, &reader); 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; return snap;
}
if (reader < 0) MDB_reader *r;
return 0; pthread_t tid;
pid_t pid;
int rc;
{ if (!env->me_oom_func)
MDB_reader *r; break;
pthread_t tid;
pid_t pid;
int rc;
if (!env->me_oom_func) r = &env->me_txns->mti_readers[ reader ];
break; pid = r->mr_pid;
tid = r->mr_tid;
if (r->mr_txnid != oldest || pid <= 0)
continue;
r = &env->me_txns->mti_readers[ reader ]; rc = env->me_oom_func(env, pid, (void*) tid, oldest,
pid = r->mr_pid; mdb_meta_head_w(env)->mm_txnid - oldest, retry);
tid = r->mr_tid; if (rc < 0)
if (r->mr_txnid != oldest || pid <= 0) break;
continue;
rc = env->me_oom_func(env, pid, (void*) tid, oldest, if (rc) {
mdb_meta_head_w(env)->mm_txnid - oldest, retry); r->mr_txnid = ~(txnid_t)0;
if (rc < 0) if (rc > 1) {
break; r->mr_tid = 0;
r->mr_pid = 0;
if (rc) { mdbx_coherent_barrier();
r->mr_txnid = ~(txnid_t)0;
if (rc > 1) {
r->mr_tid = 0;
r->mr_pid = 0;
mdbx_coherent_barrier();
}
} }
} }
} }
if (retry && env->me_oom_func) {
/* LY: notify end of oom-loop */
env->me_oom_func(env, 0, 0, oldest, 0, -retry);
}
#else #else
(void) oldest;
(void) mdb_reader_check(env, NULL); (void) mdb_reader_check(env, NULL);
#endif /* MDBX_MODE_ENABLED */ #endif /* MDBX_MODE_ENABLED */
return mdb_find_oldest(env, NULL); return mdb_find_oldest(env, NULL);