mdbx: more isolation MDBX/LMDB API.

This commit is contained in:
Leo Yuriev
2016-11-21 19:32:12 +03:00
parent 36b1ad02fb
commit aa4fd0ec76
4 changed files with 137 additions and 149 deletions

106
mdbx.h
View File

@@ -50,6 +50,11 @@
# define _GNU_SOURCE
#endif
/** @defgroup mdbx MDBX API
* @{
* @brief libmdbx - Extended version of LMDB
*/
#define mdb_version mdbx_version
#define mdb_strerror mdbx_strerror
#define mdb_env_create mdbx_env_create
@@ -61,7 +66,6 @@
#define mdb_env_copyfd2 mdbx_env_copyfd2
#define mdb_env_sync mdbx_env_sync
#define mdb_env_close mdbx_env_close
#define mdb_env_close_ex mdbx_env_close_ex
#define mdb_env_set_flags mdbx_env_set_flags
#define mdb_env_get_flags mdbx_env_get_flags
#define mdb_env_get_path mdbx_env_get_path
@@ -113,4 +117,104 @@
#include "./lmdb.h"
#ifdef __cplusplus
extern "C" {
#endif
int mdbx_env_open_ex(MDB_env *env, const char *path, unsigned flags, mode_t mode, int *exclusive);
int mdbx_env_stat(MDB_env *env, MDBX_stat *stat, size_t bytes);
int mdbx_stat(MDB_txn *txn, MDB_dbi dbi, MDBX_stat *stat, size_t bytes);
int mdbx_env_info(MDB_env *env, MDBX_envinfo *info, size_t bytes);
int mdbx_env_close_ex(MDB_env *env, int dont_sync);
/** @brief Set threshold to force flush the data buffers to disk,
* even of #MDB_NOSYNC, #MDB_NOMETASYNC and #MDB_MAPASYNC flags
* in the environment.
*
* Data is always written to disk when #mdb_txn_commit() is called,
* but the operating system may keep it buffered. LMDB always flushes
* the OS buffers upon commit as well, unless the environment was
* opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC.
*
* The default is 0, than mean no any threshold checked,
* and no additional flush will be made.
*
* @param[in] env An environment handle returned by #mdb_env_create()
* @param[in] bytes The size in bytes of summary changes
* when a synchronous flush would be made.
* @return A non-zero error value on failure and 0 on success.
*/
int mdbx_env_set_syncbytes(MDB_env *env, size_t bytes);
/** @brief Returns a lag of the reading.
*
* Returns an information for estimate how much given read-only
* transaction is lagging relative the to actual head.
*
* @param[in] txn A transaction handle returned by #mdb_txn_begin()
* @param[out] percent Percentage of page allocation in the database.
* @return Number of transactions committed after the given was started for read, or -1 on failure.
*/
int mdbx_txn_straggler(MDB_txn *txn, int *percent);
/** @brief A callback function for killing a laggard readers,
* 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),
* >1 on success (reader was SURE killed).
*/
typedef int (MDBX_oom_func)(MDB_env *env, int pid, void* thread_id, size_t txn, unsigned gap, int retry);
/** @brief Set the OOM callback.
*
* Callback will be called only on out-of-pages case for killing
* a laggard readers to allowing reclaiming of freeDB.
*
* @param[in] env An environment handle returned by #mdb_env_create().
* @param[in] oomfunc A #MDBX_oom_func function or NULL to disable.
*/
void mdbx_env_set_oomfunc(MDB_env *env, MDBX_oom_func *oom_func);
/** @brief Get the current oom_func callback.
*
* Callback will be called only on out-of-pages case for killing
* a laggard readers to allowing reclaiming of freeDB.
*
* @param[in] env An environment handle returned by #mdb_env_create().
* @return A #MDBX_oom_func function or NULL if disabled.
*/
MDBX_oom_func* mdbx_env_get_oomfunc(MDB_env *env);
#define MDBX_DBG_ASSERT 1
#define MDBX_DBG_PRINT 2
#define MDBX_DBG_TRACE 4
#define MDBX_DBG_EXTRA 8
#define MDBX_DBG_AUDIT 16
#define MDBX_DBG_EDGE 32
/* LY: a "don't touch" value */
#define MDBX_DBG_DNT (-1L)
typedef void MDBX_debug_func(int type, const char *function, int line,
const char *msg, va_list args);
int mdbx_setup_debug(int flags, MDBX_debug_func* logger, long edge_txn);
typedef int MDBX_pgvisitor_func(size_t pgno, unsigned pgnumber, void* ctx,
const char* dbi, const char *type, int nentries,
int payload_bytes, int header_bytes, int unused_bytes);
int mdbx_env_pgwalk(MDB_txn *txn, MDBX_pgvisitor_func* visitor, void* ctx);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* _MDBX_H_ */