LMDB
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lmdb.h
Go to the documentation of this file.
1 
149 #ifndef _LMDB_H_
150 #define _LMDB_H_
151 
152 #include <sys/types.h>
153 
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157 
159 #ifdef _MSC_VER
160 typedef int mdb_mode_t;
161 #else
162 typedef mode_t mdb_mode_t;
163 #endif
164 
169 #ifdef _WIN32
170 typedef void *mdb_filehandle_t;
171 #else
172 typedef int mdb_filehandle_t;
173 #endif
174 
183 #define MDB_VERSION_MAJOR 0
184 
185 #define MDB_VERSION_MINOR 9
186 
187 #define MDB_VERSION_PATCH 16
188 
190 #define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
191 
193 #define MDB_VERSION_FULL \
194  MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)
195 
197 #define MDB_VERSION_DATE "August 14, 2015"
198 
200 #define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
201 
203 #define MDB_VERFOO(a,b,c,d) MDB_VERSTR(a,b,c,d)
204 
206 #define MDB_VERSION_STRING \
207  MDB_VERFOO(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH,MDB_VERSION_DATE)
208 
215 typedef struct MDB_env MDB_env;
216 
222 typedef struct MDB_txn MDB_txn;
223 
225 typedef unsigned int MDB_dbi;
226 
228 typedef struct MDB_cursor MDB_cursor;
229 
241 typedef struct MDB_val {
242  size_t mv_size;
243  void *mv_data;
244 } MDB_val;
245 
247 typedef int (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
248 
263 typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *relctx);
264 
269 #define MDB_FIXEDMAP 0x01
270 
271 #define MDB_NOSUBDIR 0x4000
272 
273 #define MDB_NOSYNC 0x10000
274 
275 #define MDB_RDONLY 0x20000
276 
277 #define MDB_NOMETASYNC 0x40000
278 
279 #define MDB_WRITEMAP 0x80000
280 
281 #define MDB_MAPASYNC 0x100000
282 
283 #define MDB_NOTLS 0x200000
284 
285 #define MDB_NOLOCK 0x400000
286 
287 #define MDB_NORDAHEAD 0x800000
288 
289 #define MDB_NOMEMINIT 0x1000000
290 
296 #define MDB_REVERSEKEY 0x02
297 
298 #define MDB_DUPSORT 0x04
299 
301 #define MDB_INTEGERKEY 0x08
302 
303 #define MDB_DUPFIXED 0x10
304 
305 #define MDB_INTEGERDUP 0x20
306 
307 #define MDB_REVERSEDUP 0x40
308 
309 #define MDB_CREATE 0x40000
310 
316 #define MDB_NOOVERWRITE 0x10
317 
321 #define MDB_NODUPDATA 0x20
322 
323 #define MDB_CURRENT 0x40
324 
327 #define MDB_RESERVE 0x10000
328 
329 #define MDB_APPEND 0x20000
330 
331 #define MDB_APPENDDUP 0x40000
332 
333 #define MDB_MULTIPLE 0x80000
334 /* @} */
335 
342 #define MDB_CP_COMPACT 0x01
343 /* @} */
344 
350 typedef enum MDB_cursor_op {
377 } MDB_cursor_op;
378 
385 #define MDB_SUCCESS 0
386 
387 #define MDB_KEYEXIST (-30799)
388 
389 #define MDB_NOTFOUND (-30798)
390 
391 #define MDB_PAGE_NOTFOUND (-30797)
392 
393 #define MDB_CORRUPTED (-30796)
394 
395 #define MDB_PANIC (-30795)
396 
397 #define MDB_VERSION_MISMATCH (-30794)
398 
399 #define MDB_INVALID (-30793)
400 
401 #define MDB_MAP_FULL (-30792)
402 
403 #define MDB_DBS_FULL (-30791)
404 
405 #define MDB_READERS_FULL (-30790)
406 
407 #define MDB_TLS_FULL (-30789)
408 
409 #define MDB_TXN_FULL (-30788)
410 
411 #define MDB_CURSOR_FULL (-30787)
412 
413 #define MDB_PAGE_FULL (-30786)
414 
415 #define MDB_MAP_RESIZED (-30785)
416 
424 #define MDB_INCOMPATIBLE (-30784)
425 
426 #define MDB_BAD_RSLOT (-30783)
427 
428 #define MDB_BAD_TXN (-30782)
429 
430 #define MDB_BAD_VALSIZE (-30781)
431 
432 #define MDB_BAD_DBI (-30780)
433 
434 #define MDB_LAST_ERRCODE MDB_BAD_DBI
435 
438 typedef struct MDB_stat {
439  unsigned int ms_psize;
441  unsigned int ms_depth;
443  size_t ms_leaf_pages;
445  size_t ms_entries;
446 } MDB_stat;
447 
449 typedef struct MDB_envinfo {
450  void *me_mapaddr;
451  size_t me_mapsize;
452  size_t me_last_pgno;
453  size_t me_last_txnid;
454  unsigned int me_maxreaders;
455  unsigned int me_numreaders;
456 } MDB_envinfo;
457 
465 char *mdb_version(int *major, int *minor, int *patch);
466 
477 char *mdb_strerror(int err);
478 
490 int mdb_env_create(MDB_env **env);
491 
611 int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode);
612 
627 int mdb_env_copy(MDB_env *env, const char *path);
628 
642 int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd);
643 
666 int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags);
667 
685 int mdb_env_copyfd2(MDB_env *env, mdb_filehandle_t fd, unsigned int flags);
686 
693 int mdb_env_stat(MDB_env *env, MDB_stat *stat);
694 
701 int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
702 
722 int mdb_env_sync(MDB_env *env, int force);
723 
732 void mdb_env_close(MDB_env *env);
733 
748 int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff);
749 
760 int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
761 
774 int mdb_env_get_path(MDB_env *env, const char **path);
775 
786 int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
787 
820 int mdb_env_set_mapsize(MDB_env *env, size_t size);
821 
839 int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers);
840 
851 int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers);
852 
871 int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
872 
881 
888 int mdb_env_set_userctx(MDB_env *env, void *ctx);
889 
895 void *mdb_env_get_userctx(MDB_env *env);
896 
903 typedef void MDB_assert_func(MDB_env *env, const char *msg);
904 
913 
948 int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn);
949 
955 
972 int mdb_txn_commit(MDB_txn *txn);
973 
982 void mdb_txn_abort(MDB_txn *txn);
983 
1001 void mdb_txn_reset(MDB_txn *txn);
1002 
1017 int mdb_txn_renew(MDB_txn *txn);
1018 
1020 #define mdb_open(txn,name,flags,dbi) mdb_dbi_open(txn,name,flags,dbi)
1021 
1022 #define mdb_close(env,dbi) mdb_dbi_close(env,dbi)
1023 
1091 int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi);
1092 
1105 int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat);
1106 
1114 int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags);
1115 
1132 void mdb_dbi_close(MDB_env *env, MDB_dbi dbi);
1133 
1143 int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del);
1144 
1164 int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
1165 
1187 int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
1188 
1207 int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel);
1208 
1223 int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
1224 
1251 int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1252 
1299 int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data,
1300  unsigned int flags);
1301 
1324 int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1325 
1348 int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor);
1349 
1356 void mdb_cursor_close(MDB_cursor *cursor);
1357 
1374 int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor);
1375 
1381 
1386 MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor);
1387 
1407 int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1408  MDB_cursor_op op);
1409 
1467 int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1468  unsigned int flags);
1469 
1487 int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
1488 
1501 int mdb_cursor_count(MDB_cursor *cursor, size_t *countp);
1502 
1513 int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1514 
1525 int mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1526 
1533 typedef int (MDB_msg_func)(const char *msg, void *ctx);
1534 
1542 int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx);
1543 
1550 int mdb_reader_check(MDB_env *env, int *dead);
1553 #ifdef __cplusplus
1554 }
1555 #endif
1556 
1564 #endif /* _LMDB_H_ */
Statistics for a database in the environment.
Definition: lmdb.h:438
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:9422
size_t me_mapsize
Definition: lmdb.h:451
void mdb_cursor_close(MDB_cursor *cursor)
Close a cursor handle.
Definition: mdb.c:7235
int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func)
Definition: mdb.c:9008
Definition: lmdb.h:363
int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Delete items from a database.
Definition: mdb.c:7934
Definition: lmdb.h:357
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:3822
Definition: lmdb.h:364
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:9116
Definition: lmdb.h:366
char * mdb_version(int *major, int *minor, int *patch)
Return the LMDB library version information.
Definition: mdb.c:1268
size_t ms_entries
Definition: lmdb.h:445
int mdb_cursor_count(MDB_cursor *cursor, size_t *countp)
Return count of duplicates for current key.
Definition: mdb.c:7203
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
Definition: mdb.c:3223
int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Store by cursor.
Definition: mdb.c:6104
int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat)
Retrieve statistics for a database.
Definition: mdb.c:9224
void mdb_dbi_close(MDB_env *env, MDB_dbi dbi)
Close a database handle. Normally unnecessary. Use with care:
Definition: mdb.c:9241
size_t ms_overflow_pages
Definition: lmdb.h:444
void * mdb_env_get_userctx(MDB_env *env)
Get the application information associated with the MDB_env.
Definition: mdb.c:9002
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:3874
size_t mv_size
Definition: lmdb.h:242
MDB_txn * mdb_cursor_txn(MDB_cursor *cursor)
Return the cursor's transaction handle.
Definition: mdb.c:7250
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:9413
unsigned int ms_psize
Definition: lmdb.h:439
Opaque structure for a transaction handle.
Definition: mdb.c:955
int mdb_env_info(MDB_env *env, MDB_envinfo *stat)
Return information about the LMDB environment.
Definition: mdb.c:9071
Opaque structure for navigating through a database.
Definition: mdb.c:1043
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs)
Set the maximum number of named databases for the environment.
Definition: mdb.c:3856
int mdb_env_get_maxkeysize(MDB_env *env)
Get the maximum size of keys and MDB_DUPSORT data we can write.
Definition: mdb.c:9441
MDB_env * mdb_txn_env(MDB_txn *txn)
Returns the transaction's MDB_env.
Definition: mdb.c:2756
Information about the environment.
Definition: lmdb.h:449
void * mv_data
Definition: lmdb.h:243
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:903
void * me_mapaddr
Definition: lmdb.h:450
Definition: lmdb.h:370
Definition: lmdb.h:355
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:1565
MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor)
Return the cursor's database handle.
Definition: mdb.c:7257
int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx)
Dump the entries in the reader lock table.
Definition: mdb.c:9447
int( MDB_msg_func)(const char *msg, void *ctx)
A callback function used to print a message from the library.
Definition: lmdb.h:1533
size_t ms_branch_pages
Definition: lmdb.h:442
int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd)
Copy an LMDB environment to the specified file descriptor.
int mdb_env_get_path(MDB_env *env, const char **path)
Return the path that was used in mdb_env_open().
Definition: mdb.c:9019
Definition: lmdb.h:361
int mdb_env_get_flags(MDB_env *env, unsigned int *flags)
Get environment flags.
Definition: mdb.c:8983
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
Definition: mdb.c:9353
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.
unsigned int me_maxreaders
Definition: lmdb.h:454
size_t ms_leaf_pages
Definition: lmdb.h:443
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
Open an environment handle.
Definition: mdb.c:4528
int mdb_env_copy(MDB_env *env, const char *path)
Copy an LMDB environment to the specified path.
Definition: mdb.c:8965
void mdb_txn_reset(MDB_txn *txn)
Reset a read-only transaction.
Definition: mdb.c:2848
Definition: lmdb.h:369
int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
Retrieve the DB flags for a database handle.
Definition: mdb.c:9257
Definition: lmdb.h:374
Definition: lmdb.h:351
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:9431
size_t me_last_pgno
Definition: lmdb.h:452
Definition: lmdb.h:373
int mdb_txn_renew(MDB_txn *txn)
Renew a read-only transaction.
Definition: mdb.c:2622
int mdb_reader_check(MDB_env *env, int *dead)
Check for stale entries in the reader lock table.
Definition: mdb.c:9525
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:1571
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
Definition: mdb.c:7186
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:9404
Generic structure used for passing keys and data in and out of the database.
Definition: lmdb.h:241
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition: lmdb.h:225
int mdb_env_sync(MDB_env *env, int force)
Flush the data buffers to disk.
Definition: mdb.c:2329
size_t me_last_txnid
Definition: lmdb.h:453
int mdb_filehandle_t
Definition: lmdb.h:172
int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd)
Return the filedescriptor for the given environment.
Definition: mdb.c:9029
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:2644
MDB_cursor_op
Cursor Get operations.
Definition: lmdb.h:350
Definition: lmdb.h:371
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
Definition: mdb.c:5898
int mdb_env_create(MDB_env **env)
Create an LMDB environment handle.
Definition: mdb.c:3713
unsigned int me_numreaders
Definition: lmdb.h:455
void mdb_txn_abort(MDB_txn *txn)
Abandon all the operations of the transaction instead of saving them.
Definition: mdb.c:2861
mode_t mdb_mode_t
Definition: lmdb.h:162
Definition: lmdb.h:375
Opaque structure for a database environment.
Definition: mdb.c:1102
Definition: lmdb.h:360
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:247
Definition: lmdb.h:356
Definition: lmdb.h:352
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:263
int mdb_env_stat(MDB_env *env, MDB_stat *stat)
Return statistics about the LMDB environment.
Definition: mdb.c:9058
char * mdb_strerror(int err)
Return a string describing a given error code.
Definition: mdb.c:1301
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:3865
Definition: lmdb.h:376
int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff)
Set environment flags.
Definition: mdb.c:8971
int mdb_env_set_userctx(MDB_env *env, void *ctx)
Set application information associated with the MDB_env.
Definition: mdb.c:8993
int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags)
Delete current key/data pair.
Definition: mdb.c:6615
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:8905
Definition: lmdb.h:354
int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Get items from a database.
Definition: mdb.c:5374
unsigned int ms_depth
Definition: lmdb.h:441
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:8397
void mdb_env_close(MDB_env *env)
Close the environment and release the memory map.
Definition: mdb.c:4767
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.
Definition: mdb.c:7151