mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-31 11:18:21 +08:00
mdbx: Merge branch 'devel'.
This commit is contained in:
commit
6191b46ca1
4
lmdb.h
4
lmdb.h
@ -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),
|
||||||
|
36
mdb.c
36
mdb.c
@ -1990,13 +1990,14 @@ 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)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
{
|
|
||||||
MDB_reader *r;
|
MDB_reader *r;
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
pid_t pid;
|
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
|
#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);
|
||||||
@ -5013,6 +5019,7 @@ mdb_env_close0(MDB_env *env)
|
|||||||
|
|
||||||
if (!(env->me_flags & MDB_ENV_ACTIVE))
|
if (!(env->me_flags & MDB_ENV_ACTIVE))
|
||||||
return;
|
return;
|
||||||
|
env->me_flags &= ~MDB_ENV_ACTIVE;
|
||||||
|
|
||||||
/* Doing this here since me_dbxs may not exist during mdb_env_close */
|
/* Doing this here since me_dbxs may not exist during mdb_env_close */
|
||||||
if (env->me_dbxs) {
|
if (env->me_dbxs) {
|
||||||
@ -5032,7 +5039,12 @@ mdb_env_close0(MDB_env *env)
|
|||||||
mdb_midl_free(env->me_free_pgs);
|
mdb_midl_free(env->me_free_pgs);
|
||||||
|
|
||||||
if (env->me_flags & MDB_ENV_TXKEY) {
|
if (env->me_flags & MDB_ENV_TXKEY) {
|
||||||
|
struct MDB_rthc *rthc = pthread_getspecific(env->me_txkey);
|
||||||
|
if (rthc && pthread_setspecific(env->me_txkey, NULL) == 0) {
|
||||||
|
mdb_env_reader_destr(rthc);
|
||||||
|
}
|
||||||
pthread_key_delete(env->me_txkey);
|
pthread_key_delete(env->me_txkey);
|
||||||
|
env->me_flags &= ~MDB_ENV_TXKEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env->me_map) {
|
if (env->me_map) {
|
||||||
@ -5077,8 +5089,6 @@ mdb_env_close0(MDB_env *env)
|
|||||||
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
if (env->me_lfd != INVALID_HANDLE_VALUE) {
|
||||||
(void) close(env->me_lfd);
|
(void) close(env->me_lfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
env->me_flags &= ~(MDB_ENV_ACTIVE|MDB_ENV_TXKEY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ! MDBX_MODE_ENABLED
|
#if ! MDBX_MODE_ENABLED
|
||||||
@ -7317,10 +7327,10 @@ mdb_node_add(MDB_cursor *mc, indx_t indx,
|
|||||||
node_size += key->mv_size;
|
node_size += key->mv_size;
|
||||||
if (IS_LEAF(mp)) {
|
if (IS_LEAF(mp)) {
|
||||||
mdb_cassert(mc, key && data);
|
mdb_cassert(mc, key && data);
|
||||||
if (F_ISSET(flags, F_BIGDATA)) {
|
if (unlikely(F_ISSET(flags, F_BIGDATA))) {
|
||||||
/* Data already on overflow page. */
|
/* Data already on overflow page. */
|
||||||
node_size += sizeof(pgno_t);
|
node_size += sizeof(pgno_t);
|
||||||
} else if (node_size + data->mv_size > mc->mc_txn->mt_env->me_nodemax) {
|
} else if (unlikely(node_size + data->mv_size > mc->mc_txn->mt_env->me_nodemax)) {
|
||||||
int ovpages = OVPAGES(data->mv_size, mc->mc_txn->mt_env->me_psize);
|
int ovpages = OVPAGES(data->mv_size, mc->mc_txn->mt_env->me_psize);
|
||||||
int rc;
|
int rc;
|
||||||
/* Put data on overflow page. */
|
/* Put data on overflow page. */
|
||||||
@ -7368,19 +7378,19 @@ update:
|
|||||||
|
|
||||||
if (IS_LEAF(mp)) {
|
if (IS_LEAF(mp)) {
|
||||||
ndata = NODEDATA(node);
|
ndata = NODEDATA(node);
|
||||||
if (ofp == NULL) {
|
if (unlikely(ofp == NULL)) {
|
||||||
if (F_ISSET(flags, F_BIGDATA))
|
if (unlikely(F_ISSET(flags, F_BIGDATA)))
|
||||||
memcpy(ndata, data->mv_data, sizeof(pgno_t));
|
memcpy(ndata, data->mv_data, sizeof(pgno_t));
|
||||||
else if (F_ISSET(flags, MDB_RESERVE))
|
else if (F_ISSET(flags, MDB_RESERVE))
|
||||||
data->mv_data = ndata;
|
data->mv_data = ndata;
|
||||||
else
|
else if (likely(ndata != data->mv_data))
|
||||||
memcpy(ndata, data->mv_data, data->mv_size);
|
memcpy(ndata, data->mv_data, data->mv_size);
|
||||||
} else {
|
} else {
|
||||||
memcpy(ndata, &ofp->mp_pgno, sizeof(pgno_t));
|
memcpy(ndata, &ofp->mp_pgno, sizeof(pgno_t));
|
||||||
ndata = PAGEDATA(ofp);
|
ndata = PAGEDATA(ofp);
|
||||||
if (F_ISSET(flags, MDB_RESERVE))
|
if (F_ISSET(flags, MDB_RESERVE))
|
||||||
data->mv_data = ndata;
|
data->mv_data = ndata;
|
||||||
else
|
else if (likely(ndata != data->mv_data))
|
||||||
memcpy(ndata, data->mv_data, data->mv_size);
|
memcpy(ndata, data->mv_data, data->mv_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ int main(int argc, char *argv[])
|
|||||||
printf(" Used now: %zu %.1f%%\n", value, value / percent);
|
printf(" Used now: %zu %.1f%%\n", value, value / percent);
|
||||||
|
|
||||||
value = pages;
|
value = pages;
|
||||||
printf(" Free pages: %zu %.1f%%\n", value, value / percent);
|
printf(" Unallocated: %zu %.1f%%\n", value, value / percent);
|
||||||
|
|
||||||
value = pages - reclaimable;
|
value = pages - reclaimable;
|
||||||
printf(" Detained: %zu %.1f%%\n", value, value / percent);
|
printf(" Detained: %zu %.1f%%\n", value, value / percent);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user