lmdb 0.6 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/ext/lmdb_ext/extconf.rb +7 -3
  3. data/ext/lmdb_ext/lmdb_ext.c +120 -110
  4. data/lib/lmdb/version.rb +1 -1
  5. data/lmdb.gemspec +4 -4
  6. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/.gitignore +8 -0
  7. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/COPYRIGHT +1 -1
  8. data/vendor/libraries/liblmdb/Doxyfile +1631 -0
  9. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/LICENSE +0 -0
  10. data/vendor/libraries/liblmdb/Makefile +118 -0
  11. data/vendor/libraries/liblmdb/intro.doc +192 -0
  12. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/lmdb.h +161 -61
  13. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/mdb.c +3244 -1302
  14. data/vendor/libraries/liblmdb/mdb_copy.1 +61 -0
  15. data/vendor/libraries/liblmdb/mdb_copy.c +84 -0
  16. data/vendor/libraries/liblmdb/mdb_drop.1 +40 -0
  17. data/vendor/libraries/liblmdb/mdb_drop.c +135 -0
  18. data/vendor/libraries/liblmdb/mdb_dump.1 +81 -0
  19. data/vendor/libraries/liblmdb/mdb_dump.c +319 -0
  20. data/vendor/libraries/liblmdb/mdb_load.1 +84 -0
  21. data/vendor/libraries/liblmdb/mdb_load.c +492 -0
  22. data/vendor/libraries/liblmdb/mdb_stat.1 +70 -0
  23. data/vendor/libraries/liblmdb/mdb_stat.c +264 -0
  24. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/midl.c +66 -5
  25. data/{ext/lmdb_ext → vendor/libraries}/liblmdb/midl.h +19 -5
  26. data/vendor/libraries/liblmdb/mtest.c +177 -0
  27. data/vendor/libraries/liblmdb/mtest2.c +124 -0
  28. data/vendor/libraries/liblmdb/mtest3.c +133 -0
  29. data/vendor/libraries/liblmdb/mtest4.c +168 -0
  30. data/vendor/libraries/liblmdb/mtest5.c +135 -0
  31. data/vendor/libraries/liblmdb/mtest6.c +141 -0
  32. data/vendor/libraries/liblmdb/sample-bdb.txt +73 -0
  33. data/vendor/libraries/liblmdb/sample-mdb.txt +62 -0
  34. data/vendor/libraries/liblmdb/tooltag +27 -0
  35. metadata +34 -14
  36. data/.gitignore +0 -15
  37. data/.travis.yml +0 -14
  38. data/ext/lmdb_ext/liblmdb/CHANGES +0 -112
@@ -40,6 +40,9 @@
40
40
  * corrupt the database. Of course if your application code is known to
41
41
  * be bug-free (...) then this is not an issue.
42
42
  *
43
+ * If this is your first time using a transactional embedded key/value
44
+ * store, you may find the \ref starting page to be helpful.
45
+ *
43
46
  * @section caveats_sec Caveats
44
47
  * Troubleshooting the lock file, plus semaphores on BSD systems:
45
48
  *
@@ -49,11 +52,16 @@
49
52
  * stale locks can block further operation.
50
53
  *
51
54
  * Fix: Check for stale readers periodically, using the
52
- * #mdb_reader_check function or the \ref mdb_stat_1 "mdb_stat" tool. Or just
53
- * make all programs using the database close it; the lockfile
54
- * is always reset on first open of the environment.
55
+ * #mdb_reader_check function or the \ref mdb_stat_1 "mdb_stat" tool.
56
+ * Stale writers will be cleared automatically on most systems:
57
+ * - Windows - automatic
58
+ * - BSD, systems using SysV semaphores - automatic
59
+ * - Linux, systems using POSIX mutexes with Robust option - automatic
60
+ * Otherwise just make all programs using the database close it;
61
+ * the lockfile is always reset on first open of the environment.
55
62
  *
56
- * - On BSD systems or others configured with MDB_USE_POSIX_SEM,
63
+ * - On BSD systems or others configured with MDB_USE_SYSV_SEM or
64
+ * MDB_USE_POSIX_SEM,
57
65
  * startup can fail due to semaphores owned by another userid.
58
66
  *
59
67
  * Fix: Open and close the database as the user which owns the
@@ -70,6 +78,11 @@
70
78
  * access to locks and lock file. Exceptions: On read-only filesystems
71
79
  * or with the #MDB_NOLOCK flag described under #mdb_env_open().
72
80
  *
81
+ * - An LMDB configuration will often reserve considerable \b unused
82
+ * memory address space and maybe file size for future growth.
83
+ * This does not use actual memory or disk space, but users may need
84
+ * to understand the difference so they won't be scared off.
85
+ *
73
86
  * - By default, in versions before 0.9.10, unused portions of the data
74
87
  * file might receive garbage data from memory freed by other code.
75
88
  * (This does not happen when using the #MDB_WRITEMAP flag.) As of
@@ -84,11 +97,12 @@
84
97
  * transactions. Each transaction belongs to one thread. See below.
85
98
  * The #MDB_NOTLS flag changes this for read-only transactions.
86
99
  *
87
- * - Use an MDB_env* in the process which opened it, without fork()ing.
100
+ * - Use an MDB_env* in the process which opened it, not after fork().
88
101
  *
89
102
  * - Do not have open an LMDB database twice in the same process at
90
103
  * the same time. Not even from a plain open() call - close()ing it
91
- * breaks flock() advisory locking.
104
+ * breaks fcntl() advisory locking. (It is OK to reopen it after
105
+ * fork() - exec*(), since the lockfile has FD_CLOEXEC set.)
92
106
  *
93
107
  * - Avoid long-lived transactions. Read transactions prevent
94
108
  * reuse of pages freed by newer write transactions, thus the
@@ -106,6 +120,9 @@
106
120
  * for stale readers is performed or the lockfile is reset,
107
121
  * since the process may not remove it from the lockfile.
108
122
  *
123
+ * This does not apply to write transactions if the system clears
124
+ * stale writers, see above.
125
+ *
109
126
  * - If you do that anyway, do a periodic check for stale readers. Or
110
127
  * close the environment once in a while, so the lockfile can get reset.
111
128
  *
@@ -119,7 +136,7 @@
119
136
  *
120
137
  * @author Howard Chu, Symas Corporation.
121
138
  *
122
- * @copyright Copyright 2011-2014 Howard Chu, Symas Corp. All rights reserved.
139
+ * @copyright Copyright 2011-2021 Howard Chu, Symas Corp. All rights reserved.
123
140
  *
124
141
  * Redistribution and use in source and binary forms, with or without
125
142
  * modification, are permitted only as authorized by the OpenLDAP
@@ -150,6 +167,8 @@
150
167
  #define _LMDB_H_
151
168
 
152
169
  #include <sys/types.h>
170
+ #include <inttypes.h>
171
+ #include <limits.h>
153
172
 
154
173
  #ifdef __cplusplus
155
174
  extern "C" {
@@ -162,6 +181,32 @@ typedef int mdb_mode_t;
162
181
  typedef mode_t mdb_mode_t;
163
182
  #endif
164
183
 
184
+ #ifdef _WIN32
185
+ # define MDB_FMT_Z "I"
186
+ #else
187
+ # define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */
188
+ #endif
189
+
190
+ #ifndef MDB_VL32
191
+ /** Unsigned type used for mapsize, entry counts and page/transaction IDs.
192
+ *
193
+ * It is normally size_t, hence the name. Defining MDB_VL32 makes it
194
+ * uint64_t, but do not try this unless you know what you are doing.
195
+ */
196
+ typedef size_t mdb_size_t;
197
+ # define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */
198
+ /** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
199
+ # define MDB_PRIy(t) MDB_FMT_Z #t
200
+ /** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
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 /**< Prevent mixing with non-VL32 builds */
208
+ #endif
209
+
165
210
  /** An abstraction for a file handle.
166
211
  * On POSIX systems file handles are small integers. On Windows
167
212
  * they're opaque pointers.
@@ -184,7 +229,7 @@ typedef int mdb_filehandle_t;
184
229
  /** Library minor version */
185
230
  #define MDB_VERSION_MINOR 9
186
231
  /** Library patch version */
187
- #define MDB_VERSION_PATCH 14
232
+ #define MDB_VERSION_PATCH 70
188
233
 
189
234
  /** Combine args a,b,c into a single integer for easy version comparisons */
190
235
  #define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
@@ -194,7 +239,7 @@ typedef int mdb_filehandle_t;
194
239
  MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)
195
240
 
196
241
  /** The release date of this library version */
197
- #define MDB_VERSION_DATE "September 15, 2014"
242
+ #define MDB_VERSION_DATE "December 19, 2015"
198
243
 
199
244
  /** A stringifier for the version info */
200
245
  #define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
@@ -287,6 +332,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
287
332
  #define MDB_NORDAHEAD 0x800000
288
333
  /** don't initialize malloc'd memory before writing to datafile */
289
334
  #define MDB_NOMEMINIT 0x1000000
335
+ /** use the previous snapshot rather than the latest one */
336
+ #define MDB_PREVSNAPSHOT 0x2000000
290
337
  /** @} */
291
338
 
292
339
  /** @defgroup mdb_dbi_open Database Flags
@@ -296,12 +343,13 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
296
343
  #define MDB_REVERSEKEY 0x02
297
344
  /** use sorted duplicates */
298
345
  #define MDB_DUPSORT 0x04
299
- /** numeric keys in native byte order.
346
+ /** numeric keys in native byte order, either unsigned int or #mdb_size_t.
347
+ * (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
300
348
  * The keys must all be of the same size. */
301
349
  #define MDB_INTEGERKEY 0x08
302
350
  /** with #MDB_DUPSORT, sorted dup items have fixed size */
303
351
  #define MDB_DUPFIXED 0x10
304
- /** with #MDB_DUPSORT, dups are numeric in native byte order */
352
+ /** with #MDB_DUPSORT, dups are #MDB_INTEGERKEY-style integers */
305
353
  #define MDB_INTEGERDUP 0x20
306
354
  /** with #MDB_DUPSORT, use reverse string dups */
307
355
  #define MDB_REVERSEDUP 0x40
@@ -354,7 +402,7 @@ typedef enum MDB_cursor_op {
354
402
  MDB_GET_BOTH, /**< Position at key/data pair. Only for #MDB_DUPSORT */
355
403
  MDB_GET_BOTH_RANGE, /**< position at key, nearest data. Only for #MDB_DUPSORT */
356
404
  MDB_GET_CURRENT, /**< Return key/data at current cursor position */
357
- MDB_GET_MULTIPLE, /**< Return key and up to a page of duplicate data items
405
+ MDB_GET_MULTIPLE, /**< Return up to a page of duplicate data items
358
406
  from current cursor position. Move cursor to prepare
359
407
  for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
360
408
  MDB_LAST, /**< Position at last key/data item */
@@ -363,7 +411,7 @@ typedef enum MDB_cursor_op {
363
411
  MDB_NEXT, /**< Position at next data item */
364
412
  MDB_NEXT_DUP, /**< Position at next data item of current key.
365
413
  Only for #MDB_DUPSORT */
366
- MDB_NEXT_MULTIPLE, /**< Return key and up to a page of duplicate data items
414
+ MDB_NEXT_MULTIPLE, /**< Return up to a page of duplicate data items
367
415
  from next cursor position. Move cursor to prepare
368
416
  for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
369
417
  MDB_NEXT_NODUP, /**< Position at first data item of next key */
@@ -373,7 +421,9 @@ typedef enum MDB_cursor_op {
373
421
  MDB_PREV_NODUP, /**< Position at last data item of previous key */
374
422
  MDB_SET, /**< Position at specified key */
375
423
  MDB_SET_KEY, /**< Position at specified key, return key + data */
376
- MDB_SET_RANGE /**< Position at first key greater than or equal to specified key. */
424
+ MDB_SET_RANGE, /**< Position at first key greater than or equal to specified key. */
425
+ MDB_PREV_MULTIPLE /**< Position at previous page and return up to
426
+ a page of duplicate data items. Only for #MDB_DUPFIXED */
377
427
  } MDB_cursor_op;
378
428
 
379
429
  /** @defgroup errors Return Codes
@@ -391,7 +441,7 @@ typedef enum MDB_cursor_op {
391
441
  #define MDB_PAGE_NOTFOUND (-30797)
392
442
  /** Located page was wrong type */
393
443
  #define MDB_CORRUPTED (-30796)
394
- /** Update of meta page failed, probably I/O error */
444
+ /** Update of meta page failed or environment had fatal error */
395
445
  #define MDB_PANIC (-30795)
396
446
  /** Environment version mismatch */
397
447
  #define MDB_VERSION_MISMATCH (-30794)
@@ -413,18 +463,27 @@ typedef enum MDB_cursor_op {
413
463
  #define MDB_PAGE_FULL (-30786)
414
464
  /** Database contents grew beyond environment mapsize */
415
465
  #define MDB_MAP_RESIZED (-30785)
416
- /** MDB_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed */
466
+ /** Operation and DB incompatible, or DB type changed. This can mean:
467
+ * <ul>
468
+ * <li>The operation expects an #MDB_DUPSORT / #MDB_DUPFIXED database.
469
+ * <li>Opening a named DB when the unnamed DB has #MDB_DUPSORT / #MDB_INTEGERKEY.
470
+ * <li>Accessing a data record as a database, or vice versa.
471
+ * <li>The database was dropped and recreated with different flags.
472
+ * </ul>
473
+ */
417
474
  #define MDB_INCOMPATIBLE (-30784)
418
475
  /** Invalid reuse of reader locktable slot */
419
476
  #define MDB_BAD_RSLOT (-30783)
420
- /** Transaction cannot recover - it must be aborted */
477
+ /** Transaction must abort, has a child, or is invalid */
421
478
  #define MDB_BAD_TXN (-30782)
422
479
  /** Unsupported size of key/DB name/data, or wrong DUPFIXED size */
423
480
  #define MDB_BAD_VALSIZE (-30781)
424
481
  /** The specified DBI was changed unexpectedly */
425
482
  #define MDB_BAD_DBI (-30780)
483
+ /** Unexpected problem - txn should abort */
484
+ #define MDB_PROBLEM (-30779)
426
485
  /** The last defined error code */
427
- #define MDB_LAST_ERRCODE MDB_BAD_DBI
486
+ #define MDB_LAST_ERRCODE MDB_PROBLEM
428
487
  /** @} */
429
488
 
430
489
  /** @brief Statistics for a database in the environment */
@@ -432,18 +491,18 @@ typedef struct MDB_stat {
432
491
  unsigned int ms_psize; /**< Size of a database page.
433
492
  This is currently the same for all databases. */
434
493
  unsigned int ms_depth; /**< Depth (height) of the B-tree */
435
- size_t ms_branch_pages; /**< Number of internal (non-leaf) pages */
436
- size_t ms_leaf_pages; /**< Number of leaf pages */
437
- size_t ms_overflow_pages; /**< Number of overflow pages */
438
- size_t ms_entries; /**< Number of data items */
494
+ mdb_size_t ms_branch_pages; /**< Number of internal (non-leaf) pages */
495
+ mdb_size_t ms_leaf_pages; /**< Number of leaf pages */
496
+ mdb_size_t ms_overflow_pages; /**< Number of overflow pages */
497
+ mdb_size_t ms_entries; /**< Number of data items */
439
498
  } MDB_stat;
440
499
 
441
500
  /** @brief Information about the environment */
442
501
  typedef struct MDB_envinfo {
443
502
  void *me_mapaddr; /**< Address of map, if fixed */
444
- size_t me_mapsize; /**< Size of the data memory map */
445
- size_t me_last_pgno; /**< ID of the last used page */
446
- size_t me_last_txnid; /**< ID of the last committed transaction */
503
+ mdb_size_t me_mapsize; /**< Size of the data memory map */
504
+ mdb_size_t me_last_pgno; /**< ID of the last used page */
505
+ mdb_size_t me_last_txnid; /**< ID of the last committed transaction */
447
506
  unsigned int me_maxreaders; /**< max reader slots in the environment */
448
507
  unsigned int me_numreaders; /**< max reader slots used in the environment */
449
508
  } MDB_envinfo;
@@ -512,12 +571,14 @@ int mdb_env_create(MDB_env **env);
512
571
  * allowed. LMDB will still modify the lock file - except on read-only
513
572
  * filesystems, where LMDB does not use locks.
514
573
  * <li>#MDB_WRITEMAP
515
- * Use a writeable memory map unless MDB_RDONLY is set. This is faster
516
- * and uses fewer mallocs, but loses protection from application bugs
574
+ * Use a writeable memory map unless MDB_RDONLY is set. This uses
575
+ * fewer mallocs but loses protection from application bugs
517
576
  * like wild pointer writes and other bad updates into the database.
577
+ * This may be slightly faster for DBs that fit entirely in RAM, but
578
+ * is slower for DBs larger than RAM.
518
579
  * Incompatible with nested transactions.
519
- * Processes with and without MDB_WRITEMAP on the same environment do
520
- * not cooperate well.
580
+ * Do not mix processes with and without MDB_WRITEMAP on the same
581
+ * environment. This can defeat durability (#mdb_env_sync etc).
521
582
  * <li>#MDB_NOMETASYNC
522
583
  * Flush system buffers to disk only once per transaction, omit the
523
584
  * metadata flush. Defer that until the system flushes files to disk,
@@ -549,7 +610,7 @@ int mdb_env_create(MDB_env **env);
549
610
  * <li>#MDB_NOTLS
550
611
  * Don't use Thread-Local Storage. Tie reader locktable slots to
551
612
  * #MDB_txn objects instead of to threads. I.e. #mdb_txn_reset() keeps
552
- * the slot reseved for the #MDB_txn object. A thread may use parallel
613
+ * the slot reserved for the #MDB_txn object. A thread may use parallel
553
614
  * read-only transactions. A read-only transaction may span threads if
554
615
  * the user synchronizes its use. Applications that multiplex many
555
616
  * user threads over individual OS threads need this option. Such an
@@ -587,9 +648,15 @@ int mdb_env_create(MDB_env **env);
587
648
  * caller is expected to overwrite all of the memory that was
588
649
  * reserved in that case.
589
650
  * This flag may be changed at any time using #mdb_env_set_flags().
651
+ * <li>#MDB_PREVSNAPSHOT
652
+ * Open the environment with the previous snapshot rather than the latest
653
+ * one. This loses the latest transaction, but may help work around some
654
+ * types of corruption. If opened with write access, this must be the
655
+ * only process using the environment. This flag is automatically reset
656
+ * after a write transaction is successfully committed.
590
657
  * </ul>
591
- * @param[in] mode The UNIX permissions to set on created files. This parameter
592
- * is ignored on Windows.
658
+ * @param[in] mode The UNIX permissions to set on created files and semaphores.
659
+ * This parameter is ignored on Windows.
593
660
  * @return A non-zero error value on failure and 0 on success. Some possible
594
661
  * errors are:
595
662
  * <ul>
@@ -653,6 +720,7 @@ int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd);
653
720
  * <li>#MDB_CP_COMPACT - Perform compaction while copying: omit free
654
721
  * pages and sequentially renumber all pages in output. This option
655
722
  * consumes more CPU and runs more slowly than the default.
723
+ * Currently it fails if the environment has suffered a page leak.
656
724
  * </ul>
657
725
  * @return A non-zero error value on failure and 0 on success.
658
726
  */
@@ -698,7 +766,8 @@ int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
698
766
  * Data is always written to disk when #mdb_txn_commit() is called,
699
767
  * but the operating system may keep it buffered. LMDB always flushes
700
768
  * the OS buffers upon commit as well, unless the environment was
701
- * opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC.
769
+ * opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC. This call is
770
+ * not valid if the environment was opened with #MDB_RDONLY.
702
771
  * @param[in] env An environment handle returned by #mdb_env_create()
703
772
  * @param[in] force If non-zero, force a synchronous flush. Otherwise
704
773
  * if the environment has the #MDB_NOSYNC flag set the flushes
@@ -706,6 +775,7 @@ int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
706
775
  * @return A non-zero error value on failure and 0 on success. Some possible
707
776
  * errors are:
708
777
  * <ul>
778
+ * <li>EACCES - the environment is read-only.
709
779
  * <li>EINVAL - an invalid parameter was specified.
710
780
  * <li>EIO - an error occurred during synchronization.
711
781
  * </ul>
@@ -765,6 +835,10 @@ int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
765
835
  int mdb_env_get_path(MDB_env *env, const char **path);
766
836
 
767
837
  /** @brief Return the filedescriptor for the given environment.
838
+ *
839
+ * This function may be called after fork(), so the descriptor can be
840
+ * closed before exec*(). Other LMDB file descriptors have FD_CLOEXEC.
841
+ * (Until LMDB 0.9.18, only the lockfile had that.)
768
842
  *
769
843
  * @param[in] env An environment handle returned by #mdb_env_create()
770
844
  * @param[out] fd Address of a mdb_filehandle_t to contain the descriptor.
@@ -808,7 +882,7 @@ int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
808
882
  * an active write transaction.
809
883
  * </ul>
810
884
  */
811
- int mdb_env_set_mapsize(MDB_env *env, size_t size);
885
+ int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size);
812
886
 
813
887
  /** @brief Set the maximum number of threads/reader slots for the environment.
814
888
  *
@@ -894,7 +968,7 @@ void *mdb_env_get_userctx(MDB_env *env);
894
968
  typedef void MDB_assert_func(MDB_env *env, const char *msg);
895
969
 
896
970
  /** Set or reset the assert() callback of the environment.
897
- * Disabled if liblmdb is buillt with NDEBUG.
971
+ * Disabled if liblmdb is built with NDEBUG.
898
972
  * @note This hack should become obsolete as lmdb's error handling matures.
899
973
  * @param[in] env An environment handle returned by #mdb_env_create().
900
974
  * @param[in] func An #MDB_assert_func function, or 0.
@@ -921,6 +995,10 @@ int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func);
921
995
  * <ul>
922
996
  * <li>#MDB_RDONLY
923
997
  * This transaction will not perform any write operations.
998
+ * <li>#MDB_NOSYNC
999
+ * Don't flush system buffers to disk when committing this transaction.
1000
+ * <li>#MDB_NOMETASYNC
1001
+ * Flush system buffers but omit metadata flush when committing this transaction.
924
1002
  * </ul>
925
1003
  * @param[out] txn Address where the new #MDB_txn handle will be stored
926
1004
  * @return A non-zero error value on failure and 0 on success. Some possible
@@ -944,6 +1022,17 @@ int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **
944
1022
  */
945
1023
  MDB_env *mdb_txn_env(MDB_txn *txn);
946
1024
 
1025
+ /** @brief Return the transaction's ID.
1026
+ *
1027
+ * This returns the identifier associated with this transaction. For a
1028
+ * read-only transaction, this corresponds to the snapshot being read;
1029
+ * concurrent readers will frequently have the same transaction ID.
1030
+ *
1031
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1032
+ * @return A transaction ID, valid if input is an active transaction.
1033
+ */
1034
+ mdb_size_t mdb_txn_id(MDB_txn *txn);
1035
+
947
1036
  /** @brief Commit all the operations of a transaction into the database.
948
1037
  *
949
1038
  * The transaction handle is freed. It and its cursors must not be used
@@ -1019,19 +1108,22 @@ int mdb_txn_renew(MDB_txn *txn);
1019
1108
  * The database handle may be discarded by calling #mdb_dbi_close().
1020
1109
  * The old database handle is returned if the database was already open.
1021
1110
  * The handle may only be closed once.
1111
+ *
1022
1112
  * The database handle will be private to the current transaction until
1023
1113
  * the transaction is successfully committed. If the transaction is
1024
1114
  * aborted the handle will be closed automatically.
1025
- * After a successful commit the
1026
- * handle will reside in the shared environment, and may be used
1027
- * by other transactions. This function must not be called from
1028
- * multiple concurrent transactions. A transaction that uses this function
1029
- * must finish (either commit or abort) before any other transaction may
1030
- * use this function.
1115
+ * After a successful commit the handle will reside in the shared
1116
+ * environment, and may be used by other transactions.
1117
+ *
1118
+ * This function must not be called from multiple concurrent
1119
+ * transactions in the same process. A transaction that uses
1120
+ * this function must finish (either commit or abort) before
1121
+ * any other transaction in the process may use this function.
1031
1122
  *
1032
1123
  * To use named databases (with name != NULL), #mdb_env_set_maxdbs()
1033
- * must be called before opening the environment. Database names
1034
- * are kept as keys in the unnamed database.
1124
+ * must be called before opening the environment. Database names are
1125
+ * keys in the unnamed database, and may be read but not written.
1126
+ *
1035
1127
  * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1036
1128
  * @param[in] name The name of the database to open. If only a single
1037
1129
  * database is needed in the environment, this value may be NULL.
@@ -1048,18 +1140,20 @@ int mdb_txn_renew(MDB_txn *txn);
1048
1140
  * keys may have multiple data items, stored in sorted order.) By default
1049
1141
  * keys must be unique and may have only a single data item.
1050
1142
  * <li>#MDB_INTEGERKEY
1051
- * Keys are binary integers in native byte order. Setting this option
1052
- * requires all keys to be the same size, typically sizeof(int)
1053
- * or sizeof(size_t).
1143
+ * Keys are binary integers in native byte order, either unsigned int
1144
+ * or #mdb_size_t, and will be sorted as such.
1145
+ * (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
1146
+ * The keys must all be of the same size.
1054
1147
  * <li>#MDB_DUPFIXED
1055
1148
  * This flag may only be used in combination with #MDB_DUPSORT. This option
1056
1149
  * tells the library that the data items for this database are all the same
1057
1150
  * size, which allows further optimizations in storage and retrieval. When
1058
- * all data items are the same size, the #MDB_GET_MULTIPLE and #MDB_NEXT_MULTIPLE
1059
- * cursor operations may be used to retrieve multiple items at once.
1151
+ * all data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE
1152
+ * and #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple
1153
+ * items at once.
1060
1154
  * <li>#MDB_INTEGERDUP
1061
- * This option specifies that duplicate data items are also integers, and
1062
- * should be sorted as such.
1155
+ * This option specifies that duplicate data items are binary integers,
1156
+ * similar to #MDB_INTEGERKEY keys.
1063
1157
  * <li>#MDB_REVERSEDUP
1064
1158
  * This option specifies that duplicate data items should be compared as
1065
1159
  * strings in reverse order.
@@ -1268,12 +1362,12 @@ int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1268
1362
  * the next update operation or the transaction ends. This saves
1269
1363
  * an extra memcpy if the data is being generated later.
1270
1364
  * LMDB does nothing else with this memory, the caller is expected
1271
- * to modify all of the space requested.
1365
+ * to modify all of the space requested. This flag must not be
1366
+ * specified if the database was opened with #MDB_DUPSORT.
1272
1367
  * <li>#MDB_APPEND - append the given key/data pair to the end of the
1273
- * database. No key comparisons are performed. This option allows
1274
- * fast bulk loading when keys are already known to be in the
1275
- * correct order. Loading unsorted keys with this flag will cause
1276
- * data corruption.
1368
+ * database. This option allows fast bulk loading when keys are
1369
+ * already known to be in the correct order. Loading unsorted keys
1370
+ * with this flag will cause a #MDB_KEYEXIST error.
1277
1371
  * <li>#MDB_APPENDDUP - as above, but for sorted dup data.
1278
1372
  * </ul>
1279
1373
  * @return A non-zero error value on failure and 0 on success. Some possible
@@ -1425,13 +1519,15 @@ int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1425
1519
  * the database supports duplicates (#MDB_DUPSORT).
1426
1520
  * <li>#MDB_RESERVE - reserve space for data of the given size, but
1427
1521
  * don't copy the given data. Instead, return a pointer to the
1428
- * reserved space, which the caller can fill in later. This saves
1429
- * an extra memcpy if the data is being generated later.
1522
+ * reserved space, which the caller can fill in later - before
1523
+ * the next update operation or the transaction ends. This saves
1524
+ * an extra memcpy if the data is being generated later. This flag
1525
+ * must not be specified if the database was opened with #MDB_DUPSORT.
1430
1526
  * <li>#MDB_APPEND - append the given key/data pair to the end of the
1431
1527
  * database. No key comparisons are performed. This option allows
1432
1528
  * fast bulk loading when keys are already known to be in the
1433
1529
  * correct order. Loading unsorted keys with this flag will cause
1434
- * data corruption.
1530
+ * a #MDB_KEYEXIST error.
1435
1531
  * <li>#MDB_APPENDDUP - as above, but for sorted dup data.
1436
1532
  * <li>#MDB_MULTIPLE - store multiple contiguous data elements in a
1437
1533
  * single request. This flag may only be specified if the database
@@ -1449,7 +1545,7 @@ int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1449
1545
  * <ul>
1450
1546
  * <li>#MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
1451
1547
  * <li>#MDB_TXN_FULL - the transaction has too many dirty pages.
1452
- * <li>EACCES - an attempt was made to modify a read-only database.
1548
+ * <li>EACCES - an attempt was made to write in a read-only transaction.
1453
1549
  * <li>EINVAL - an invalid parameter was specified.
1454
1550
  * </ul>
1455
1551
  */
@@ -1459,6 +1555,10 @@ int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1459
1555
  /** @brief Delete current key/data pair
1460
1556
  *
1461
1557
  * This function deletes the key/data pair to which the cursor refers.
1558
+ * This does not invalidate the cursor, so operations such as MDB_NEXT
1559
+ * can still be used on it.
1560
+ * Both MDB_NEXT and MDB_GET_CURRENT will return the same record after
1561
+ * this operation.
1462
1562
  * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1463
1563
  * @param[in] flags Options for this operation. This parameter
1464
1564
  * must be set to 0 or one of the values described here.
@@ -1469,7 +1569,7 @@ int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1469
1569
  * @return A non-zero error value on failure and 0 on success. Some possible
1470
1570
  * errors are:
1471
1571
  * <ul>
1472
- * <li>EACCES - an attempt was made to modify a read-only database.
1572
+ * <li>EACCES - an attempt was made to write in a read-only transaction.
1473
1573
  * <li>EINVAL - an invalid parameter was specified.
1474
1574
  * </ul>
1475
1575
  */
@@ -1487,7 +1587,7 @@ int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
1487
1587
  * <li>EINVAL - cursor is not initialized, or an invalid parameter was specified.
1488
1588
  * </ul>
1489
1589
  */
1490
- int mdb_cursor_count(MDB_cursor *cursor, size_t *countp);
1590
+ int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp);
1491
1591
 
1492
1592
  /** @brief Compare two data items according to a particular database.
1493
1593
  *