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
191 
196 typedef size_t mdb_size_t;
197 # define MDB_SIZE_MAX SIZE_MAX
199 # define MDB_PRIy(t) MDB_FMT_Z #t
200 
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
229 
230 #define MDB_VERSION_MINOR 9
231 
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)
253 
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;
289 } MDB_val;
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
315 
316 #define MDB_NOSUBDIR 0x4000
317 
318 #define MDB_NOSYNC 0x10000
319 
320 #define MDB_RDONLY 0x20000
321 
322 #define MDB_NOMETASYNC 0x40000
323 
324 #define MDB_WRITEMAP 0x80000
325 
326 #define MDB_MAPASYNC 0x100000
327 
328 #define MDB_NOTLS 0x200000
329 
330 #define MDB_NOLOCK 0x400000
331 
332 #define MDB_NORDAHEAD 0x800000
333 
334 #define MDB_NOMEMINIT 0x1000000
335 
336 #define MDB_PREVSNAPSHOT 0x2000000
337 
343 #define MDB_REVERSEKEY 0x02
344 
345 #define MDB_DUPSORT 0x04
346 
349 #define MDB_INTEGERKEY 0x08
350 
351 #define MDB_DUPFIXED 0x10
352 
353 #define MDB_INTEGERDUP 0x20
354 
355 #define MDB_REVERSEDUP 0x40
356 
357 #define MDB_CREATE 0x40000
358 
364 #define MDB_NOOVERWRITE 0x10
365 
369 #define MDB_NODUPDATA 0x20
370 
371 #define MDB_CURRENT 0x40
372 
375 #define MDB_RESERVE 0x10000
376 
377 #define MDB_APPEND 0x20000
378 
379 #define MDB_APPENDDUP 0x40000
380 
381 #define MDB_MULTIPLE 0x80000
382 /* @} */
383 
390 #define MDB_CP_COMPACT 0x01
391 /* @} */
392 
398 typedef enum MDB_cursor_op {
427 } MDB_cursor_op;
428 
435 #define MDB_SUCCESS 0
436 
437 #define MDB_KEYEXIST (-30799)
438 
439 #define MDB_NOTFOUND (-30798)
440 
441 #define MDB_PAGE_NOTFOUND (-30797)
442 
443 #define MDB_CORRUPTED (-30796)
444 
445 #define MDB_PANIC (-30795)
446 
447 #define MDB_VERSION_MISMATCH (-30794)
448 
449 #define MDB_INVALID (-30793)
450 
451 #define MDB_MAP_FULL (-30792)
452 
453 #define MDB_DBS_FULL (-30791)
454 
455 #define MDB_READERS_FULL (-30790)
456 
457 #define MDB_TLS_FULL (-30789)
458 
459 #define MDB_TXN_FULL (-30788)
460 
461 #define MDB_CURSOR_FULL (-30787)
462 
463 #define MDB_PAGE_FULL (-30786)
464 
465 #define MDB_MAP_RESIZED (-30785)
466 
474 #define MDB_INCOMPATIBLE (-30784)
475 
476 #define MDB_BAD_RSLOT (-30783)
477 
478 #define MDB_BAD_TXN (-30782)
479 
480 #define MDB_BAD_VALSIZE (-30781)
481 
482 #define MDB_BAD_DBI (-30780)
483 
484 #define MDB_PROBLEM (-30779)
485 
486 #define MDB_LAST_ERRCODE MDB_PROBLEM
487 
490 typedef struct MDB_stat {
491  unsigned int ms_psize;
493  unsigned int ms_depth;
498 } MDB_stat;
499 
501 typedef struct MDB_envinfo {
502  void *me_mapaddr;
506  unsigned int me_maxreaders;
507  unsigned int me_numreaders;
508 } MDB_envinfo;
509 
517 char *mdb_version(int *major, int *minor, int *patch);
518 
529 char *mdb_strerror(int err);
530 
542 int mdb_env_create(MDB_env **env);
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 
762 int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
763 
783 int mdb_env_sync(MDB_env *env, int force);
784 
793 void mdb_env_close(MDB_env *env);
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 
885 int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size);
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 
936 int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
937 
946 
953 int mdb_env_set_userctx(MDB_env *env, void *ctx);
954 
960 void *mdb_env_get_userctx(MDB_env *env);
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 
1023 MDB_env *mdb_txn_env(MDB_txn *txn);
1024 
1035 
1052 int mdb_txn_commit(MDB_txn *txn);
1053 
1062 void mdb_txn_abort(MDB_txn *txn);
1063 
1081 void mdb_txn_reset(MDB_txn *txn);
1082 
1097 int mdb_txn_renew(MDB_txn *txn);
1098 
1100 #define mdb_open(txn,name,flags,dbi) mdb_dbi_open(txn,name,flags,dbi)
1101 
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 
1214 void mdb_dbi_close(MDB_env *env, MDB_dbi dbi);
1215 
1225 int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del);
1226 
1246 int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
1247 
1269 int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
1270 
1289 int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel);
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 
1439 void mdb_cursor_close(MDB_cursor *cursor);
1440 
1457 int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor);
1458 
1464 
1470 
1490 int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1491  MDB_cursor_op op);
1492 
1552 int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1553  unsigned int flags);
1554 
1576 int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
1577 
1590 int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp);
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
1645 
1653 #endif /* _LMDB_H_ */
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_env_set_mapsize(MDB_env *env, mdb_size_t size)
Set the size of the memory map to use for this environment.
void mdb_cursor_close(MDB_cursor *cursor)
Close a cursor handle.
int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func)
Definition: lmdb.h:411
int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Delete items from a database.
int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp)
Return count of duplicates for current key.
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
Open a database in the environment.
char * mdb_version(int *major, int *minor, int *patch)
Return the LMDB library version information.
int mdb_txn_commit(MDB_txn *txn)
Commit all the operations of a transaction into the database.
int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, unsigned int flags)
Store by cursor.
int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat)
Retrieve statistics for a database.
unsigned int me_numreaders
Definition: lmdb.h:507
void mdb_dbi_close(MDB_env *env, MDB_dbi dbi)
Close a database handle. Normally unnecessary. Use with care:
void * mdb_env_get_userctx(MDB_env *env)
Get the application information associated with the MDB_env.
struct MDB_envinfo MDB_envinfo
Information about the environment.
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
int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers)
Get the maximum number of threads/reader slots for the environment.
const char * key
Definition: hmac_keccak.cpp:39
MDB_txn * mdb_cursor_txn(MDB_cursor *cursor)
Return the cursor&#39;s transaction 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.
int mdb_env_info(MDB_env *env, MDB_envinfo *stat)
Return information about the LMDB environment.
int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs)
Set the maximum number of named databases for the environment.
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
int mdb_env_get_maxkeysize(MDB_env *env)
Get the maximum size of keys and MDB_DUPSORT data we can write.
struct MDB_env MDB_env
Opaque structure for a database environment.
Definition: lmdb.h:260
mdb_size_t ms_branch_pages
Definition: lmdb.h:494
MDB_env * mdb_txn_env(MDB_txn *txn)
Returns the transaction&#39;s MDB_env.
struct MDB_val MDB_val
Generic structure used for passing keys and data in and out of the database.
const char * name
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
unsigned int ms_depth
Definition: lmdb.h:493
Definition: lmdb.h:418
unsigned int me_maxreaders
Definition: lmdb.h:506
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.
MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor)
Return the cursor&#39;s database handle.
int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx)
Dump the entries in the reader lock table.
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
Definition: lmdb.h:267
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().
int mdb_env_get_flags(MDB_env *env, unsigned int *flags)
Get environment flags.
int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del)
Empty or delete+close 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.
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode)
Open an environment handle.
Statistics for a database in the environment.
Definition: lmdb.h:490
Information about the environment.
Definition: lmdb.h:501
int mdb_env_copy(MDB_env *env, const char *path)
Copy an LMDB environment to the specified path.
void * mv_data
Definition: lmdb.h:288
void mdb_txn_reset(MDB_txn *txn)
Reset a read-only transaction.
int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags)
Retrieve the DB flags for a database handle.
size_t mv_size
Definition: lmdb.h:287
Definition: lmdb.h:422
int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx)
Set a context pointer for a MDB_FIXEDMAP database&#39;s relocation function.
int mdb_txn_renew(MDB_txn *txn)
Renew a read-only transaction.
mdb_size_t me_last_pgno
Definition: lmdb.h:504
unsigned __int64 uint64_t
Definition: stdint.h:136
int mdb_reader_check(MDB_env *env, int *dead)
Check for stale entries in the reader lock table.
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_cursor_renew(MDB_txn *txn, MDB_cursor *cursor)
Renew a cursor handle.
int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp)
Set a custom key comparison function for a database.
mdb_size_t ms_overflow_pages
Definition: lmdb.h:496
unsigned int MDB_dbi
A handle for an individual database in the DB environment.
Definition: lmdb.h:270
mdb_size_t me_last_txnid
Definition: lmdb.h:505
int mdb_env_sync(MDB_env *env, int force)
Flush the data buffers to disk.
int mdb_filehandle_t
Definition: lmdb.h:217
mdb_size_t mdb_txn_id(MDB_txn *txn)
Return the transaction&#39;s ID.
int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd)
Return the filedescriptor for the given environment.
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
MDB_cursor_op
Cursor Get operations.
Definition: lmdb.h:398
void * me_mapaddr
Definition: lmdb.h:502
int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op)
Retrieve by cursor.
int mdb_env_create(MDB_env **env)
Create an LMDB environment handle.
void mdb_txn_abort(MDB_txn *txn)
Abandon all the operations of the transaction instead of saving them.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
mdb_size_t ms_leaf_pages
Definition: lmdb.h:495
mode_t mdb_mode_t
Definition: lmdb.h:181
struct MDB_cursor MDB_cursor
Opaque structure for navigating through a database.
Definition: lmdb.h:273
Generic structure used for passing keys and data in and out of the database.
Definition: lmdb.h:286
unsigned int ms_psize
Definition: lmdb.h:491
Definition: lmdb.h:408
int mdb_env_stat(MDB_env *env, MDB_stat *stat)
Return statistics about the LMDB environment.
char * mdb_strerror(int err)
Return a string describing a given error code.
int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers)
Set the maximum number of threads/reader slots for the environment.
mdb_size_t me_mapsize
Definition: lmdb.h:503
int() MDB_msg_func(const char *msg, void *ctx)
A callback function used to print a message from the library.
Definition: lmdb.h:1622
int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff)
Set environment flags.
int mdb_env_set_userctx(MDB_env *env, void *ctx)
Set application information associated with the MDB_env.
int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags)
Delete current key/data pair.
int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
Copy an LMDB environment to the specified path, with options.
struct MDB_stat MDB_stat
Statistics for a database in the environment.
size_t mdb_size_t
Definition: lmdb.h:196
mdb_size_t ms_entries
Definition: lmdb.h:497
int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data)
Get items from a database.
int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, unsigned int flags)
Store items into a database.
void mdb_env_close(MDB_env *env)
Close the environment and release the memory map.
int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor)
Create a cursor handle.