Electroneum
lmdb.h
Go to the documentation of this file.
1 
166 #ifndef _LMDB_H_
167 #define _LMDB_H_
168 
169 #include <sys/types.h>
170 #include <inttypes.h>
171 #include <limits.h>
172 
173 #ifdef __cplusplus
174 extern "C" {
175 #endif
176 
178 #ifdef _MSC_VER
179 typedef int mdb_mode_t;
180 #else
181 typedef mode_t mdb_mode_t;
182 #endif
183 
184 #ifdef _WIN32
185 # define MDB_FMT_Z "I"
186 #else
187 # define MDB_FMT_Z "z"
188 #endif
189 
190 #ifndef MDB_VL32
196 typedef size_t mdb_size_t;
197 # define MDB_SIZE_MAX SIZE_MAX
199 # define MDB_PRIy(t) MDB_FMT_Z #t
201 # define MDB_SCNy(t) MDB_FMT_Z #t
202 #else
203 typedef uint64_t mdb_size_t;
204 # define MDB_SIZE_MAX UINT64_MAX
205 # define MDB_PRIy(t) PRI##t##64
206 # define MDB_SCNy(t) SCN##t##64
207 # define mdb_env_create mdb_env_create_vl32
208 #endif
209 
214 #ifdef _WIN32
215 typedef void *mdb_filehandle_t;
216 #else
217 typedef int mdb_filehandle_t;
218 #endif
219 
228 #define MDB_VERSION_MAJOR 0
230 #define MDB_VERSION_MINOR 9
232 #define MDB_VERSION_PATCH 70
233 
235 #define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
236 
238 #define MDB_VERSION_FULL \
239  MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)
240 
242 #define MDB_VERSION_DATE "December 19, 2015"
243 
245 #define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
246 
248 #define MDB_VERFOO(a,b,c,d) MDB_VERSTR(a,b,c,d)
249 
251 #define MDB_VERSION_STRING \
252  MDB_VERFOO(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH,MDB_VERSION_DATE)
260 typedef struct MDB_env MDB_env;
261 
267 typedef struct MDB_txn MDB_txn;
268 
270 typedef unsigned int MDB_dbi;
271 
273 typedef struct MDB_cursor MDB_cursor;
274 
286 typedef struct MDB_val {
287  size_t mv_size;
288  void *mv_data;
290 
292 typedef int (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
293 
308 typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *relctx);
309 
314 #define MDB_FIXEDMAP 0x01
316 #define MDB_NOSUBDIR 0x4000
318 #define MDB_NOSYNC 0x10000
320 #define MDB_RDONLY 0x20000
322 #define MDB_NOMETASYNC 0x40000
324 #define MDB_WRITEMAP 0x80000
326 #define MDB_MAPASYNC 0x100000
328 #define MDB_NOTLS 0x200000
330 #define MDB_NOLOCK 0x400000
332 #define MDB_NORDAHEAD 0x800000
334 #define MDB_NOMEMINIT 0x1000000
336 #define MDB_PREVSNAPSHOT 0x2000000
343 #define MDB_REVERSEKEY 0x02
345 #define MDB_DUPSORT 0x04
349 #define MDB_INTEGERKEY 0x08
351 #define MDB_DUPFIXED 0x10
353 #define MDB_INTEGERDUP 0x20
355 #define MDB_REVERSEDUP 0x40
357 #define MDB_CREATE 0x40000
364 #define MDB_NOOVERWRITE 0x10
369 #define MDB_NODUPDATA 0x20
371 #define MDB_CURRENT 0x40
375 #define MDB_RESERVE 0x10000
377 #define MDB_APPEND 0x20000
379 #define MDB_APPENDDUP 0x40000
381 #define MDB_MULTIPLE 0x80000
382 /* @} */
383 
390 #define MDB_CP_COMPACT 0x01
391 /* @} */
392 
398 typedef enum MDB_cursor_op {
400  MDB_FIRST_DUP,
409  MDB_LAST_DUP,
412  MDB_NEXT_DUP,
419  MDB_PREV_DUP,
428 
435 #define MDB_SUCCESS 0
437 #define MDB_KEYEXIST (-30799)
439 #define MDB_NOTFOUND (-30798)
441 #define MDB_PAGE_NOTFOUND (-30797)
443 #define MDB_CORRUPTED (-30796)
445 #define MDB_PANIC (-30795)
447 #define MDB_VERSION_MISMATCH (-30794)
449 #define MDB_INVALID (-30793)
451 #define MDB_MAP_FULL (-30792)
453 #define MDB_DBS_FULL (-30791)
455 #define MDB_READERS_FULL (-30790)
457 #define MDB_TLS_FULL (-30789)
459 #define MDB_TXN_FULL (-30788)
461 #define MDB_CURSOR_FULL (-30787)
463 #define MDB_PAGE_FULL (-30786)
465 #define MDB_MAP_RESIZED (-30785)
474 #define MDB_INCOMPATIBLE (-30784)
476 #define MDB_BAD_RSLOT (-30783)
478 #define MDB_BAD_TXN (-30782)
480 #define MDB_BAD_VALSIZE (-30781)
482 #define MDB_BAD_DBI (-30780)
484 #define MDB_PROBLEM (-30779)
486 #define MDB_LAST_ERRCODE MDB_PROBLEM
490 typedef struct MDB_stat {
491  unsigned int ms_psize;
493  unsigned int ms_depth;
499 
501 typedef struct MDB_envinfo {
502  void *me_mapaddr;
506  unsigned int me_maxreaders;
507  unsigned int me_numreaders;
509 
517 char *mdb_version(int *major, int *minor, int *patch);
518 
529 char *mdb_strerror(int err);
530 
543 
671 int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode);
672 
687 int mdb_env_copy(MDB_env *env, const char *path);
688 
703 
727 int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags);
728 
746 int mdb_env_copyfd2(MDB_env *env, mdb_filehandle_t fd, unsigned int flags);
747 
754 int mdb_env_stat(MDB_env *env, MDB_stat *stat);
755 
763 
783 int mdb_env_sync(MDB_env *env, int force);
784 
794 
809 int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff);
810 
821 int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
822 
835 int mdb_env_get_path(MDB_env *env, const char **path);
836 
852 
886 
904 int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers);
905 
916 int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers);
917 
937 
946 
953 int mdb_env_set_userctx(MDB_env *env, void *ctx);
954 
961 
968 typedef void MDB_assert_func(MDB_env *env, const char *msg);
969 
978 
1017 int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn);
1018 
1024 
1035 
1053 
1063 
1082 
1098 
1100 #define mdb_open(txn,name,flags,dbi) mdb_dbi_open(txn,name,flags,dbi)
1102 #define mdb_close(env,dbi) mdb_dbi_close(env,dbi)
1103 
1173 int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi);
1174 
1187 int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat);
1188 
1196 int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags);
1197 
1215 
1225 int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del);
1226 
1247 
1270 
1290 
1305 int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
1306 
1333 int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1334 
1382 int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data,
1383  unsigned int flags);
1384 
1407 int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1408 
1431 int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor);
1432 
1440 
1458 
1464 
1470 
1491  MDB_cursor_op op);
1492 
1553  unsigned int flags);
1554 
1576 int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
1577 
1591 
1602 int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1603 
1614 int mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1615 
1622 typedef int (MDB_msg_func)(const char *msg, void *ctx);
1623 
1631 int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx);
1632 
1639 int mdb_reader_check(MDB_env *env, int *dead);
1642 #ifdef __cplusplus
1643 }
1644 #endif
1653 #endif /* _LMDB_H_ */
struct MDB_stat MDB_stat
Statistics for a database in the environment.
void mdb_txn_reset(MDB_txn *txn)
Reset a read-only transaction.
int() MDB_msg_func(const char *msg, void *ctx)
A callback function used to print a message from the library.
Definition: lmdb.h:1622
char * mdb_version(int *major, int *minor, int *patch)
Return the LMDB library version information.
MDB_cursor_op
Cursor Get operations.
Definition: lmdb.h:398
int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp)
Return count of duplicates for current key.
int mdb_env_info(MDB_env *env, MDB_envinfo *stat)
Return information about the LMDB environment.
int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Store by cursor.
int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags)
Delete current key/data pair.
int mdb_env_get_flags(MDB_env *env, unsigned int *flags)
Get environment flags.
MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor)
Return the cursor's database handle.
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
Open an environment handle.
int mdb_reader_check(MDB_env *env, int *dead)
Check for stale entries in the reader lock table.
int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
Copy an LMDB environment to the specified path, with options.
void mdb_env_close(MDB_env *env)
Close the environment and release the memory map.
void * mdb_env_get_userctx(MDB_env *env)
Get the application information associated with the MDB_env.
int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd)
Copy an LMDB environment to the specified file descriptor.
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size)
Set the size of the memory map to use for this environment.
int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags)
Store items into a database.
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.
void mdb_dbi_close(MDB_env *env, MDB_dbi dbi)
Close a database handle. Normally unnecessary. Use with care:
struct MDB_envinfo MDB_envinfo
Information about the environment.
char * mdb_strerror(int err)
Return a string describing a given error code.
int mdb_env_copy(MDB_env *env, const char *path)
Copy an LMDB environment to the specified path.
int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Set a custom key comparison function for a database.
int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel)
Set a relocation function for a MDB_FIXEDMAP database.
int mdb_txn_renew(MDB_txn *txn)
Renew a read-only transaction.
int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func)
int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers)
Get the maximum number of threads/reader slots for the environment.
void mdb_txn_abort(MDB_txn *txn)
Abandon all the operations of the transaction instead of saving them.
mdb_size_t mdb_txn_id(MDB_txn *txn)
Return the transaction's ID.
MDB_txn * mdb_cursor_txn(MDB_cursor *cursor)
Return the cursor's transaction handle.
int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx)
Set a context pointer for a MDB_FIXEDMAP database's relocation function.
int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff)
Set environment flags.
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx)
Dump the entries in the reader lock table.
int mdb_env_sync(MDB_env *env, int force)
Flush the data buffers to disk.
int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Get items from a database.
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:968
int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
Retrieve the DB flags for a database handle.
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs)
Set the maximum number of named databases for the environment.
int mdb_env_create(MDB_env **env)
Create an LMDB environment handle.
int mdb_env_get_maxkeysize(MDB_env *env)
Get the maximum size of keys and MDB_DUPSORT data we can write.
int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Delete items from a database.
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close a database.
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.
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
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.
int mdb_env_get_path(MDB_env *env, const char **path)
Return the path that was used in mdb_env_open().
int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
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.
void mdb_cursor_close(MDB_cursor *cursor)
Close a cursor handle.
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers)
Set the maximum number of threads/reader slots for the environment.
int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat)
Retrieve statistics for a database.
MDB_env * mdb_txn_env(MDB_txn *txn)
Returns the transaction's MDB_env.
int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd)
Return the filedescriptor for the given environment.
int mdb_env_set_userctx(MDB_env *env, void *ctx)
Set application information associated with the MDB_env.
int mdb_env_stat(MDB_env *env, MDB_stat *stat)
Return statistics about the LMDB environment.
@ MDB_PREV_MULTIPLE
Definition: lmdb.h:425
@ MDB_SET
Definition: lmdb.h:422
@ MDB_NEXT_DUP
Definition: lmdb.h:412
@ MDB_GET_BOTH_RANGE
Definition: lmdb.h:403
@ MDB_NEXT_MULTIPLE
Definition: lmdb.h:414
@ MDB_GET_CURRENT
Definition: lmdb.h:404
@ MDB_SET_KEY
Definition: lmdb.h:423
@ MDB_FIRST_DUP
Definition: lmdb.h:400
@ MDB_FIRST
Definition: lmdb.h:399
@ MDB_LAST_DUP
Definition: lmdb.h:409
@ MDB_GET_MULTIPLE
Definition: lmdb.h:405
@ MDB_NEXT
Definition: lmdb.h:411
@ MDB_PREV
Definition: lmdb.h:418
@ MDB_PREV_DUP
Definition: lmdb.h:419
@ MDB_NEXT_NODUP
Definition: lmdb.h:417
@ MDB_PREV_NODUP
Definition: lmdb.h:421
@ MDB_LAST
Definition: lmdb.h:408
@ MDB_GET_BOTH
Definition: lmdb.h:402
@ MDB_SET_RANGE
Definition: lmdb.h:424
unsigned int me_maxreaders
Definition: lmdb.h:506
mdb_size_t me_mapsize
Definition: lmdb.h:503
mdb_size_t me_last_pgno
Definition: lmdb.h:504
mdb_size_t ms_entries
Definition: lmdb.h:497
unsigned int ms_psize
Definition: lmdb.h:491
mdb_size_t ms_branch_pages
Definition: lmdb.h:494
void * mv_data
Definition: lmdb.h:288
size_t mv_size
Definition: lmdb.h:287
mdb_size_t me_last_txnid
Definition: lmdb.h:505
unsigned int ms_depth
Definition: lmdb.h:493
mdb_size_t ms_leaf_pages
Definition: lmdb.h:495
void * me_mapaddr
Definition: lmdb.h:502
unsigned int me_numreaders
Definition: lmdb.h:507
mdb_size_t ms_overflow_pages
Definition: lmdb.h:496
struct MDB_val MDB_val
Generic structure used for passing keys and data in and out of the database.
struct MDB_env MDB_env
Opaque structure for a database environment.
Definition: lmdb.h:260
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:308
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
Definition: lmdb.h:267
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:292
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition: lmdb.h:270
struct MDB_cursor MDB_cursor
Opaque structure for navigating through a database.
Definition: lmdb.h:273
const char * key
Definition: hmac_keccak.cpp:39
int mdb_filehandle_t
Definition: lmdb.h:217
mode_t mdb_mode_t
Definition: lmdb.h:181
size_t mdb_size_t
Definition: lmdb.h:196
const char * name
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
unsigned __int64 uint64_t
Definition: stdint.h:136
Information about the environment.
Definition: lmdb.h:501
Statistics for a database in the environment.
Definition: lmdb.h:490
Generic structure used for passing keys and data in and out of the database.
Definition: lmdb.h:286