Loading...
Searching...
No Matches
lmdb.h
Go to the documentation of this file.
#ifndef _LMDB_H_
#define _LMDB_H_
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
typedef int mdb_mode_t;
#else
typedef mode_t mdb_mode_t;
#endif
#ifdef _WIN32
typedef void *mdb_filehandle_t;
#else
typedef int mdb_filehandle_t;
#endif
#define MDB_VERSION_MAJOR 0
#define MDB_VERSION_MINOR 9
#define MDB_VERSION_PATCH 35
#define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
#define MDB_VERSION_FULL \
MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)
#define MDB_VERSION_DATE "Jan 27, 2026"
#define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
#define MDB_VERFOO(a,b,c,d) MDB_VERSTR(a,b,c,d)
#define MDB_VERSION_STRING \
MDB_VERFOO(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH,MDB_VERSION_DATE)
typedef struct MDB_env MDB_env;
typedef struct MDB_txn MDB_txn;
typedef unsigned int MDB_dbi;
typedef struct MDB_cursor MDB_cursor;
typedef struct MDB_val {
size_t mv_size;
void *mv_data;
} MDB_val;
typedef int (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *relctx);
#define MDB_FIXEDMAP 0x01
#define MDB_NOSUBDIR 0x4000
#define MDB_NOSYNC 0x10000
#define MDB_RDONLY 0x20000
#define MDB_NOMETASYNC 0x40000
#define MDB_WRITEMAP 0x80000
#define MDB_MAPASYNC 0x100000
#define MDB_NOTLS 0x200000
#define MDB_NOLOCK 0x400000
#define MDB_NORDAHEAD 0x800000
#define MDB_NOMEMINIT 0x1000000
#define MDB_REVERSEKEY 0x02
#define MDB_DUPSORT 0x04
#define MDB_INTEGERKEY 0x08
#define MDB_DUPFIXED 0x10
#define MDB_INTEGERDUP 0x20
#define MDB_REVERSEDUP 0x40
#define MDB_CREATE 0x40000
#define MDB_NOOVERWRITE 0x10
#define MDB_NODUPDATA 0x20
#define MDB_CURRENT 0x40
#define MDB_RESERVE 0x10000
#define MDB_APPEND 0x20000
#define MDB_APPENDDUP 0x40000
#define MDB_MULTIPLE 0x80000
/* @} */
#define MDB_CP_COMPACT 0x01
/* @} */
typedef enum MDB_cursor_op {
MDB_FIRST,
MDB_FIRST_DUP,
MDB_GET_BOTH,
MDB_GET_BOTH_RANGE,
MDB_GET_CURRENT,
MDB_GET_MULTIPLE,
MDB_LAST,
MDB_LAST_DUP,
MDB_NEXT,
MDB_NEXT_DUP,
MDB_NEXT_MULTIPLE,
MDB_NEXT_NODUP,
MDB_PREV,
MDB_PREV_DUP,
MDB_PREV_NODUP,
MDB_SET,
MDB_SET_KEY,
MDB_SET_RANGE,
MDB_PREV_MULTIPLE
} MDB_cursor_op;
#define MDB_SUCCESS 0
#define MDB_KEYEXIST (-30799)
#define MDB_NOTFOUND (-30798)
#define MDB_PAGE_NOTFOUND (-30797)
#define MDB_CORRUPTED (-30796)
#define MDB_PANIC (-30795)
#define MDB_VERSION_MISMATCH (-30794)
#define MDB_INVALID (-30793)
#define MDB_MAP_FULL (-30792)
#define MDB_DBS_FULL (-30791)
#define MDB_READERS_FULL (-30790)
#define MDB_TLS_FULL (-30789)
#define MDB_TXN_FULL (-30788)
#define MDB_CURSOR_FULL (-30787)
#define MDB_PAGE_FULL (-30786)
#define MDB_MAP_RESIZED (-30785)
#define MDB_INCOMPATIBLE (-30784)
#define MDB_BAD_RSLOT (-30783)
#define MDB_BAD_TXN (-30782)
#define MDB_BAD_VALSIZE (-30781)
#define MDB_BAD_DBI (-30780)
#define MDB_LAST_ERRCODE MDB_BAD_DBI
typedef struct MDB_stat {
unsigned int ms_psize;
unsigned int ms_depth;
size_t ms_branch_pages;
size_t ms_leaf_pages;
size_t ms_overflow_pages;
size_t ms_entries;
} MDB_stat;
typedef struct MDB_envinfo {
void *me_mapaddr;
size_t me_mapsize;
size_t me_last_pgno;
size_t me_last_txnid;
unsigned int me_maxreaders;
unsigned int me_numreaders;
} MDB_envinfo;
char *mdb_version(int *major, int *minor, int *patch);
char *mdb_strerror(int err);
int mdb_env_create(MDB_env **env);
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode);
int mdb_env_copy(MDB_env *env, const char *path);
int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd);
int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags);
int mdb_env_copyfd2(MDB_env *env, mdb_filehandle_t fd, unsigned int flags);
int mdb_env_stat(MDB_env *env, MDB_stat *stat);
int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
int mdb_env_sync(MDB_env *env, int force);
void mdb_env_close(MDB_env *env);
int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff);
int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
int mdb_env_get_path(MDB_env *env, const char **path);
int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
int mdb_env_set_mapsize(MDB_env *env, size_t size);
int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers);
int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers);
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
int mdb_env_get_maxkeysize(MDB_env *env);
int mdb_env_set_userctx(MDB_env *env, void *ctx);
void *mdb_env_get_userctx(MDB_env *env);
typedef void MDB_assert_func(MDB_env *env, const char *msg);
int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func);
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn);
MDB_env *mdb_txn_env(MDB_txn *txn);
size_t mdb_txn_id(MDB_txn *txn);
int mdb_txn_commit(MDB_txn *txn);
void mdb_txn_abort(MDB_txn *txn);
void mdb_txn_reset(MDB_txn *txn);
int mdb_txn_renew(MDB_txn *txn);
#define mdb_open(txn,name,flags,dbi) mdb_dbi_open(txn,name,flags,dbi)
#define mdb_close(env,dbi) mdb_dbi_close(env,dbi)
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi);
int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat);
int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags);
void mdb_dbi_close(MDB_env *env, MDB_dbi dbi);
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del);
int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel);
int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data,
unsigned int flags);
int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor);
void mdb_cursor_close(MDB_cursor *cursor);
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor);
MDB_txn *mdb_cursor_txn(MDB_cursor *cursor);
MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor);
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
MDB_cursor_op op);
int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
unsigned int flags);
int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
int mdb_cursor_count(MDB_cursor *cursor, size_t *countp);
int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
int mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
typedef int (MDB_msg_func)(const char *msg, void *ctx);
int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx);
int mdb_reader_check(MDB_env *env, int *dead);
#ifdef __cplusplus
}
#endif
#endif /* _LMDB_H_ */
MDB_cursor
Opaque structure for navigating through a database.
Definition mdb.c:1231
MDB_env
Opaque structure for a database environment.
Definition mdb.c:1306
MDB_txn
Opaque structure for a transaction handle.
Definition mdb.c:1131
mdb_txn_reset
void mdb_txn_reset(MDB_txn *txn)
Reset a read-only transaction.
Definition mdb.c:3120
MDB_cursor_op
MDB_cursor_op
Cursor Get operations.
Definition lmdb.h:366
mdb_env_info
int mdb_env_info(MDB_env *env, MDB_envinfo *stat)
Return information about the LMDB environment.
Definition mdb.c:9831
MDB_msg_func
int MDB_msg_func(const char *msg, void *ctx)
A callback function used to print a message from the library.
Definition lmdb.h:1577
mdb_cursor_put
int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Store by cursor.
Definition mdb.c:7164
mdb_cursor_del
int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags)
Delete current key/data pair.
Definition mdb.c:7280
mdb_env_get_flags
int mdb_env_get_flags(MDB_env *env, unsigned int *flags)
Get environment flags.
Definition mdb.c:9743
mdb_cursor_dbi
MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor)
Return the cursor's database handle.
Definition mdb.c:7865
mdb_env_open
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
Open an environment handle.
Definition mdb.c:5054
mdb_reader_check
int mdb_reader_check(MDB_env *env, int *dead)
Check for stale entries in the reader lock table.
Definition mdb.c:10309
mdb_env_copy2
int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
Copy an LMDB environment to the specified path, with options.
Definition mdb.c:9705
mdb_cursor_count
int mdb_cursor_count(MDB_cursor *cursor, size_t *countp)
Return count of duplicates for current key.
Definition mdb.c:7804
mdb_env_close
void mdb_env_close(MDB_env *env)
Close the environment and release the memory map.
Definition mdb.c:5252
mdb_env_copyfd
int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd)
Copy an LMDB environment to the specified file descriptor.
mdb_cursor_get
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
Definition mdb.c:6410
mdb_put
int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags)
Store items into a database.
Definition mdb.c:9146
mdb_env_copyfd2
int mdb_env_copyfd2(MDB_env *env, mdb_filehandle_t fd, unsigned int flags)
Copy an LMDB environment to the specified file descriptor, with options.
mdb_dbi_close
void mdb_dbi_close(MDB_env *env, MDB_dbi dbi)
Close a database handle. Normally unnecessary. Use with care:
Definition mdb.c:10011
mdb_env_copy
int mdb_env_copy(MDB_env *env, const char *path)
Copy an LMDB environment to the specified path.
Definition mdb.c:9725
mdb_set_compare
int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Set a custom key comparison function for a database.
Definition mdb.c:10188
mdb_set_relfunc
int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel)
Set a relocation function for a MDB_FIXEDMAP database.
Definition mdb.c:10206
mdb_txn_renew
int mdb_txn_renew(MDB_txn *txn)
Renew a read-only transaction.
Definition mdb.c:2881
mdb_env_set_assert
int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func)
Definition mdb.c:9768
mdb_env_get_userctx
void * mdb_env_get_userctx(MDB_env *env)
Get the application information associated with the MDB_env.
Definition mdb.c:9762
mdb_env_get_maxreaders
int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers)
Get the maximum number of threads/reader slots for the environment.
Definition mdb.c:4207
mdb_txn_abort
void mdb_txn_abort(MDB_txn *txn)
Abandon all the operations of the transaction instead of saving them.
Definition mdb.c:3145
mdb_set_relctx
int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx)
Set a context pointer for a MDB_FIXEDMAP database's relocation function.
Definition mdb.c:10215
mdb_env_set_flags
int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff)
Set environment flags.
Definition mdb.c:9731
mdb_txn_commit
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
Definition mdb.c:3756
mdb_reader_list
int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx)
Dump the entries in the reader lock table.
Definition mdb.c:10231
mdb_env_sync
int mdb_env_sync(MDB_env *env, int force)
Flush the data buffers to disk.
Definition mdb.c:2577
mdb_get
int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Get items from a database.
Definition mdb.c:5879
MDB_assert_func
void MDB_assert_func(MDB_env *env, const char *msg)
A callback function for most LMDB assert() failures, called before printing the message and aborting.
Definition lmdb.h:928
mdb_dbi_flags
int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
Retrieve the DB flags for a database handle.
Definition mdb.c:10028
mdb_strerror
char * mdb_strerror(int err)
Return a string describing a given error code.
Definition mdb.c:1529
mdb_cursor_open
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.
Definition mdb.c:7752
mdb_env_set_mapsize
int mdb_env_set_mapsize(MDB_env *env, size_t size)
Set the size of the memory map to use for this environment.
Definition mdb.c:4152
mdb_env_set_maxdbs
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs)
Set the maximum number of named databases for the environment.
Definition mdb.c:4187
mdb_env_create
int mdb_env_create(MDB_env **env)
Create an LMDB environment handle.
Definition mdb.c:4037
mdb_env_get_maxkeysize
int mdb_env_get_maxkeysize(MDB_env *env)
Get the maximum size of keys and MDB_DUPSORT data we can write.
Definition mdb.c:10225
mdb_del
int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Delete items from a database.
Definition mdb.c:8651
mdb_drop
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
Definition mdb.c:10136
mdb_cmp
int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
Compare two data items according to a particular database.
Definition mdb.c:1816
mdb_dbi_open
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
Definition mdb.c:9872
mdb_dcmp
int mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
Compare two data items according to a particular database.
Definition mdb.c:1822
mdb_env_get_path
int mdb_env_get_path(MDB_env *env, const char **path)
Return the path that was used in mdb_env_open().
Definition mdb.c:9779
mdb_cursor_renew
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
Definition mdb.c:7787
mdb_set_dupsort
int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Set a custom data comparison function for a MDB_DUPSORT database.
Definition mdb.c:10197
mdb_cursor_close
void mdb_cursor_close(MDB_cursor *cursor)
Close a cursor handle.
Definition mdb.c:7842
mdb_txn_begin
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
Definition mdb.c:2898
mdb_txn_id
size_t mdb_txn_id(MDB_txn *txn)
Return the transaction's ID.
Definition mdb.c:3009
mdb_env_set_maxreaders
int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers)
Set the maximum number of threads/reader slots for the environment.
Definition mdb.c:4197
mdb_stat
int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat)
Retrieve statistics for a database.
Definition mdb.c:9994
mdb_cursor_txn
MDB_txn * mdb_cursor_txn(MDB_cursor *cursor)
Return the cursor's transaction handle.
Definition mdb.c:7858
mdb_env_get_fd
int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd)
Return the filedescriptor for the given environment.
Definition mdb.c:9789
mdb_env_set_userctx
int mdb_env_set_userctx(MDB_env *env, void *ctx)
Set application information associated with the MDB_env.
Definition mdb.c:9753
mdb_env_stat
int mdb_env_stat(MDB_env *env, MDB_stat *stat)
Return statistics about the LMDB environment.
Definition mdb.c:9818
mdb_version
char * mdb_version(int *major, int *minor, int *patch)
Return the LMDB library version information.
Definition mdb.c:1496
mdb_txn_env
MDB_env * mdb_txn_env(MDB_txn *txn)
Returns the transaction's MDB_env.
Definition mdb.c:3002
MDB_PREV_MULTIPLE
@ MDB_PREV_MULTIPLE
Definition lmdb.h:393
MDB_SET
@ MDB_SET
Definition lmdb.h:390
MDB_NEXT_DUP
@ MDB_NEXT_DUP
Definition lmdb.h:380
MDB_GET_BOTH_RANGE
@ MDB_GET_BOTH_RANGE
Definition lmdb.h:371
MDB_NEXT_MULTIPLE
@ MDB_NEXT_MULTIPLE
Definition lmdb.h:382
MDB_GET_CURRENT
@ MDB_GET_CURRENT
Definition lmdb.h:372
MDB_SET_KEY
@ MDB_SET_KEY
Definition lmdb.h:391
MDB_FIRST_DUP
@ MDB_FIRST_DUP
Definition lmdb.h:368
MDB_FIRST
@ MDB_FIRST
Definition lmdb.h:367
MDB_LAST_DUP
@ MDB_LAST_DUP
Definition lmdb.h:377
MDB_GET_MULTIPLE
@ MDB_GET_MULTIPLE
Definition lmdb.h:373
MDB_NEXT
@ MDB_NEXT
Definition lmdb.h:379
MDB_PREV
@ MDB_PREV
Definition lmdb.h:386
MDB_PREV_DUP
@ MDB_PREV_DUP
Definition lmdb.h:387
MDB_NEXT_NODUP
@ MDB_NEXT_NODUP
Definition lmdb.h:385
MDB_PREV_NODUP
@ MDB_PREV_NODUP
Definition lmdb.h:389
MDB_LAST
@ MDB_LAST
Definition lmdb.h:376
MDB_GET_BOTH
@ MDB_GET_BOTH
Definition lmdb.h:370
MDB_SET_RANGE
@ MDB_SET_RANGE
Definition lmdb.h:392
MDB_envinfo
Information about the environment.
Definition lmdb.h:467
MDB_stat
Statistics for a database in the environment.
Definition lmdb.h:456
MDB_envinfo::me_maxreaders
unsigned int me_maxreaders
Definition lmdb.h:472
MDB_stat::ms_entries
size_t ms_entries
Definition lmdb.h:463
MDB_envinfo::me_mapsize
size_t me_mapsize
Definition lmdb.h:469
MDB_envinfo::me_last_txnid
size_t me_last_txnid
Definition lmdb.h:471
MDB_stat::ms_psize
unsigned int ms_psize
Definition lmdb.h:457
MDB_val::mv_data
void * mv_data
Definition lmdb.h:259
MDB_val::mv_size
size_t mv_size
Definition lmdb.h:258
MDB_stat::ms_depth
unsigned int ms_depth
Definition lmdb.h:459
MDB_stat::ms_overflow_pages
size_t ms_overflow_pages
Definition lmdb.h:462
MDB_stat::ms_leaf_pages
size_t ms_leaf_pages
Definition lmdb.h:461
MDB_stat::ms_branch_pages
size_t ms_branch_pages
Definition lmdb.h:460
MDB_envinfo::me_mapaddr
void * me_mapaddr
Definition lmdb.h:468
MDB_envinfo::me_numreaders
unsigned int me_numreaders
Definition lmdb.h:473
MDB_envinfo::me_last_pgno
size_t me_last_pgno
Definition lmdb.h:470
MDB_rel_func
void MDB_rel_func(MDB_val *item, void *oldptr, void *newptr, void *relctx)
A callback function used to relocate a position-dependent data item in a fixed-address database.
Definition lmdb.h:279
MDB_dbi
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition lmdb.h:241
MDB_cmp_func
int MDB_cmp_func(const MDB_val *a, const MDB_val *b)
A callback function used to compare two keys in a database.
Definition lmdb.h:263
MDB_val
Generic structure used for passing keys and data in and out of the database.
Definition lmdb.h:257
mdb_filehandle_t
int mdb_filehandle_t
Definition lmdb.h:188
mdb_mode_t
mode_t mdb_mode_t
Definition lmdb.h:178