mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:24:13 +08:00
test: setup oom-callback for retry.
This commit is contained in:
parent
2c43997026
commit
3fa09a9937
23
test/test.cc
23
test/test.cc
@ -90,6 +90,25 @@ static void mdbx_debug_logger(int type, const char *function, int line,
|
||||
abort();
|
||||
}
|
||||
|
||||
int testcase::oom_callback(MDB_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
unsigned gap, int retry) {
|
||||
|
||||
testcase *self = (testcase *)mdbx_env_get_userctx(env);
|
||||
|
||||
if (retry == 0)
|
||||
log_notice("oom_callback: waitfor pid %u, thread %" PRIuPTR
|
||||
", txn #%" PRIu64 ", gap %d",
|
||||
pid, (size_t)tid, txn, gap);
|
||||
|
||||
if (self->should_continue()) {
|
||||
osal_yield();
|
||||
osal_udelay(retry * 100);
|
||||
return 1 /* always retry */;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void testcase::db_prepare() {
|
||||
log_trace(">> db_prepare");
|
||||
assert(!db_guard);
|
||||
@ -122,6 +141,10 @@ void testcase::db_prepare() {
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
failure_perror("mdbx_env_set_maxdbs()", rc);
|
||||
|
||||
rc = mdbx_env_set_oomfunc(env, testcase::oom_callback);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
failure_perror("mdbx_env_set_oomfunc()", rc);
|
||||
|
||||
rc = mdbx_env_set_mapsize(env, (size_t)config.params.size);
|
||||
if (unlikely(rc != MDB_SUCCESS))
|
||||
failure_perror("mdbx_env_set_mapsize()", rc);
|
||||
|
@ -96,6 +96,9 @@ protected:
|
||||
mdbx_canary canary;
|
||||
} last;
|
||||
|
||||
static int oom_callback(MDB_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
unsigned gap, int retry);
|
||||
|
||||
void db_prepare();
|
||||
void db_open();
|
||||
void db_close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user