From 3fa09a99373881c559d19d8c17dbde87657e2e4e Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 23 May 2017 22:08:18 +0300 Subject: [PATCH] test: setup oom-callback for retry. --- test/test.cc | 23 +++++++++++++++++++++++ test/test.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/test/test.cc b/test/test.cc index 5fde326d..ad5141f6 100644 --- a/test/test.cc +++ b/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); diff --git a/test/test.h b/test/test.h index 43674d3e..441bc72c 100644 --- a/test/test.h +++ b/test/test.h @@ -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();