@ohos-ports/lmdb 2.8.6-beta.0

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 (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +580 -0
  3. package/SECURITY.md +12 -0
  4. package/bin/download-prebuilds.js +15 -0
  5. package/binding.gyp +113 -0
  6. package/build/Release/lmdb.node +0 -0
  7. package/caching.js +212 -0
  8. package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -0
  9. package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -0
  10. package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -0
  11. package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -0
  12. package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -0
  13. package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -0
  14. package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -0
  15. package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -0
  16. package/dependencies/lmdb/libraries/liblmdb/lmdb.h +1817 -0
  17. package/dependencies/lmdb/libraries/liblmdb/mdb.c +12555 -0
  18. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -0
  19. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -0
  20. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -0
  21. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -0
  22. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -0
  23. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -0
  24. package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -0
  25. package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -0
  26. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -0
  27. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -0
  28. package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
  29. package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -0
  30. package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -0
  31. package/dependencies/lmdb/libraries/liblmdb/module.c +101 -0
  32. package/dependencies/lmdb/libraries/liblmdb/module.h +16 -0
  33. package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -0
  34. package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -0
  35. package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -0
  36. package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -0
  37. package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -0
  38. package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -0
  39. package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -0
  40. package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -0
  41. package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -0
  42. package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -0
  43. package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -0
  44. package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -0
  45. package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
  46. package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -0
  47. package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -0
  48. package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -0
  49. package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -0
  50. package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -0
  51. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -0
  52. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -0
  53. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -0
  54. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -0
  55. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -0
  56. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -0
  57. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -0
  58. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -0
  59. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -0
  60. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -0
  61. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -0
  62. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -0
  63. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -0
  64. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -0
  65. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -0
  66. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -0
  67. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -0
  68. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -0
  69. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -0
  70. package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -0
  71. package/dependencies/lz4/LICENSE +11 -0
  72. package/dependencies/lz4/lib/LICENSE +24 -0
  73. package/dependencies/lz4/lib/Makefile +225 -0
  74. package/dependencies/lz4/lib/README.md +169 -0
  75. package/dependencies/lz4/lib/dll/example/Makefile +63 -0
  76. package/dependencies/lz4/lib/dll/example/README.md +69 -0
  77. package/dependencies/lz4/lib/dll/example/fullbench-dll.sln +25 -0
  78. package/dependencies/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
  79. package/dependencies/lz4/lib/dll/liblz4.def +62 -0
  80. package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -0
  81. package/dependencies/lz4/lib/liblz4.pc.in +14 -0
  82. package/dependencies/lz4/lib/lz4.c +2722 -0
  83. package/dependencies/lz4/lib/lz4.h +842 -0
  84. package/dependencies/lz4/lib/lz4file.c +311 -0
  85. package/dependencies/lz4/lib/lz4file.h +93 -0
  86. package/dependencies/lz4/lib/lz4frame.c +2078 -0
  87. package/dependencies/lz4/lib/lz4frame.h +692 -0
  88. package/dependencies/lz4/lib/lz4frame_static.h +47 -0
  89. package/dependencies/lz4/lib/lz4hc.c +1631 -0
  90. package/dependencies/lz4/lib/lz4hc.h +413 -0
  91. package/dependencies/lz4/lib/xxhash.c +1030 -0
  92. package/dependencies/lz4/lib/xxhash.h +328 -0
  93. package/dependencies/v8/v8-fast-api-calls-v16.h +791 -0
  94. package/dependencies/v8/v8-fast-api-calls.h +888 -0
  95. package/dict/dict.txt +1 -0
  96. package/dict/dict2.txt +1 -0
  97. package/dist/index.cjs +2950 -0
  98. package/dist/index.cjs.map +1 -0
  99. package/index.d.cts +420 -0
  100. package/index.d.ts +450 -0
  101. package/index.js +38 -0
  102. package/keys.js +116 -0
  103. package/level.js +27 -0
  104. package/native.js +85 -0
  105. package/node-index.js +32 -0
  106. package/open.js +448 -0
  107. package/package.json +124 -0
  108. package/read.js +833 -0
  109. package/rollup.config.js +12 -0
  110. package/src/compression.cpp +225 -0
  111. package/src/cursor.cpp +395 -0
  112. package/src/dbi.cpp +382 -0
  113. package/src/env.cpp +1030 -0
  114. package/src/lmdb-js.cpp +64 -0
  115. package/src/lmdb-js.h +633 -0
  116. package/src/misc.cpp +593 -0
  117. package/src/ordered-binary.cpp +46 -0
  118. package/src/txn.cpp +210 -0
  119. package/src/v8-functions.cpp +170 -0
  120. package/src/windows.c +35 -0
  121. package/src/writer.cpp +537 -0
  122. package/util/RangeIterable.js +236 -0
  123. package/util/set-optional-deps.cjs +14 -0
  124. package/util/when.js +8 -0
  125. package/write.js +912 -0
@@ -0,0 +1,1817 @@
1
+ /** @file lmdb.h
2
+ * @brief Lightning memory-mapped database library
3
+ *
4
+ * @mainpage Lightning Memory-Mapped Database Manager (LMDB)
5
+ *
6
+ * @section intro_sec Introduction
7
+ * LMDB is a Btree-based database management library modeled loosely on the
8
+ * BerkeleyDB API, but much simplified. The entire database is exposed
9
+ * in a memory map, and all data fetches return data directly
10
+ * from the mapped memory, so no malloc's or memcpy's occur during
11
+ * data fetches. As such, the library is extremely simple because it
12
+ * requires no page caching layer of its own, and it is extremely high
13
+ * performance and memory-efficient. It is also fully transactional with
14
+ * full ACID semantics, and when the memory map is read-only, the
15
+ * database integrity cannot be corrupted by stray pointer writes from
16
+ * application code.
17
+ *
18
+ * The library is fully thread-aware and supports concurrent read/write
19
+ * access from multiple processes and threads. Data pages use a copy-on-
20
+ * write strategy so no active data pages are ever overwritten, which
21
+ * also provides resistance to corruption and eliminates the need of any
22
+ * special recovery procedures after a system crash. Writes are fully
23
+ * serialized; only one write transaction may be active at a time, which
24
+ * guarantees that writers can never deadlock. The database structure is
25
+ * multi-versioned so readers run with no locks; writers cannot block
26
+ * readers, and readers don't block writers.
27
+ *
28
+ * Unlike other well-known database mechanisms which use either write-ahead
29
+ * transaction logs or append-only data writes, LMDB requires no maintenance
30
+ * during operation. Both write-ahead loggers and append-only databases
31
+ * require periodic checkpointing and/or compaction of their log or database
32
+ * files otherwise they grow without bound. LMDB tracks free pages within
33
+ * the database and re-uses them for new write operations, so the database
34
+ * size does not grow without bound in normal use.
35
+ *
36
+ * The memory map can be used as a read-only or read-write map. It is
37
+ * read-only by default as this provides total immunity to corruption.
38
+ * Using read-write mode offers much higher write performance, but adds
39
+ * the possibility for stray application writes thru pointers to silently
40
+ * corrupt the database. Of course if your application code is known to
41
+ * be bug-free (...) then this is not an issue.
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
+ *
46
+ * @section caveats_sec Caveats
47
+ * Troubleshooting the lock file, plus semaphores on BSD systems:
48
+ *
49
+ * - A broken lockfile can cause sync issues.
50
+ * Stale reader transactions left behind by an aborted program
51
+ * cause further writes to grow the database quickly, and
52
+ * stale locks can block further operation.
53
+ *
54
+ * Fix: Check for stale readers periodically, using the
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.
62
+ *
63
+ * - On BSD systems or others configured with MDB_USE_SYSV_SEM or
64
+ * MDB_USE_POSIX_SEM,
65
+ * startup can fail due to semaphores owned by another userid.
66
+ *
67
+ * Fix: Open and close the database as the user which owns the
68
+ * semaphores (likely last user) or as root, while no other
69
+ * process is using the database.
70
+ *
71
+ * Restrictions/caveats (in addition to those listed for some functions):
72
+ *
73
+ * - Only the database owner should normally use the database on
74
+ * BSD systems or when otherwise configured with MDB_USE_POSIX_SEM.
75
+ * Multiple users can cause startup to fail later, as noted above.
76
+ *
77
+ * - There is normally no pure read-only mode, since readers need write
78
+ * access to locks and lock file. Exceptions: On read-only filesystems
79
+ * or with the #MDB_NOLOCK flag described under #mdb_env_open().
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
+ *
86
+ * - By default, in versions before 0.9.10, unused portions of the data
87
+ * file might receive garbage data from memory freed by other code.
88
+ * (This does not happen when using the #MDB_WRITEMAP flag.) As of
89
+ * 0.9.10 the default behavior is to initialize such memory before
90
+ * writing to the data file. Since there may be a slight performance
91
+ * cost due to this initialization, applications may disable it using
92
+ * the #MDB_NOMEMINIT flag. Applications handling sensitive data
93
+ * which must not be written should not use this flag. This flag is
94
+ * irrelevant when using #MDB_WRITEMAP.
95
+ *
96
+ * - A thread can only use one transaction at a time, plus any child
97
+ * transactions. Each transaction belongs to one thread. See below.
98
+ * The #MDB_NOTLS flag changes this for read-only transactions.
99
+ *
100
+ * - Use an MDB_env* in the process which opened it, not after fork().
101
+ *
102
+ * - Do not have open an LMDB database twice in the same process at
103
+ * the same time. Not even from a plain open() call - close()ing it
104
+ * breaks fcntl() advisory locking. (It is OK to reopen it after
105
+ * fork() - exec*(), since the lockfile has FD_CLOEXEC set.)
106
+ *
107
+ * - Avoid long-lived transactions. Read transactions prevent
108
+ * reuse of pages freed by newer write transactions, thus the
109
+ * database can grow quickly. Write transactions prevent
110
+ * other write transactions, since writes are serialized.
111
+ *
112
+ * - Avoid suspending a process with active transactions. These
113
+ * would then be "long-lived" as above. Also read transactions
114
+ * suspended when writers commit could sometimes see wrong data.
115
+ *
116
+ * ...when several processes can use a database concurrently:
117
+ *
118
+ * - Avoid aborting a process with an active transaction.
119
+ * The transaction becomes "long-lived" as above until a check
120
+ * for stale readers is performed or the lockfile is reset,
121
+ * since the process may not remove it from the lockfile.
122
+ *
123
+ * This does not apply to write transactions if the system clears
124
+ * stale writers, see above.
125
+ *
126
+ * - If you do that anyway, do a periodic check for stale readers. Or
127
+ * close the environment once in a while, so the lockfile can get reset.
128
+ *
129
+ * - Do not use LMDB databases on remote filesystems, even between
130
+ * processes on the same host. This breaks flock() on some OSes,
131
+ * possibly memory map sync, and certainly sync between programs
132
+ * on different hosts.
133
+ *
134
+ * - Opening a database can fail if another process is opening or
135
+ * closing it at exactly the same time.
136
+ *
137
+ * @author Howard Chu, Symas Corporation.
138
+ *
139
+ * @copyright Copyright 2011-2021 Howard Chu, Symas Corp. All rights reserved.
140
+ *
141
+ * Redistribution and use in source and binary forms, with or without
142
+ * modification, are permitted only as authorized by the OpenLDAP
143
+ * Public License.
144
+ *
145
+ * A copy of this license is available in the file LICENSE in the
146
+ * top-level directory of the distribution or, alternatively, at
147
+ * <http://www.OpenLDAP.org/license.html>.
148
+ *
149
+ * @par Derived From:
150
+ * This code is derived from btree.c written by Martin Hedenfalk.
151
+ *
152
+ * Copyright (c) 2009, 2010 Martin Hedenfalk <martin@bzero.se>
153
+ *
154
+ * Permission to use, copy, modify, and distribute this software for any
155
+ * purpose with or without fee is hereby granted, provided that the above
156
+ * copyright notice and this permission notice appear in all copies.
157
+ *
158
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
159
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
160
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
161
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
162
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
163
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
164
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165
+ */
166
+ #ifndef _LMDB_H_
167
+ #define _LMDB_H_
168
+
169
+ #include <sys/types.h>
170
+ #include <inttypes.h>
171
+ #include <limits.h>
172
+ #include <time.h>
173
+
174
+ #ifdef __cplusplus
175
+ extern "C" {
176
+ #endif
177
+
178
+ /** Unix permissions for creating files, or dummy definition for Windows */
179
+ #ifdef _MSC_VER
180
+ typedef int mdb_mode_t;
181
+ #else
182
+ typedef mode_t mdb_mode_t;
183
+ #endif
184
+
185
+ #ifdef _WIN32
186
+ # define MDB_FMT_Z "I"
187
+ #else
188
+ # define MDB_FMT_Z "z" /**< printf/scanf format modifier for size_t */
189
+ #endif
190
+
191
+ #if !defined(MDB_RPAGE_CACHE) || (defined(MDB_VL32) && !(MDB_RPAGE_CACHE))
192
+ /** Support #MDB_REMAP_CHUNKS. Implied by MDB_VL32. Define as 0 to disable. */
193
+ #define MDB_RPAGE_CACHE 1
194
+ #endif
195
+
196
+ #ifndef MDB_VL32
197
+ /** Unsigned type used for mapsize, entry counts and page/transaction IDs.
198
+ *
199
+ * It is normally size_t, hence the name. Defining MDB_VL32 makes it
200
+ * uint64_t, but do not try this unless you know what you are doing.
201
+ */
202
+ typedef size_t mdb_size_t;
203
+ # define MDB_SIZE_MAX SIZE_MAX /**< max #mdb_size_t */
204
+ /** #mdb_size_t printf formats, \b t = one of [diouxX] without quotes */
205
+ # define MDB_PRIy(t) MDB_FMT_Z #t
206
+ /** #mdb_size_t scanf formats, \b t = one of [dioux] without quotes */
207
+ # define MDB_SCNy(t) MDB_FMT_Z #t
208
+ #else
209
+ typedef uint64_t mdb_size_t;
210
+ # define MDB_SIZE_MAX UINT64_MAX
211
+ # define MDB_PRIy(t) PRI##t##64
212
+ # define MDB_SCNy(t) SCN##t##64
213
+ # define mdb_env_create mdb_env_create_vl32 /**< Prevent mixing with non-VL32 builds */
214
+ #endif
215
+
216
+ /** An abstraction for a file handle.
217
+ * On POSIX systems file handles are small integers. On Windows
218
+ * they're opaque pointers.
219
+ */
220
+ #ifdef _WIN32
221
+ typedef void *mdb_filehandle_t;
222
+ #else
223
+ typedef int mdb_filehandle_t;
224
+ #endif
225
+
226
+ /** @defgroup mdb LMDB API
227
+ * @{
228
+ * @brief Symas Lightning Memory-Mapped Database Manager
229
+ */
230
+ /** @defgroup Version Version Macros
231
+ * @{
232
+ */
233
+ /** Library major version */
234
+ #define MDB_VERSION_MAJOR 0
235
+ /** Library minor version */
236
+ #define MDB_VERSION_MINOR 9
237
+ /** Library patch version */
238
+ #define MDB_VERSION_PATCH 90
239
+
240
+ /** Combine args a,b,c into a single integer for easy version comparisons */
241
+ #define MDB_VERINT(a,b,c) (((a) << 24) | ((b) << 16) | (c))
242
+
243
+ /** The full library version as a single integer */
244
+ #define MDB_VERSION_FULL \
245
+ MDB_VERINT(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH)
246
+
247
+ /** The release date of this library version */
248
+ #define MDB_VERSION_DATE "May 1, 2017"
249
+
250
+ /** A stringifier for the version info */
251
+ #define MDB_VERSTR(a,b,c,d) "LMDB " #a "." #b "." #c ": (" d ")"
252
+
253
+ /** A helper for the stringifier macro */
254
+ #define MDB_VERFOO(a,b,c,d) MDB_VERSTR(a,b,c,d)
255
+
256
+ /** The full library version as a C string */
257
+ #define MDB_VERSION_STRING \
258
+ MDB_VERFOO(MDB_VERSION_MAJOR,MDB_VERSION_MINOR,MDB_VERSION_PATCH,MDB_VERSION_DATE)
259
+ /** @} */
260
+
261
+ /** @brief Opaque structure for a database environment.
262
+ *
263
+ * A DB environment supports multiple databases, all residing in the same
264
+ * shared-memory map.
265
+ */
266
+ typedef struct MDB_env MDB_env;
267
+
268
+ /** @brief Opaque structure for a transaction handle.
269
+ *
270
+ * All database operations require a transaction handle. Transactions may be
271
+ * read-only or read-write.
272
+ */
273
+ typedef struct MDB_txn MDB_txn;
274
+
275
+ /** @brief A handle for an individual database in the DB environment. */
276
+ typedef unsigned int MDB_dbi;
277
+
278
+ /** @brief Opaque structure for navigating through a database */
279
+ typedef struct MDB_cursor MDB_cursor;
280
+
281
+ /** @brief Generic structure used for passing keys and data in and out
282
+ * of the database.
283
+ *
284
+ * Values returned from the database are valid only until a subsequent
285
+ * update operation, or the end of the transaction. Do not modify or
286
+ * free them, they commonly point into the database itself.
287
+ *
288
+ * Key sizes must be between 1 and #mdb_env_get_maxkeysize() inclusive.
289
+ * The same applies to data sizes in databases with the #MDB_DUPSORT flag.
290
+ * Other data items can in theory be from 0 to 0xffffffff bytes long.
291
+ */
292
+ typedef struct MDB_val {
293
+ size_t mv_size; /**< size of the data item */
294
+ void *mv_data; /**< address of the data item */
295
+ } MDB_val;
296
+
297
+
298
+ /** @brief A callback function used to compare two keys in a database */
299
+ typedef int (MDB_cmp_func)(const MDB_val *a, const MDB_val *b);
300
+
301
+ /** @brief A callback function used to relocate a position-dependent data item
302
+ * in a fixed-address database.
303
+ *
304
+ * The \b newptr gives the item's desired address in
305
+ * the memory map, and \b oldptr gives its previous address. The item's actual
306
+ * data resides at the address in \b item. This callback is expected to walk
307
+ * through the fields of the record in \b item and modify any
308
+ * values based at the \b oldptr address to be relative to the \b newptr address.
309
+ * @param[in,out] item The item that is to be relocated.
310
+ * @param[in] oldptr The previous address.
311
+ * @param[in] newptr The new address to relocate to.
312
+ * @param[in] relctx An application-provided context, set by #mdb_set_relctx().
313
+ * @todo This feature is currently unimplemented.
314
+ */
315
+ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *relctx);
316
+
317
+ #if MDB_RPAGE_CACHE
318
+ /** @brief A callback function used to encrypt/decrypt pages in the env.
319
+ *
320
+ * Encrypt or decrypt the data in src and store the result in dst using the
321
+ * provided key. The result must be the same number of bytes as the input.
322
+ * @param[in] src The input data to be transformed.
323
+ * @param[out] dst Storage for the result.
324
+ * @param[in] key An array of three values: key[0] is the encryption key,
325
+ * key[1] is the initialization vector, and key[2] is the authentication
326
+ * data, if any.
327
+ * @param[in] encdec 1 to encrypt, 0 to decrypt.
328
+ * @return A non-zero error value on failure and 0 on success.
329
+ */
330
+ typedef int (MDB_enc_func)(const MDB_val *src, MDB_val *dst, const MDB_val *key, int encdec);
331
+
332
+ /** @brief A callback function used to checksum pages in the env.
333
+ *
334
+ * Compute the checksum of the data in src and store the result in dst,
335
+ * An optional key may be used with keyed hash algorithms.
336
+ * @param[in] src The input data to be transformed.
337
+ * @param[out] dst Storage for the result.
338
+ * @param[in] key An encryption key, if encryption was configured. This
339
+ * parameter will be NULL if there is no key.
340
+ */
341
+ typedef void (MDB_sum_func)(const MDB_val *src, MDB_val *dst, const MDB_val *key);
342
+ #endif
343
+
344
+ /** @defgroup mdb_env Environment Flags
345
+ * @{
346
+ */
347
+ /** mmap at a fixed address (experimental) */
348
+ #define MDB_FIXEDMAP 0x01
349
+ /** Use overlapping sync approach */
350
+ #define MDB_OVERLAPPINGSYNC 0x1000
351
+ /** encrypted DB - read-only flag, set by #mdb_env_set_encrypt() */
352
+ #define MDB_ENCRYPT 0x2000U
353
+ /** no environment directory */
354
+ #define MDB_NOSUBDIR 0x4000
355
+ /** don't fsync after commit */
356
+ #define MDB_NOSYNC 0x10000
357
+ /** read only */
358
+ #define MDB_RDONLY 0x20000
359
+ /** don't fsync metapage after commit */
360
+ #define MDB_NOMETASYNC 0x40000
361
+ /** use writable mmap */
362
+ #define MDB_WRITEMAP 0x80000
363
+ /** use asynchronous msync when #MDB_WRITEMAP is used */
364
+ #define MDB_MAPASYNC 0x100000
365
+ /** tie reader locktable slots to #MDB_txn objects instead of to threads */
366
+ #define MDB_NOTLS 0x200000
367
+ /** don't do any locking, caller must manage their own locks */
368
+ #define MDB_NOLOCK 0x400000
369
+ /** don't do readahead (no effect on Windows) */
370
+ #define MDB_NORDAHEAD 0x800000
371
+ /** don't initialize malloc'd memory before writing to datafile */
372
+ #define MDB_NOMEMINIT 0x1000000
373
+ /** use the previous snapshot rather than the latest one */
374
+ #define MDB_PREVSNAPSHOT 0x2000000
375
+ /** don't use a single mmap, remap individual chunks (needs MDB_RPAGE_CACHE) */
376
+ #define MDB_REMAP_CHUNKS 0x4000000
377
+ /** Don't consult boot_id and assume that only the "flushed" txn is valid */
378
+ #define MDB_SAFE_RESTORE 0x800
379
+ /** Track metrics for this env */
380
+ #define MDB_TRACK_METRICS 0x400
381
+ /** Use the overlapping sync strategy */
382
+ #define MDB_OVERLAPPINGSYNC_SYNC = 0x02
383
+ /** @} */
384
+
385
+
386
+ /** @defgroup mdb_dbi_open Database Flags
387
+ * @{
388
+ */
389
+ /** use reverse string keys */
390
+ #define MDB_REVERSEKEY 0x02
391
+ /** use sorted duplicates */
392
+ #define MDB_DUPSORT 0x04
393
+ /** numeric keys in native byte order, either unsigned int or #mdb_size_t.
394
+ * (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
395
+ * The keys must all be of the same size. */
396
+ #define MDB_INTEGERKEY 0x08
397
+ /** with #MDB_DUPSORT, sorted dup items have fixed size */
398
+ #define MDB_DUPFIXED 0x10
399
+ /** with #MDB_DUPSORT, dups are #MDB_INTEGERKEY-style integers */
400
+ #define MDB_INTEGERDUP 0x20
401
+ /** with #MDB_DUPSORT, use reverse string dups */
402
+ #define MDB_REVERSEDUP 0x40
403
+ /** create DB if not already existing */
404
+ #define MDB_CREATE 0x40000
405
+ /** @} */
406
+
407
+ /** @defgroup mdb_put Write Flags
408
+ * @{
409
+ */
410
+ /** For put: Don't write if the key already exists. */
411
+ #define MDB_NOOVERWRITE 0x10
412
+ /** Only for #MDB_DUPSORT<br>
413
+ * For put: don't write if the key and data pair already exist.<br>
414
+ * For mdb_cursor_del: remove all duplicate data items.
415
+ */
416
+ #define MDB_NODUPDATA 0x20
417
+ /** For mdb_cursor_put: overwrite the current key/data pair */
418
+ #define MDB_CURRENT 0x40
419
+ /** For put: Just reserve space for data, don't copy it. Return a
420
+ * pointer to the reserved space.
421
+ */
422
+ #define MDB_RESERVE 0x10000
423
+ /** Data is being appended, don't split full pages. */
424
+ #define MDB_APPEND 0x20000
425
+ /** Duplicate data is being appended, don't split full pages. */
426
+ #define MDB_APPENDDUP 0x40000
427
+ /** Store multiple data items in one call. Only for #MDB_DUPFIXED. */
428
+ #define MDB_MULTIPLE 0x80000
429
+ /* @} */
430
+
431
+ /** @defgroup mdb_copy Copy Flags
432
+ * @{
433
+ */
434
+ /** Compacting copy: Omit free space from copy, and renumber all
435
+ * pages sequentially.
436
+ */
437
+ #define MDB_CP_COMPACT 0x01
438
+ /* @} */
439
+
440
+ /** @brief Cursor Get operations.
441
+ *
442
+ * This is the set of all operations for retrieving data
443
+ * using a cursor.
444
+ */
445
+ typedef enum MDB_cursor_op {
446
+ MDB_FIRST, /**< Position at first key/data item */
447
+ MDB_FIRST_DUP, /**< Position at first data item of current key.
448
+ Only for #MDB_DUPSORT */
449
+ MDB_GET_BOTH, /**< Position at key/data pair. Only for #MDB_DUPSORT */
450
+ MDB_GET_BOTH_RANGE, /**< position at key, nearest data. Only for #MDB_DUPSORT */
451
+ MDB_GET_CURRENT, /**< Return key/data at current cursor position */
452
+ MDB_GET_MULTIPLE, /**< Return up to a page of duplicate data items
453
+ from current cursor position. Move cursor to prepare
454
+ for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
455
+ MDB_LAST, /**< Position at last key/data item */
456
+ MDB_LAST_DUP, /**< Position at last data item of current key.
457
+ Only for #MDB_DUPSORT */
458
+ MDB_NEXT, /**< Position at next data item */
459
+ MDB_NEXT_DUP, /**< Position at next data item of current key.
460
+ Only for #MDB_DUPSORT */
461
+ MDB_NEXT_MULTIPLE, /**< Return up to a page of duplicate data items
462
+ from next cursor position. Move cursor to prepare
463
+ for #MDB_NEXT_MULTIPLE. Only for #MDB_DUPFIXED */
464
+ MDB_NEXT_NODUP, /**< Position at first data item of next key */
465
+ MDB_PREV, /**< Position at previous data item */
466
+ MDB_PREV_DUP, /**< Position at previous data item of current key.
467
+ Only for #MDB_DUPSORT */
468
+ MDB_PREV_NODUP, /**< Position at last data item of previous key */
469
+ MDB_SET, /**< Position at specified key */
470
+ MDB_SET_KEY, /**< Position at specified key, return key + data */
471
+ MDB_SET_RANGE, /**< Position at first key greater than or equal to specified key. */
472
+ MDB_PREV_MULTIPLE /**< Position at previous page and return up to
473
+ a page of duplicate data items. Only for #MDB_DUPFIXED */
474
+ } MDB_cursor_op;
475
+
476
+ /** @defgroup errors Return Codes
477
+ *
478
+ * BerkeleyDB uses -30800 to -30999, we'll go under them
479
+ * @{
480
+ */
481
+ /** Successful result */
482
+ #define MDB_SUCCESS 0
483
+ /** key/data pair already exists */
484
+ #define MDB_KEYEXIST (-30799)
485
+ /** key/data pair not found (EOF) */
486
+ #define MDB_NOTFOUND (-30798)
487
+ /** Requested page not found - this usually indicates corruption */
488
+ #define MDB_PAGE_NOTFOUND (-30797)
489
+ /** Located page was wrong type */
490
+ #define MDB_CORRUPTED (-30796)
491
+ /** Update of meta page failed or environment had fatal error */
492
+ #define MDB_PANIC (-30795)
493
+ /** Environment version mismatch */
494
+ #define MDB_VERSION_MISMATCH (-30794)
495
+ /** File is not a valid LMDB file */
496
+ #define MDB_INVALID (-30793)
497
+ /** Environment mapsize reached */
498
+ #define MDB_MAP_FULL (-30792)
499
+ /** Environment maxdbs reached */
500
+ #define MDB_DBS_FULL (-30791)
501
+ /** Environment maxreaders reached */
502
+ #define MDB_READERS_FULL (-30790)
503
+ /** Too many TLS keys in use - Windows only */
504
+ #define MDB_TLS_FULL (-30789)
505
+ /** Txn has too many dirty pages */
506
+ #define MDB_TXN_FULL (-30788)
507
+ /** Cursor stack too deep - internal error */
508
+ #define MDB_CURSOR_FULL (-30787)
509
+ /** Page has not enough space - internal error */
510
+ #define MDB_PAGE_FULL (-30786)
511
+ /** Database contents grew beyond environment mapsize */
512
+ #define MDB_MAP_RESIZED (-30785)
513
+ /** Operation and DB incompatible, or DB type changed. This can mean:
514
+ * <ul>
515
+ * <li>The operation expects an #MDB_DUPSORT / #MDB_DUPFIXED database.
516
+ * <li>Opening a named DB when the unnamed DB has #MDB_DUPSORT / #MDB_INTEGERKEY.
517
+ * <li>Accessing a data record as a database, or vice versa.
518
+ * <li>The database was dropped and recreated with different flags.
519
+ * </ul>
520
+ */
521
+ #define MDB_INCOMPATIBLE (-30784)
522
+ /** Invalid reuse of reader locktable slot */
523
+ #define MDB_BAD_RSLOT (-30783)
524
+ /** Transaction must abort, has a child, or is invalid */
525
+ #define MDB_BAD_TXN (-30782)
526
+ /** Unsupported size of key/DB name/data, or wrong DUPFIXED size */
527
+ #define MDB_BAD_VALSIZE (-30781)
528
+ /** The specified DBI was changed unexpectedly */
529
+ #define MDB_BAD_DBI (-30780)
530
+ /** Unexpected problem - txn should abort */
531
+ #define MDB_PROBLEM (-30779)
532
+ /** Page checksum incorrect */
533
+ #define MDB_BAD_CHECKSUM (-30778)
534
+ /** Encryption/decryption failed */
535
+ #define MDB_CRYPTO_FAIL (-30777)
536
+ /** Environment encryption mismatch */
537
+ #define MDB_ENV_ENCRYPTION (-30776)
538
+ /** Unable to acquire a robust mutex */
539
+ #define MDB_LOCK_FAILURE (-30775)
540
+ /** The transaction was empty (not an error, but informative) */
541
+ #define MDB_EMPTY_TXN (-30774)
542
+ /** The last defined error code */
543
+ #define MDB_LAST_ERRCODE MDB_EMPTY_TXN
544
+ /** @} */
545
+
546
+ typedef struct MDB_metrics {
547
+ mdb_size_t puts;
548
+ mdb_size_t deletes;
549
+ mdb_size_t txns;
550
+ mdb_size_t page_flushes;
551
+ mdb_size_t writes;
552
+ mdb_size_t pages_written;
553
+ uint64_t clock_txn;
554
+ uint64_t time_during_txns;
555
+ uint64_t time_start_txns;
556
+ uint64_t time_page_flushes;
557
+ uint64_t time_sync;
558
+ } MDB_metrics;
559
+
560
+ /** @brief Statistics for a database in the environment */
561
+ typedef struct MDB_stat {
562
+ unsigned int ms_psize; /**< Size of a database page.
563
+ This is currently the same for all databases. */
564
+ unsigned int ms_depth; /**< Depth (height) of the B-tree */
565
+ mdb_size_t ms_branch_pages; /**< Number of internal (non-leaf) pages */
566
+ mdb_size_t ms_leaf_pages; /**< Number of leaf pages */
567
+ mdb_size_t ms_overflow_pages; /**< Number of overflow pages */
568
+ mdb_size_t ms_entries; /**< Number of data items */
569
+ } MDB_stat;
570
+
571
+ /** @brief Information about the environment */
572
+ typedef struct MDB_envinfo {
573
+ void *me_mapaddr; /**< Address of map, if fixed */
574
+ mdb_size_t me_mapsize; /**< Size of the data memory map */
575
+ mdb_size_t me_last_pgno; /**< ID of the last used page */
576
+ mdb_size_t me_last_txnid; /**< ID of the last committed transaction */
577
+ unsigned int me_maxreaders; /**< max reader slots in the environment */
578
+ unsigned int me_numreaders; /**< max reader slots used in the environment */
579
+ } MDB_envinfo;
580
+
581
+ /** @brief Return the LMDB library version information.
582
+ *
583
+ * @param[out] major if non-NULL, the library major version number is copied here
584
+ * @param[out] minor if non-NULL, the library minor version number is copied here
585
+ * @param[out] patch if non-NULL, the library patch version number is copied here
586
+ * @retval "version string" The library version as a string
587
+ */
588
+ char *mdb_version(int *major, int *minor, int *patch);
589
+
590
+ /** @brief Return a string describing a given error code.
591
+ *
592
+ * This function is a superset of the ANSI C X3.159-1989 (ANSI C) strerror(3)
593
+ * function. If the error code is greater than or equal to 0, then the string
594
+ * returned by the system function strerror(3) is returned. If the error code
595
+ * is less than 0, an error string corresponding to the LMDB library error is
596
+ * returned. See @ref errors for a list of LMDB-specific error codes.
597
+ * @param[in] err The error code
598
+ * @retval "error message" The description of the error
599
+ */
600
+ char *mdb_strerror(int err);
601
+
602
+ /** @brief Create an LMDB environment handle.
603
+ *
604
+ * This function allocates memory for a #MDB_env structure. To release
605
+ * the allocated memory and discard the handle, call #mdb_env_close().
606
+ * Before the handle may be used, it must be opened using #mdb_env_open().
607
+ * Various other options may also need to be set before opening the handle,
608
+ * e.g. #mdb_env_set_mapsize(), #mdb_env_set_maxreaders(), #mdb_env_set_maxdbs(),
609
+ * depending on usage requirements.
610
+ * @param[out] env The address where the new handle will be stored
611
+ * @return A non-zero error value on failure and 0 on success.
612
+ */
613
+ int mdb_env_create(MDB_env **env);
614
+
615
+ /** @brief Open an environment handle.
616
+ *
617
+ * If this function fails, #mdb_env_close() must be called to discard the #MDB_env handle.
618
+ * @param[in] env An environment handle returned by #mdb_env_create()
619
+ * @param[in] path The directory in which the database files reside. This
620
+ * directory must already exist and be writable.
621
+ * @param[in] flags Special options for this environment. This parameter
622
+ * must be set to 0 or by bitwise OR'ing together one or more of the
623
+ * values described here.
624
+ * Flags set by mdb_env_set_flags() are also used.
625
+ * <ul>
626
+ * <li>#MDB_FIXEDMAP
627
+ * use a fixed address for the mmap region. This flag must be specified
628
+ * when creating the environment, and is stored persistently in the environment.
629
+ * If successful, the memory map will always reside at the same virtual address
630
+ * and pointers used to reference data items in the database will be constant
631
+ * across multiple invocations. This option may not always work, depending on
632
+ * how the operating system has allocated memory to shared libraries and other uses.
633
+ * The feature is highly experimental.
634
+ * <li>#MDB_NOSUBDIR
635
+ * By default, LMDB creates its environment in a directory whose
636
+ * pathname is given in \b path, and creates its data and lock files
637
+ * under that directory. With this option, \b path is used as-is for
638
+ * the database main data file. The database lock file is the \b path
639
+ * with "-lock" appended.
640
+ * <li>#MDB_RDONLY
641
+ * Open the environment in read-only mode. No write operations will be
642
+ * allowed. LMDB will still modify the lock file - except on read-only
643
+ * filesystems, where LMDB does not use locks.
644
+ * <li>#MDB_WRITEMAP
645
+ * Use a writeable memory map unless MDB_RDONLY is set. This uses
646
+ * fewer mallocs but loses protection from application bugs
647
+ * like wild pointer writes and other bad updates into the database.
648
+ * This may be slightly faster for DBs that fit entirely in RAM, but
649
+ * is slower for DBs larger than RAM.
650
+ * Incompatible with nested transactions.
651
+ * Do not mix processes with and without MDB_WRITEMAP on the same
652
+ * environment. This can defeat durability (#mdb_env_sync etc).
653
+ * <li>#MDB_NOMETASYNC
654
+ * Flush system buffers to disk only once per transaction, omit the
655
+ * metadata flush. Defer that until the system flushes files to disk,
656
+ * or next non-MDB_RDONLY commit or #mdb_env_sync(). This optimization
657
+ * maintains database integrity, but a system crash may undo the last
658
+ * committed transaction. I.e. it preserves the ACI (atomicity,
659
+ * consistency, isolation) but not D (durability) database property.
660
+ * This flag may be changed at any time using #mdb_env_set_flags().
661
+ * <li>#MDB_NOSYNC
662
+ * Don't flush system buffers to disk when committing a transaction.
663
+ * This optimization means a system crash can corrupt the database or
664
+ * lose the last transactions if buffers are not yet flushed to disk.
665
+ * The risk is governed by how often the system flushes dirty buffers
666
+ * to disk and how often #mdb_env_sync() is called. However, if the
667
+ * filesystem preserves write order and the #MDB_WRITEMAP flag is not
668
+ * used, transactions exhibit ACI (atomicity, consistency, isolation)
669
+ * properties and only lose D (durability). I.e. database integrity
670
+ * is maintained, but a system crash may undo the final transactions.
671
+ * Note that (#MDB_NOSYNC | #MDB_WRITEMAP) leaves the system with no
672
+ * hint for when to write transactions to disk, unless #mdb_env_sync()
673
+ * is called. (#MDB_MAPASYNC | #MDB_WRITEMAP) may be preferable.
674
+ * This flag may be changed at any time using #mdb_env_set_flags().
675
+ * <li>#MDB_MAPASYNC
676
+ * When using #MDB_WRITEMAP, use asynchronous flushes to disk.
677
+ * As with #MDB_NOSYNC, a system crash can then corrupt the
678
+ * database or lose the last transactions. Calling #mdb_env_sync()
679
+ * ensures on-disk database integrity until next commit.
680
+ * This flag may be changed at any time using #mdb_env_set_flags().
681
+ * <li>#MDB_NOTLS
682
+ * Don't use Thread-Local Storage. Tie reader locktable slots to
683
+ * #MDB_txn objects instead of to threads. I.e. #mdb_txn_reset() keeps
684
+ * the slot reserved for the #MDB_txn object. A thread may use parallel
685
+ * read-only transactions. A read-only transaction may span threads if
686
+ * the user synchronizes its use. Applications that multiplex many
687
+ * user threads over individual OS threads need this option. Such an
688
+ * application must also serialize the write transactions in an OS
689
+ * thread, since LMDB's write locking is unaware of the user threads.
690
+ * <li>#MDB_NOLOCK
691
+ * Don't do any locking. If concurrent access is anticipated, the
692
+ * caller must manage all concurrency itself. For proper operation
693
+ * the caller must enforce single-writer semantics, and must ensure
694
+ * that no readers are using old transactions while a writer is
695
+ * active. The simplest approach is to use an exclusive lock so that
696
+ * no readers may be active at all when a writer begins.
697
+ * <li>#MDB_NORDAHEAD
698
+ * Turn off readahead. Most operating systems perform readahead on
699
+ * read requests by default. This option turns it off if the OS
700
+ * supports it. Turning it off may help random read performance
701
+ * when the DB is larger than RAM and system RAM is full.
702
+ * The option is not implemented on Windows.
703
+ * <li>#MDB_NOMEMINIT
704
+ * Don't initialize malloc'd memory before writing to unused spaces
705
+ * in the data file. By default, memory for pages written to the data
706
+ * file is obtained using malloc. While these pages may be reused in
707
+ * subsequent transactions, freshly malloc'd pages will be initialized
708
+ * to zeroes before use. This avoids persisting leftover data from other
709
+ * code (that used the heap and subsequently freed the memory) into the
710
+ * data file. Note that many other system libraries may allocate
711
+ * and free memory from the heap for arbitrary uses. E.g., stdio may
712
+ * use the heap for file I/O buffers. This initialization step has a
713
+ * modest performance cost so some applications may want to disable
714
+ * it using this flag. This option can be a problem for applications
715
+ * which handle sensitive data like passwords, and it makes memory
716
+ * checkers like Valgrind noisy. This flag is not needed with #MDB_WRITEMAP,
717
+ * which writes directly to the mmap instead of using malloc for pages. The
718
+ * initialization is also skipped if #MDB_RESERVE is used; the
719
+ * caller is expected to overwrite all of the memory that was
720
+ * reserved in that case.
721
+ * This flag may be changed at any time using #mdb_env_set_flags().
722
+ * <li>#MDB_PREVSNAPSHOT
723
+ * Open the environment with the previous snapshot rather than the latest
724
+ * one. This loses the latest transaction, but may help work around some
725
+ * types of corruption. If opened with write access, this must be the
726
+ * only process using the environment. This flag is automatically reset
727
+ * after a write transaction is successfully committed.
728
+ * </ul>
729
+ * @param[in] mode The UNIX permissions to set on created files and semaphores.
730
+ * This parameter is ignored on Windows.
731
+ * @return A non-zero error value on failure and 0 on success. Some possible
732
+ * errors are:
733
+ * <ul>
734
+ * <li>#MDB_VERSION_MISMATCH - the version of the LMDB library doesn't match the
735
+ * version that created the database environment.
736
+ * <li>#MDB_INVALID - the environment file headers are corrupted.
737
+ * <li>ENOENT - the directory specified by the path parameter doesn't exist.
738
+ * <li>EACCES - the user didn't have permission to access the environment files.
739
+ * <li>EAGAIN - the environment was locked by another process.
740
+ * </ul>
741
+ */
742
+ int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode);
743
+
744
+ /** @brief Copy an LMDB environment to the specified path.
745
+ *
746
+ * This function may be used to make a backup of an existing environment.
747
+ * No lockfile is created, since it gets recreated at need.
748
+ * @note This call can trigger significant file size growth if run in
749
+ * parallel with write transactions, because it employs a read-only
750
+ * transaction. See long-lived transactions under @ref caveats_sec.
751
+ * @param[in] env An environment handle returned by #mdb_env_create(). It
752
+ * must have already been opened successfully.
753
+ * @param[in] path The directory in which the copy will reside. This
754
+ * directory must already exist and be writable but must otherwise be
755
+ * empty.
756
+ * @return A non-zero error value on failure and 0 on success.
757
+ */
758
+ int mdb_env_copy(MDB_env *env, const char *path);
759
+
760
+ /** @brief Copy an LMDB environment to the specified file descriptor.
761
+ *
762
+ * This function may be used to make a backup of an existing environment.
763
+ * No lockfile is created, since it gets recreated at need.
764
+ * @note This call can trigger significant file size growth if run in
765
+ * parallel with write transactions, because it employs a read-only
766
+ * transaction. See long-lived transactions under @ref caveats_sec.
767
+ * @param[in] env An environment handle returned by #mdb_env_create(). It
768
+ * must have already been opened successfully.
769
+ * @param[in] fd The filedescriptor to write the copy to. It must
770
+ * have already been opened for Write access.
771
+ * @return A non-zero error value on failure and 0 on success.
772
+ */
773
+ int mdb_env_copyfd(MDB_env *env, mdb_filehandle_t fd);
774
+
775
+ /** @brief Copy an LMDB environment to the specified path, with options.
776
+ *
777
+ * This function may be used to make a backup of an existing environment.
778
+ * No lockfile is created, since it gets recreated at need.
779
+ * @note This call can trigger significant file size growth if run in
780
+ * parallel with write transactions, because it employs a read-only
781
+ * transaction. See long-lived transactions under @ref caveats_sec.
782
+ * @param[in] env An environment handle returned by #mdb_env_create(). It
783
+ * must have already been opened successfully.
784
+ * @param[in] path The directory in which the copy will reside. This
785
+ * directory must already exist and be writable but must otherwise be
786
+ * empty.
787
+ * @param[in] flags Special options for this operation. This parameter
788
+ * must be set to 0 or by bitwise OR'ing together one or more of the
789
+ * values described here.
790
+ * <ul>
791
+ * <li>#MDB_CP_COMPACT - Perform compaction while copying: omit free
792
+ * pages and sequentially renumber all pages in output. This option
793
+ * consumes more CPU and runs more slowly than the default.
794
+ * Currently it fails if the environment has suffered a page leak.
795
+ * </ul>
796
+ * @return A non-zero error value on failure and 0 on success.
797
+ */
798
+ int mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags);
799
+
800
+ /** @brief Copy an LMDB environment to the specified file descriptor,
801
+ * with options.
802
+ *
803
+ * This function may be used to make a backup of an existing environment.
804
+ * No lockfile is created, since it gets recreated at need. See
805
+ * #mdb_env_copy2() for further details.
806
+ * @note This call can trigger significant file size growth if run in
807
+ * parallel with write transactions, because it employs a read-only
808
+ * transaction. See long-lived transactions under @ref caveats_sec.
809
+ * @param[in] env An environment handle returned by #mdb_env_create(). It
810
+ * must have already been opened successfully.
811
+ * @param[in] fd The filedescriptor to write the copy to. It must
812
+ * have already been opened for Write access.
813
+ * @param[in] flags Special options for this operation.
814
+ * See #mdb_env_copy2() for options.
815
+ * @return A non-zero error value on failure and 0 on success.
816
+ */
817
+ int mdb_env_copyfd2(MDB_env *env, mdb_filehandle_t fd, unsigned int flags);
818
+
819
+ /** @brief Return statistics about the LMDB environment.
820
+ *
821
+ * @param[in] env An environment handle returned by #mdb_env_create()
822
+ * @param[out] stat The address of an #MDB_stat structure
823
+ * where the statistics will be copied
824
+ */
825
+ int mdb_env_stat(MDB_env *env, MDB_stat *stat);
826
+
827
+ /** @brief Return information about the LMDB environment.
828
+ *
829
+ * @param[in] env An environment handle returned by #mdb_env_create()
830
+ * @param[out] stat The address of an #MDB_envinfo structure
831
+ * where the information will be copied
832
+ */
833
+ int mdb_env_info(MDB_env *env, MDB_envinfo *stat);
834
+
835
+ /** @brief Flush the data buffers to disk.
836
+ *
837
+ * Data is always written to disk when #mdb_txn_commit() is called,
838
+ * but the operating system may keep it buffered. LMDB always flushes
839
+ * the OS buffers upon commit as well, unless the environment was
840
+ * opened with #MDB_NOSYNC or in part #MDB_NOMETASYNC. This call is
841
+ * not valid if the environment was opened with #MDB_RDONLY.
842
+ * @param[in] env An environment handle returned by #mdb_env_create()
843
+ * @param[in] force If non-zero, force a synchronous flush. Otherwise
844
+ * if the environment has the #MDB_NOSYNC flag set the flushes
845
+ * will be omitted, and with #MDB_MAPASYNC they will be asynchronous.
846
+ * @return A non-zero error value on failure and 0 on success. Some possible
847
+ * errors are:
848
+ * <ul>
849
+ * <li>EACCES - the environment is read-only.
850
+ * <li>EINVAL - an invalid parameter was specified.
851
+ * <li>EIO - an error occurred during synchronization.
852
+ * </ul>
853
+ */
854
+ int mdb_env_sync(MDB_env *env, int force);
855
+
856
+ /** @brief Close the environment and release the memory map.
857
+ *
858
+ * Only a single thread may call this function. All transactions, databases,
859
+ * and cursors must already be closed before calling this function. Attempts to
860
+ * use any such handles after calling this function will cause a SIGSEGV.
861
+ * The environment handle will be freed and must not be used again after this call.
862
+ * @param[in] env An environment handle returned by #mdb_env_create()
863
+ */
864
+ void mdb_env_close(MDB_env *env);
865
+
866
+ /** @brief Set environment flags.
867
+ *
868
+ * This may be used to set some flags in addition to those from
869
+ * #mdb_env_open(), or to unset these flags. If several threads
870
+ * change the flags at the same time, the result is undefined.
871
+ * @param[in] env An environment handle returned by #mdb_env_create()
872
+ * @param[in] flags The flags to change, bitwise OR'ed together
873
+ * @param[in] onoff A non-zero value sets the flags, zero clears them.
874
+ * @return A non-zero error value on failure and 0 on success. Some possible
875
+ * errors are:
876
+ * <ul>
877
+ * <li>EINVAL - an invalid parameter was specified.
878
+ * </ul>
879
+ */
880
+ int mdb_env_set_flags(MDB_env *env, unsigned int flags, int onoff);
881
+
882
+ /** @brief Get environment flags.
883
+ *
884
+ * @param[in] env An environment handle returned by #mdb_env_create()
885
+ * @param[out] flags The address of an integer to store the flags
886
+ * @return A non-zero error value on failure and 0 on success. Some possible
887
+ * errors are:
888
+ * <ul>
889
+ * <li>EINVAL - an invalid parameter was specified.
890
+ * </ul>
891
+ */
892
+ int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
893
+
894
+ /** @brief Return the path that was used in #mdb_env_open().
895
+ *
896
+ * @param[in] env An environment handle returned by #mdb_env_create()
897
+ * @param[out] path Address of a string pointer to contain the path. This
898
+ * is the actual string in the environment, not a copy. It should not be
899
+ * altered in any way.
900
+ * @return A non-zero error value on failure and 0 on success. Some possible
901
+ * errors are:
902
+ * <ul>
903
+ * <li>EINVAL - an invalid parameter was specified.
904
+ * </ul>
905
+ */
906
+ int mdb_env_get_path(MDB_env *env, const char **path);
907
+
908
+ /** @brief Return the filedescriptor for the given environment.
909
+ *
910
+ * This function may be called after fork(), so the descriptor can be
911
+ * closed before exec*(). Other LMDB file descriptors have FD_CLOEXEC.
912
+ * (Until LMDB 0.9.18, only the lockfile had that.)
913
+ *
914
+ * @param[in] env An environment handle returned by #mdb_env_create()
915
+ * @param[out] fd Address of a mdb_filehandle_t to contain the descriptor.
916
+ * @return A non-zero error value on failure and 0 on success. Some possible
917
+ * errors are:
918
+ * <ul>
919
+ * <li>EINVAL - an invalid parameter was specified.
920
+ * </ul>
921
+ */
922
+ int mdb_env_get_fd(MDB_env *env, mdb_filehandle_t *fd);
923
+
924
+ /** @brief Set the size of the memory map to use for this environment.
925
+ *
926
+ * The size should be a multiple of the OS page size. The default is
927
+ * 10485760 bytes. The size of the memory map is also the maximum size
928
+ * of the database. The value should be chosen as large as possible,
929
+ * to accommodate future growth of the database.
930
+ * This function should be called after #mdb_env_create() and before #mdb_env_open().
931
+ * It may be called at later times if no transactions are active in
932
+ * this process. Note that the library does not check for this condition,
933
+ * the caller must ensure it explicitly.
934
+ *
935
+ * The new size takes effect immediately for the current process but
936
+ * will not be persisted to any others until a write transaction has been
937
+ * committed by the current process. Also, only mapsize increases are
938
+ * persisted into the environment.
939
+ *
940
+ * If the mapsize is increased by another process, and data has grown
941
+ * beyond the range of the current mapsize, #mdb_txn_begin() will
942
+ * return #MDB_MAP_RESIZED. This function may be called with a size
943
+ * of zero to adopt the new size.
944
+ *
945
+ * Any attempt to set a size smaller than the space already consumed
946
+ * by the environment will be silently changed to the current size of the used space.
947
+ * @param[in] env An environment handle returned by #mdb_env_create()
948
+ * @param[in] size The size in bytes
949
+ * @return A non-zero error value on failure and 0 on success. Some possible
950
+ * errors are:
951
+ * <ul>
952
+ * <li>EINVAL - an invalid parameter was specified, or the environment has
953
+ * an active write transaction.
954
+ * </ul>
955
+ */
956
+ int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size);
957
+
958
+
959
+ /** @brief Set the size of DB pages in bytes.
960
+ *
961
+ * The size defaults to the OS page size. Smaller or larger values may be
962
+ * desired depending on the size of keys and values being used. Also, an
963
+ * explicit size may need to be set when using filesystems like ZFS which
964
+ * don't use the OS page size.
965
+ */
966
+ int mdb_env_set_pagesize(MDB_env *env, int size);
967
+
968
+ /** @brief Set the maximum number of threads/reader slots for the environment.
969
+ *
970
+ * This defines the number of slots in the lock table that is used to track readers in the
971
+ * the environment. The default is 126.
972
+ * Starting a read-only transaction normally ties a lock table slot to the
973
+ * current thread until the environment closes or the thread exits. If
974
+ * MDB_NOTLS is in use, #mdb_txn_begin() instead ties the slot to the
975
+ * MDB_txn object until it or the #MDB_env object is destroyed.
976
+ * This function may only be called after #mdb_env_create() and before #mdb_env_open().
977
+ * @param[in] env An environment handle returned by #mdb_env_create()
978
+ * @param[in] readers The maximum number of reader lock table slots
979
+ * @return A non-zero error value on failure and 0 on success. Some possible
980
+ * errors are:
981
+ * <ul>
982
+ * <li>EINVAL - an invalid parameter was specified, or the environment is already open.
983
+ * </ul>
984
+ */
985
+ int mdb_env_set_maxreaders(MDB_env *env, unsigned int readers);
986
+
987
+ /** @brief Get the maximum number of threads/reader slots for the environment.
988
+ *
989
+ * @param[in] env An environment handle returned by #mdb_env_create()
990
+ * @param[out] readers Address of an integer to store the number of readers
991
+ * @return A non-zero error value on failure and 0 on success. Some possible
992
+ * errors are:
993
+ * <ul>
994
+ * <li>EINVAL - an invalid parameter was specified.
995
+ * </ul>
996
+ */
997
+ int mdb_env_get_maxreaders(MDB_env *env, unsigned int *readers);
998
+
999
+ /** @brief Set the maximum number of named databases for the environment.
1000
+ *
1001
+ * This function is only needed if multiple databases will be used in the
1002
+ * environment. Simpler applications that use the environment as a single
1003
+ * unnamed database can ignore this option.
1004
+ * This function may only be called after #mdb_env_create() and before #mdb_env_open().
1005
+ *
1006
+ * Currently a moderate number of slots are cheap but a huge number gets
1007
+ * expensive: 7-120 words per transaction, and every #mdb_dbi_open()
1008
+ * does a linear search of the opened slots.
1009
+ * @param[in] env An environment handle returned by #mdb_env_create()
1010
+ * @param[in] dbs The maximum number of databases
1011
+ * @return A non-zero error value on failure and 0 on success. Some possible
1012
+ * errors are:
1013
+ * <ul>
1014
+ * <li>EINVAL - an invalid parameter was specified, or the environment is already open.
1015
+ * </ul>
1016
+ */
1017
+ int mdb_env_set_maxdbs(MDB_env *env, MDB_dbi dbs);
1018
+
1019
+ /** @brief Get the maximum size of keys and #MDB_DUPSORT data we can write.
1020
+ *
1021
+ * Depends on the compile-time constant #MDB_MAXKEYSIZE. Default 511.
1022
+ * See @ref MDB_val.
1023
+ * @param[in] env An environment handle returned by #mdb_env_create()
1024
+ * @return The maximum size of a key we can write
1025
+ */
1026
+ int mdb_env_get_maxkeysize(MDB_env *env);
1027
+
1028
+ /** @brief Set application information associated with the #MDB_env.
1029
+ *
1030
+ * @param[in] env An environment handle returned by #mdb_env_create()
1031
+ * @param[in] ctx An arbitrary pointer for whatever the application needs.
1032
+ * @return A non-zero error value on failure and 0 on success.
1033
+ */
1034
+ int mdb_env_set_userctx(MDB_env *env, void *ctx);
1035
+
1036
+ /** @brief Get the application information associated with the #MDB_env.
1037
+ *
1038
+ * @param[in] env An environment handle returned by #mdb_env_create()
1039
+ * @return The pointer set by #mdb_env_set_userctx().
1040
+ */
1041
+ void *mdb_env_get_userctx(MDB_env *env);
1042
+
1043
+ /** @brief A callback function for most LMDB assert() failures,
1044
+ * called before printing the message and aborting.
1045
+ *
1046
+ * @param[in] env An environment handle returned by #mdb_env_create().
1047
+ * @param[in] msg The assertion message, not including newline.
1048
+ */
1049
+ typedef void MDB_assert_func(MDB_env *env, const char *msg);
1050
+
1051
+ /** Set or reset the assert() callback of the environment.
1052
+ * Disabled if liblmdb is built with NDEBUG.
1053
+ * @note This hack should become obsolete as lmdb's error handling matures.
1054
+ * @param[in] env An environment handle returned by #mdb_env_create().
1055
+ * @param[in] func An #MDB_assert_func function, or 0.
1056
+ * @return A non-zero error value on failure and 0 on success.
1057
+ */
1058
+ int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func);
1059
+
1060
+ //<lmdb-js>
1061
+ typedef int (MDB_check_fd)(const mdb_filehandle_t fd, MDB_env* env);
1062
+ typedef void (MDB_txn_visible)(const void* ctx);
1063
+ int mdb_env_set_callback(MDB_env *env, MDB_check_fd *func);
1064
+ int mdb_txn_set_callback(MDB_txn *txn, MDB_txn_visible *func, void* ctx);
1065
+ //</lmdb-js>
1066
+
1067
+ #if MDB_RPAGE_CACHE
1068
+ /** @brief Set encryption on an environment.
1069
+ *
1070
+ * This must be called before #mdb_env_open().
1071
+ * It implicitly sets #MDB_REMAP_CHUNKS on the env.
1072
+ * @param[in] env An environment handle returned by #mdb_env_create().
1073
+ * @param[in] func An #MDB_enc_func function.
1074
+ * @param[in] key The encryption key.
1075
+ * @param[in] size The size of authentication data in bytes, if any.
1076
+ * Set this to zero for unauthenticated encryption mechanisms.
1077
+ * @return A non-zero error value on failure and 0 on success.
1078
+ */
1079
+ int mdb_env_set_encrypt(MDB_env *env, MDB_enc_func *func, const MDB_val *key, unsigned int size);
1080
+
1081
+
1082
+ /** @brief Set checksums on an environment.
1083
+ *
1084
+ * This must be called before #mdb_env_open().
1085
+ * @param[in] env An environment handle returned by #mdb_env_create().
1086
+ * @param[in] func An #MDB_sum_func function.
1087
+ * @param[in] size The size of computed checksum values, in bytes.
1088
+ * @return A non-zero error value on failure and 0 on success.
1089
+ */
1090
+ int mdb_env_set_checksum(MDB_env *env, MDB_sum_func *func, unsigned int size);
1091
+ #endif
1092
+
1093
+ /** @brief Create a transaction for use with the environment.
1094
+ *
1095
+ * The transaction handle may be discarded using #mdb_txn_abort() or #mdb_txn_commit().
1096
+ * @note A transaction and its cursors must only be used by a single
1097
+ * thread, and a thread may only have a single transaction at a time.
1098
+ * If #MDB_NOTLS is in use, this does not apply to read-only transactions.
1099
+ * @note Cursors may not span transactions.
1100
+ * @param[in] env An environment handle returned by #mdb_env_create()
1101
+ * @param[in] parent If this parameter is non-NULL, the new transaction
1102
+ * will be a nested transaction, with the transaction indicated by \b parent
1103
+ * as its parent. Transactions may be nested to any level. A parent
1104
+ * transaction and its cursors may not issue any other operations than
1105
+ * mdb_txn_commit and mdb_txn_abort while it has active child transactions.
1106
+ * @param[in] flags Special options for this transaction. This parameter
1107
+ * must be set to 0 or by bitwise OR'ing together one or more of the
1108
+ * values described here.
1109
+ * <ul>
1110
+ * <li>#MDB_RDONLY
1111
+ * This transaction will not perform any write operations.
1112
+ * <li>#MDB_NOSYNC
1113
+ * Don't flush system buffers to disk when committing this transaction.
1114
+ * <li>#MDB_NOMETASYNC
1115
+ * Flush system buffers but omit metadata flush when committing this transaction.
1116
+ * </ul>
1117
+ * @param[out] txn Address where the new #MDB_txn handle will be stored
1118
+ * @return A non-zero error value on failure and 0 on success. Some possible
1119
+ * errors are:
1120
+ * <ul>
1121
+ * <li>#MDB_PANIC - a fatal error occurred earlier and the environment
1122
+ * must be shut down.
1123
+ * <li>#MDB_MAP_RESIZED - another process wrote data beyond this MDB_env's
1124
+ * mapsize and this environment's map must be resized as well.
1125
+ * See #mdb_env_set_mapsize().
1126
+ * <li>#MDB_READERS_FULL - a read-only transaction was requested and
1127
+ * the reader lock table is full. See #mdb_env_set_maxreaders().
1128
+ * <li>ENOMEM - out of memory.
1129
+ * </ul>
1130
+ */
1131
+ int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn);
1132
+
1133
+ /** @brief Returns the transaction's #MDB_env
1134
+ *
1135
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1136
+ */
1137
+ MDB_env *mdb_txn_env(MDB_txn *txn);
1138
+
1139
+ /** @brief Return the transaction's ID.
1140
+ *
1141
+ * This returns the identifier associated with this transaction. For a
1142
+ * read-only transaction, this corresponds to the snapshot being read;
1143
+ * concurrent readers will frequently have the same transaction ID.
1144
+ *
1145
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1146
+ * @return A transaction ID, valid if input is an active transaction.
1147
+ */
1148
+ mdb_size_t mdb_txn_id(MDB_txn *txn);
1149
+
1150
+ /** @brief Commit all the operations of a transaction into the database.
1151
+ *
1152
+ * The transaction handle is freed. It and its cursors must not be used
1153
+ * again after this call, except with #mdb_cursor_renew().
1154
+ * @note Earlier documentation incorrectly said all cursors would be freed.
1155
+ * Only write-transactions free cursors.
1156
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1157
+ * @return A non-zero error value on failure and 0 on success. Some possible
1158
+ * errors are:
1159
+ * <ul>
1160
+ * <li>EINVAL - an invalid parameter was specified.
1161
+ * <li>ENOSPC - no more disk space.
1162
+ * <li>EIO - a low-level I/O error occurred while writing.
1163
+ * <li>ENOMEM - out of memory.
1164
+ * </ul>
1165
+ */
1166
+ int mdb_txn_commit(MDB_txn *txn);
1167
+
1168
+ /** @brief Abandon all the operations of the transaction instead of saving them.
1169
+ *
1170
+ * The transaction handle is freed. It and its cursors must not be used
1171
+ * again after this call, except with #mdb_cursor_renew().
1172
+ * @note Earlier documentation incorrectly said all cursors would be freed.
1173
+ * Only write-transactions free cursors.
1174
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1175
+ */
1176
+ void mdb_txn_abort(MDB_txn *txn);
1177
+
1178
+ /** @brief Reset a read-only transaction.
1179
+ *
1180
+ * Abort the transaction like #mdb_txn_abort(), but keep the transaction
1181
+ * handle. #mdb_txn_renew() may reuse the handle. This saves allocation
1182
+ * overhead if the process will start a new read-only transaction soon,
1183
+ * and also locking overhead if #MDB_NOTLS is in use. The reader table
1184
+ * lock is released, but the table slot stays tied to its thread or
1185
+ * #MDB_txn. Use mdb_txn_abort() to discard a reset handle, and to free
1186
+ * its lock table slot if MDB_NOTLS is in use.
1187
+ * Cursors opened within the transaction must not be used
1188
+ * again after this call, except with #mdb_cursor_renew().
1189
+ * Reader locks generally don't interfere with writers, but they keep old
1190
+ * versions of database pages allocated. Thus they prevent the old pages
1191
+ * from being reused when writers commit new data, and so under heavy load
1192
+ * the database size may grow much more rapidly than otherwise.
1193
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1194
+ */
1195
+ void mdb_txn_reset(MDB_txn *txn);
1196
+
1197
+ /** @brief Renew a read-only transaction.
1198
+ *
1199
+ * This acquires a new reader lock for a transaction handle that had been
1200
+ * released by #mdb_txn_reset(). It must be called before a reset transaction
1201
+ * may be used again.
1202
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1203
+ * @return A non-zero error value on failure and 0 on success. Some possible
1204
+ * errors are:
1205
+ * <ul>
1206
+ * <li>#MDB_PANIC - a fatal error occurred earlier and the environment
1207
+ * must be shut down.
1208
+ * <li>EINVAL - an invalid parameter was specified.
1209
+ * </ul>
1210
+ */
1211
+ int mdb_txn_renew(MDB_txn *txn);
1212
+
1213
+ /** Compat with version <= 0.9.4, avoid clash with libmdb from MDB Tools project */
1214
+ #define mdb_open(txn,name,flags,dbi) mdb_dbi_open(txn,name,flags,dbi)
1215
+ /** Compat with version <= 0.9.4, avoid clash with libmdb from MDB Tools project */
1216
+ #define mdb_close(env,dbi) mdb_dbi_close(env,dbi)
1217
+
1218
+ /** @brief Open a database in the environment.
1219
+ *
1220
+ * A database handle denotes the name and parameters of a database,
1221
+ * independently of whether such a database exists.
1222
+ * The database handle may be discarded by calling #mdb_dbi_close().
1223
+ * The old database handle is returned if the database was already open.
1224
+ * The handle may only be closed once.
1225
+ *
1226
+ * The database handle will be private to the current transaction until
1227
+ * the transaction is successfully committed. If the transaction is
1228
+ * aborted the handle will be closed automatically.
1229
+ * After a successful commit the handle will reside in the shared
1230
+ * environment, and may be used by other transactions.
1231
+ *
1232
+ * This function must not be called from multiple concurrent
1233
+ * transactions in the same process. A transaction that uses
1234
+ * this function must finish (either commit or abort) before
1235
+ * any other transaction in the process may use this function.
1236
+ *
1237
+ * To use named databases (with name != NULL), #mdb_env_set_maxdbs()
1238
+ * must be called before opening the environment. Database names are
1239
+ * keys in the unnamed database, and may be read but not written.
1240
+ * @note Names are C strings and stored with their NUL terminator included.
1241
+ * In LMDB 0.9 the NUL terminator was omitted.
1242
+ *
1243
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1244
+ * @param[in] name The name of the database to open. If only a single
1245
+ * database is needed in the environment, this value may be NULL.
1246
+ * @param[in] flags Special options for this database. This parameter
1247
+ * must be set to 0 or by bitwise OR'ing together one or more of the
1248
+ * values described here.
1249
+ * <ul>
1250
+ * <li>#MDB_REVERSEKEY
1251
+ * Keys are strings to be compared in reverse order, from the end
1252
+ * of the strings to the beginning. By default, Keys are treated as strings and
1253
+ * compared from beginning to end.
1254
+ * <li>#MDB_DUPSORT
1255
+ * Duplicate keys may be used in the database. (Or, from another perspective,
1256
+ * keys may have multiple data items, stored in sorted order.) By default
1257
+ * keys must be unique and may have only a single data item.
1258
+ * <li>#MDB_INTEGERKEY
1259
+ * Keys are binary integers in native byte order, either unsigned int
1260
+ * or #mdb_size_t, and will be sorted as such.
1261
+ * (lmdb expects 32-bit int <= size_t <= 32/64-bit mdb_size_t.)
1262
+ * The keys must all be of the same size.
1263
+ * <li>#MDB_DUPFIXED
1264
+ * This flag may only be used in combination with #MDB_DUPSORT. This option
1265
+ * tells the library that the data items for this database are all the same
1266
+ * size, which allows further optimizations in storage and retrieval. When
1267
+ * all data items are the same size, the #MDB_GET_MULTIPLE, #MDB_NEXT_MULTIPLE
1268
+ * and #MDB_PREV_MULTIPLE cursor operations may be used to retrieve multiple
1269
+ * items at once.
1270
+ * <li>#MDB_INTEGERDUP
1271
+ * This option specifies that duplicate data items are binary integers,
1272
+ * similar to #MDB_INTEGERKEY keys.
1273
+ * <li>#MDB_REVERSEDUP
1274
+ * This option specifies that duplicate data items should be compared as
1275
+ * strings in reverse order.
1276
+ * <li>#MDB_CREATE
1277
+ * Create the named database if it doesn't exist. This option is not
1278
+ * allowed in a read-only transaction or a read-only environment.
1279
+ * </ul>
1280
+ * @param[out] dbi Address where the new #MDB_dbi handle will be stored
1281
+ * @return A non-zero error value on failure and 0 on success. Some possible
1282
+ * errors are:
1283
+ * <ul>
1284
+ * <li>#MDB_NOTFOUND - the specified database doesn't exist in the environment
1285
+ * and #MDB_CREATE was not specified.
1286
+ * <li>#MDB_DBS_FULL - too many databases have been opened. See #mdb_env_set_maxdbs().
1287
+ * </ul>
1288
+ */
1289
+ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi);
1290
+
1291
+ /** @brief Retrieve statistics for a database.
1292
+ *
1293
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1294
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1295
+ * @param[out] stat The address of an #MDB_stat structure
1296
+ * where the statistics will be copied
1297
+ * @return A non-zero error value on failure and 0 on success. Some possible
1298
+ * errors are:
1299
+ * <ul>
1300
+ * <li>EINVAL - an invalid parameter was specified.
1301
+ * </ul>
1302
+ */
1303
+ int mdb_stat(MDB_txn *txn, MDB_dbi dbi, MDB_stat *stat);
1304
+
1305
+ /** @brief Retrieve the DB flags for a database handle.
1306
+ *
1307
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1308
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1309
+ * @param[out] flags Address where the flags will be returned.
1310
+ * @return A non-zero error value on failure and 0 on success.
1311
+ */
1312
+ int mdb_dbi_flags(MDB_txn *txn, MDB_dbi dbi, unsigned int *flags);
1313
+
1314
+ /** @brief Close a database handle. Normally unnecessary. Use with care:
1315
+ *
1316
+ * This call is not mutex protected. Handles should only be closed by
1317
+ * a single thread, and only if no other threads are going to reference
1318
+ * the database handle or one of its cursors any further. Do not close
1319
+ * a handle if an existing transaction has modified its database.
1320
+ * Doing so can cause misbehavior from database corruption to errors
1321
+ * like MDB_BAD_VALSIZE (since the DB name is gone).
1322
+ *
1323
+ * Closing a database handle is not necessary, but lets #mdb_dbi_open()
1324
+ * reuse the handle value. Usually it's better to set a bigger
1325
+ * #mdb_env_set_maxdbs(), unless that value would be large.
1326
+ *
1327
+ * @param[in] env An environment handle returned by #mdb_env_create()
1328
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1329
+ */
1330
+ void mdb_dbi_close(MDB_env *env, MDB_dbi dbi);
1331
+
1332
+ /** @brief Empty or delete+close a database.
1333
+ *
1334
+ * See #mdb_dbi_close() for restrictions about closing the DB handle.
1335
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1336
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1337
+ * @param[in] del 0 to empty the DB, 1 to delete it from the
1338
+ * environment and close the DB handle.
1339
+ * @return A non-zero error value on failure and 0 on success.
1340
+ */
1341
+ int mdb_drop(MDB_txn *txn, MDB_dbi dbi, int del);
1342
+
1343
+ /** @brief Set a custom key comparison function for a database.
1344
+ *
1345
+ * The comparison function is called whenever it is necessary to compare a
1346
+ * key specified by the application with a key currently stored in the database.
1347
+ * If no comparison function is specified, and no special key flags were specified
1348
+ * with #mdb_dbi_open(), the keys are compared lexically, with shorter keys collating
1349
+ * before longer keys.
1350
+ * @warning This function must be called before any data access functions are used,
1351
+ * otherwise data corruption may occur. The same comparison function must be used by every
1352
+ * program accessing the database, every time the database is used.
1353
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1354
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1355
+ * @param[in] cmp A #MDB_cmp_func function
1356
+ * @return A non-zero error value on failure and 0 on success. Some possible
1357
+ * errors are:
1358
+ * <ul>
1359
+ * <li>EINVAL - an invalid parameter was specified.
1360
+ * </ul>
1361
+ */
1362
+ int mdb_set_compare(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
1363
+
1364
+ /** @brief Set a custom data comparison function for a #MDB_DUPSORT database.
1365
+ *
1366
+ * This comparison function is called whenever it is necessary to compare a data
1367
+ * item specified by the application with a data item currently stored in the database.
1368
+ * This function only takes effect if the database was opened with the #MDB_DUPSORT
1369
+ * flag.
1370
+ * If no comparison function is specified, and no special key flags were specified
1371
+ * with #mdb_dbi_open(), the data items are compared lexically, with shorter items collating
1372
+ * before longer items.
1373
+ * @warning This function must be called before any data access functions are used,
1374
+ * otherwise data corruption may occur. The same comparison function must be used by every
1375
+ * program accessing the database, every time the database is used.
1376
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1377
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1378
+ * @param[in] cmp A #MDB_cmp_func function
1379
+ * @return A non-zero error value on failure and 0 on success. Some possible
1380
+ * errors are:
1381
+ * <ul>
1382
+ * <li>EINVAL - an invalid parameter was specified.
1383
+ * </ul>
1384
+ */
1385
+ int mdb_set_dupsort(MDB_txn *txn, MDB_dbi dbi, MDB_cmp_func *cmp);
1386
+
1387
+ /** @brief Set a relocation function for a #MDB_FIXEDMAP database.
1388
+ *
1389
+ * @todo The relocation function is called whenever it is necessary to move the data
1390
+ * of an item to a different position in the database (e.g. through tree
1391
+ * balancing operations, shifts as a result of adds or deletes, etc.). It is
1392
+ * intended to allow address/position-dependent data items to be stored in
1393
+ * a database in an environment opened with the #MDB_FIXEDMAP option.
1394
+ * Currently the relocation feature is unimplemented and setting
1395
+ * this function has no effect.
1396
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1397
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1398
+ * @param[in] rel A #MDB_rel_func function
1399
+ * @return A non-zero error value on failure and 0 on success. Some possible
1400
+ * errors are:
1401
+ * <ul>
1402
+ * <li>EINVAL - an invalid parameter was specified.
1403
+ * </ul>
1404
+ */
1405
+ int mdb_set_relfunc(MDB_txn *txn, MDB_dbi dbi, MDB_rel_func *rel);
1406
+
1407
+ /** @brief Set a context pointer for a #MDB_FIXEDMAP database's relocation function.
1408
+ *
1409
+ * See #mdb_set_relfunc and #MDB_rel_func for more details.
1410
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1411
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1412
+ * @param[in] ctx An arbitrary pointer for whatever the application needs.
1413
+ * It will be passed to the callback function set by #mdb_set_relfunc
1414
+ * as its \b relctx parameter whenever the callback is invoked.
1415
+ * @return A non-zero error value on failure and 0 on success. Some possible
1416
+ * errors are:
1417
+ * <ul>
1418
+ * <li>EINVAL - an invalid parameter was specified.
1419
+ * </ul>
1420
+ */
1421
+ int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
1422
+
1423
+ /** @brief Get items from a database.
1424
+ *
1425
+ * This function retrieves key/data pairs from the database. The address
1426
+ * and length of the data associated with the specified \b key are returned
1427
+ * in the structure to which \b data refers.
1428
+ * If the database supports duplicate keys (#MDB_DUPSORT) then the
1429
+ * first data item for the key will be returned. Retrieval of other
1430
+ * items requires the use of #mdb_cursor_get().
1431
+ *
1432
+ * @note The memory pointed to by the returned values is owned by the
1433
+ * database. The caller need not dispose of the memory, and may not
1434
+ * modify it in any way. For values returned in a read-only transaction
1435
+ * any modification attempts will cause a SIGSEGV.
1436
+ * @note Values returned from the database are valid only until a
1437
+ * subsequent update operation, or the end of the transaction.
1438
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1439
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1440
+ * @param[in] key The key to search for in the database
1441
+ * @param[out] data The data corresponding to the key
1442
+ * @return A non-zero error value on failure and 0 on success. Some possible
1443
+ * errors are:
1444
+ * <ul>
1445
+ * <li>#MDB_NOTFOUND - the key was not in the database.
1446
+ * <li>EINVAL - an invalid parameter was specified.
1447
+ * </ul>
1448
+ */
1449
+ int mdb_get_with_txn(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, mdb_size_t *txn_id);
1450
+
1451
+ int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1452
+
1453
+ /** @brief Store items into a database.
1454
+ *
1455
+ * This function stores key/data pairs in the database. The default behavior
1456
+ * is to enter the new key/data pair, replacing any previously existing key
1457
+ * if duplicates are disallowed, or adding a duplicate data item if
1458
+ * duplicates are allowed (#MDB_DUPSORT).
1459
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1460
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1461
+ * @param[in] key The key to store in the database
1462
+ * @param[in,out] data The data to store
1463
+ * @param[in] flags Special options for this operation. This parameter
1464
+ * must be set to 0 or by bitwise OR'ing together one or more of the
1465
+ * values described here.
1466
+ * <ul>
1467
+ * <li>#MDB_NODUPDATA - enter the new key/data pair only if it does not
1468
+ * already appear in the database. This flag may only be specified
1469
+ * if the database was opened with #MDB_DUPSORT. The function will
1470
+ * return #MDB_KEYEXIST if the key/data pair already appears in the
1471
+ * database.
1472
+ * <li>#MDB_NOOVERWRITE - enter the new key/data pair only if the key
1473
+ * does not already appear in the database. The function will return
1474
+ * #MDB_KEYEXIST if the key already appears in the database, even if
1475
+ * the database supports duplicates (#MDB_DUPSORT). The \b data
1476
+ * parameter will be set to point to the existing item.
1477
+ * <li>#MDB_RESERVE - reserve space for data of the given size, but
1478
+ * don't copy the given data. Instead, return a pointer to the
1479
+ * reserved space, which the caller can fill in later - before
1480
+ * the next update operation or the transaction ends. This saves
1481
+ * an extra memcpy if the data is being generated later.
1482
+ * LMDB does nothing else with this memory, the caller is expected
1483
+ * to modify all of the space requested. This flag must not be
1484
+ * specified if the database was opened with #MDB_DUPSORT.
1485
+ * <li>#MDB_APPEND - append the given key/data pair to the end of the
1486
+ * database. This option allows fast bulk loading when keys are
1487
+ * already known to be in the correct order. Loading unsorted keys
1488
+ * with this flag will cause a #MDB_KEYEXIST error.
1489
+ * <li>#MDB_APPENDDUP - as above, but for sorted dup data.
1490
+ * </ul>
1491
+ * @return A non-zero error value on failure and 0 on success. Some possible
1492
+ * errors are:
1493
+ * <ul>
1494
+ * <li>#MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
1495
+ * <li>#MDB_TXN_FULL - the transaction has too many dirty pages.
1496
+ * <li>EACCES - an attempt was made to write in a read-only transaction.
1497
+ * <li>EINVAL - an invalid parameter was specified.
1498
+ * </ul>
1499
+ */
1500
+ int mdb_put(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data,
1501
+ unsigned int flags);
1502
+
1503
+ /** @brief Delete items from a database.
1504
+ *
1505
+ * This function removes key/data pairs from the database.
1506
+ * If the database does not support sorted duplicate data items
1507
+ * (#MDB_DUPSORT) the data parameter is ignored.
1508
+ * If the database supports sorted duplicates and the data parameter
1509
+ * is NULL, all of the duplicate data items for the key will be
1510
+ * deleted. Otherwise, if the data parameter is non-NULL
1511
+ * only the matching data item will be deleted.
1512
+ * This function will return #MDB_NOTFOUND if the specified key/data
1513
+ * pair is not in the database.
1514
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1515
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1516
+ * @param[in] key The key to delete from the database
1517
+ * @param[in] data The data to delete
1518
+ * @return A non-zero error value on failure and 0 on success. Some possible
1519
+ * errors are:
1520
+ * <ul>
1521
+ * <li>EACCES - an attempt was made to write in a read-only transaction.
1522
+ * <li>EINVAL - an invalid parameter was specified.
1523
+ * </ul>
1524
+ */
1525
+ int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1526
+
1527
+ /** @brief Create a cursor handle.
1528
+ *
1529
+ * A cursor is associated with a specific transaction and database.
1530
+ * A cursor cannot be used when its database handle is closed. Nor
1531
+ * when its transaction has ended, except with #mdb_cursor_renew().
1532
+ * It can be discarded with #mdb_cursor_close().
1533
+ * A cursor in a write-transaction can be closed before its transaction
1534
+ * ends, and will otherwise be closed when its transaction ends.
1535
+ * A cursor in a read-only transaction must be closed explicitly, before
1536
+ * or after its transaction ends. It can be reused with
1537
+ * #mdb_cursor_renew() before finally closing it.
1538
+ * @note Earlier documentation said that cursors in every transaction
1539
+ * were closed when the transaction committed or aborted.
1540
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1541
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1542
+ * @param[out] cursor Address where the new #MDB_cursor handle will be stored
1543
+ * @return A non-zero error value on failure and 0 on success. Some possible
1544
+ * errors are:
1545
+ * <ul>
1546
+ * <li>EINVAL - an invalid parameter was specified.
1547
+ * </ul>
1548
+ */
1549
+ int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor);
1550
+
1551
+ /** @brief Close a cursor handle.
1552
+ *
1553
+ * The cursor handle will be freed and must not be used again after this call.
1554
+ * Its transaction must still be live if it is a write-transaction.
1555
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1556
+ */
1557
+ void mdb_cursor_close(MDB_cursor *cursor);
1558
+
1559
+ /** @brief Renew a cursor handle.
1560
+ *
1561
+ * A cursor is associated with a specific transaction and database.
1562
+ * Cursors that are only used in read-only
1563
+ * transactions may be re-used, to avoid unnecessary malloc/free overhead.
1564
+ * The cursor may be associated with a new read-only transaction, and
1565
+ * referencing the same database handle as it was created with.
1566
+ * This may be done whether the previous transaction is live or dead.
1567
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1568
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1569
+ * @return A non-zero error value on failure and 0 on success. Some possible
1570
+ * errors are:
1571
+ * <ul>
1572
+ * <li>EINVAL - an invalid parameter was specified.
1573
+ * </ul>
1574
+ */
1575
+ int mdb_cursor_renew(MDB_txn *txn, MDB_cursor *cursor);
1576
+
1577
+ /** @brief Return the cursor's transaction handle.
1578
+ *
1579
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1580
+ */
1581
+ MDB_txn *mdb_cursor_txn(MDB_cursor *cursor);
1582
+
1583
+ /** @brief Return the cursor's database handle.
1584
+ *
1585
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1586
+ */
1587
+ MDB_dbi mdb_cursor_dbi(MDB_cursor *cursor);
1588
+
1589
+ /** @brief Check if the cursor is pointing to a named database record.
1590
+ *
1591
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1592
+ * @return 1 if current record is a named database, 0 otherwise.
1593
+ */
1594
+ int mdb_cursor_is_db(MDB_cursor *cursor);
1595
+
1596
+ /** @brief Retrieve by cursor.
1597
+ *
1598
+ * This function retrieves key/data pairs from the database. The address and length
1599
+ * of the key are returned in the object to which \b key refers (except for the
1600
+ * case of the #MDB_SET option, in which the \b key object is unchanged), and
1601
+ * the address and length of the data are returned in the object to which \b data
1602
+ * refers.
1603
+ * See #mdb_get() for restrictions on using the output values.
1604
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1605
+ * @param[in,out] key The key for a retrieved item
1606
+ * @param[in,out] data The data of a retrieved item
1607
+ * @param[in] op A cursor operation #MDB_cursor_op
1608
+ * @return A non-zero error value on failure and 0 on success. Some possible
1609
+ * errors are:
1610
+ * <ul>
1611
+ * <li>#MDB_NOTFOUND - no matching key found.
1612
+ * <li>EINVAL - an invalid parameter was specified.
1613
+ * </ul>
1614
+ */
1615
+ int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1616
+ MDB_cursor_op op);
1617
+
1618
+ /** @brief Store by cursor.
1619
+ *
1620
+ * This function stores key/data pairs into the database.
1621
+ * The cursor is positioned at the new item, or on failure usually near it.
1622
+ * @note Earlier documentation incorrectly said errors would leave the
1623
+ * state of the cursor unchanged.
1624
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1625
+ * @param[in] key The key operated on.
1626
+ * @param[in] data The data operated on.
1627
+ * @param[in] flags Options for this operation. This parameter
1628
+ * must be set to 0 or one of the values described here.
1629
+ * <ul>
1630
+ * <li>#MDB_CURRENT - replace the item at the current cursor position.
1631
+ * The \b key parameter must still be provided, and must match it.
1632
+ * If using sorted duplicates (#MDB_DUPSORT) the data item must still
1633
+ * sort into the same place. This is intended to be used when the
1634
+ * new data is the same size as the old. Otherwise it will simply
1635
+ * perform a delete of the old record followed by an insert.
1636
+ * <li>#MDB_NODUPDATA - enter the new key/data pair only if it does not
1637
+ * already appear in the database. This flag may only be specified
1638
+ * if the database was opened with #MDB_DUPSORT. The function will
1639
+ * return #MDB_KEYEXIST if the key/data pair already appears in the
1640
+ * database.
1641
+ * <li>#MDB_NOOVERWRITE - enter the new key/data pair only if the key
1642
+ * does not already appear in the database. The function will return
1643
+ * #MDB_KEYEXIST if the key already appears in the database, even if
1644
+ * the database supports duplicates (#MDB_DUPSORT).
1645
+ * <li>#MDB_RESERVE - reserve space for data of the given size, but
1646
+ * don't copy the given data. Instead, return a pointer to the
1647
+ * reserved space, which the caller can fill in later - before
1648
+ * the next update operation or the transaction ends. This saves
1649
+ * an extra memcpy if the data is being generated later. This flag
1650
+ * must not be specified if the database was opened with #MDB_DUPSORT.
1651
+ * <li>#MDB_APPEND - append the given key/data pair to the end of the
1652
+ * database. No key comparisons are performed. This option allows
1653
+ * fast bulk loading when keys are already known to be in the
1654
+ * correct order. Loading unsorted keys with this flag will cause
1655
+ * a #MDB_KEYEXIST error.
1656
+ * <li>#MDB_APPENDDUP - as above, but for sorted dup data.
1657
+ * <li>#MDB_MULTIPLE - store multiple contiguous data elements in a
1658
+ * single request. This flag may only be specified if the database
1659
+ * was opened with #MDB_DUPFIXED. The \b data argument must be an
1660
+ * array of two MDB_vals. The mv_size of the first MDB_val must be
1661
+ * the size of a single data element. The mv_data of the first MDB_val
1662
+ * must point to the beginning of the array of contiguous data elements.
1663
+ * The mv_size of the second MDB_val must be the count of the number
1664
+ * of data elements to store. On return this field will be set to
1665
+ * the count of the number of elements actually written. The mv_data
1666
+ * of the second MDB_val is unused.
1667
+ * </ul>
1668
+ * @return A non-zero error value on failure and 0 on success. Some possible
1669
+ * errors are:
1670
+ * <ul>
1671
+ * <li>#MDB_MAP_FULL - the database is full, see #mdb_env_set_mapsize().
1672
+ * <li>#MDB_TXN_FULL - the transaction has too many dirty pages.
1673
+ * <li>EACCES - an attempt was made to write in a read-only transaction.
1674
+ * <li>EINVAL - an invalid parameter was specified.
1675
+ * </ul>
1676
+ */
1677
+ int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
1678
+ unsigned int flags);
1679
+
1680
+ /** @brief Delete current key/data pair
1681
+ *
1682
+ * This function deletes the key/data pair to which the cursor refers.
1683
+ * This does not invalidate the cursor, so operations such as MDB_NEXT
1684
+ * can still be used on it.
1685
+ * Both MDB_NEXT and MDB_GET_CURRENT will return the same record after
1686
+ * this operation.
1687
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1688
+ * @param[in] flags Options for this operation. This parameter
1689
+ * must be set to 0 or one of the values described here.
1690
+ * <ul>
1691
+ * <li>#MDB_NODUPDATA - delete all of the data items for the current key.
1692
+ * This flag may only be specified if the database was opened with #MDB_DUPSORT.
1693
+ * </ul>
1694
+ * @return A non-zero error value on failure and 0 on success. Some possible
1695
+ * errors are:
1696
+ * <ul>
1697
+ * <li>EACCES - an attempt was made to write in a read-only transaction.
1698
+ * <li>EINVAL - an invalid parameter was specified.
1699
+ * </ul>
1700
+ */
1701
+ int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags);
1702
+
1703
+ /** @brief Return count of duplicates for current key.
1704
+ *
1705
+ * This call is only valid on databases that support sorted duplicate
1706
+ * data items #MDB_DUPSORT.
1707
+ * @param[in] cursor A cursor handle returned by #mdb_cursor_open()
1708
+ * @param[out] countp Address where the count will be stored
1709
+ * @return A non-zero error value on failure and 0 on success. Some possible
1710
+ * errors are:
1711
+ * <ul>
1712
+ * <li>EINVAL - cursor is not initialized, or an invalid parameter was specified.
1713
+ * </ul>
1714
+ */
1715
+ int mdb_cursor_count(MDB_cursor *cursor, mdb_size_t *countp);
1716
+
1717
+ /** @brief Compare two data items according to a particular database.
1718
+ *
1719
+ * This returns a comparison as if the two data items were keys in the
1720
+ * specified database.
1721
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1722
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1723
+ * @param[in] a The first item to compare
1724
+ * @param[in] b The second item to compare
1725
+ * @return < 0 if a < b, 0 if a == b, > 0 if a > b
1726
+ */
1727
+ int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1728
+
1729
+ /** @brief Compare two data items according to a particular database.
1730
+ *
1731
+ * This returns a comparison as if the two items were data items of
1732
+ * the specified database. The database must have the #MDB_DUPSORT flag.
1733
+ * @param[in] txn A transaction handle returned by #mdb_txn_begin()
1734
+ * @param[in] dbi A database handle returned by #mdb_dbi_open()
1735
+ * @param[in] a The first item to compare
1736
+ * @param[in] b The second item to compare
1737
+ * @return < 0 if a < b, 0 if a == b, > 0 if a > b
1738
+ */
1739
+ int mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b);
1740
+
1741
+ /** @brief A callback function used to print a message from the library.
1742
+ *
1743
+ * @param[in] msg The string to be printed.
1744
+ * @param[in] ctx An arbitrary context pointer for the callback.
1745
+ * @return < 0 on failure, >= 0 on success.
1746
+ */
1747
+ typedef int (MDB_msg_func)(const char *msg, void *ctx);
1748
+
1749
+ /** @brief Dump the entries in the reader lock table.
1750
+ *
1751
+ * @param[in] env An environment handle returned by #mdb_env_create()
1752
+ * @param[in] func A #MDB_msg_func function
1753
+ * @param[in] ctx Anything the message function needs
1754
+ * @return < 0 on failure, >= 0 on success.
1755
+ */
1756
+ int mdb_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx);
1757
+
1758
+ /** @brief Check for stale entries in the reader lock table.
1759
+ *
1760
+ * @param[in] env An environment handle returned by #mdb_env_create()
1761
+ * @param[out] dead Number of stale slots that were cleared
1762
+ * @return 0 on success, non-zero on failure.
1763
+ */
1764
+ int mdb_reader_check(MDB_env *env, int *dead);
1765
+ /** @} */
1766
+
1767
+ /** @defgroup crypto LMDB Encryption Helper API
1768
+ * @{
1769
+ * @brief Helpers for setting up encryption
1770
+ */
1771
+
1772
+ /** @brief A function for converting a string into an encryption key.
1773
+ *
1774
+ * @param[in] passwd The string to be converted.
1775
+ * @param[in,out] key The resulting key. The caller must
1776
+ * provide the space for the key.
1777
+ * @return 0 on success, non-zero on failure.
1778
+ */
1779
+ typedef int (MDB_str2key_func)(const char *passwd, MDB_val *key);
1780
+
1781
+ /** @brief A structure for dynamically loaded crypto modules.
1782
+ *
1783
+ * This is the information that the command line tools expect
1784
+ * in order to operate on encrypted or checksummed environments.
1785
+ */
1786
+ typedef struct MDB_crypto_funcs {
1787
+ MDB_str2key_func *mcf_str2key;
1788
+ MDB_enc_func *mcf_encfunc;
1789
+ MDB_sum_func *mcf_sumfunc;
1790
+ int mcf_keysize; /**< The size of an encryption key, in bytes */
1791
+ int mcf_esumsize; /**< The size of the MAC, for authenticated encryption */
1792
+ int mcf_sumsize; /**< The size of the checksum, for plain checksums */
1793
+ } MDB_crypto_funcs;
1794
+
1795
+ /** @brief The function that returns the #MDB_crypto_funcs structure.
1796
+ *
1797
+ * The command line tools expect this function to be named "MDB_crypto".
1798
+ * It must be exported by the dynamic module so that the tools can use it.
1799
+ * @return A pointer to a #MDB_crypto_funcs structure.
1800
+ */
1801
+ typedef MDB_crypto_funcs *(MDB_crypto_hooks)(void);
1802
+ /** @} */
1803
+
1804
+ #ifdef __cplusplus
1805
+ }
1806
+ #endif
1807
+ /** @page tools LMDB Command Line Tools
1808
+ The following describes the command line tools that are available for LMDB.
1809
+ \li \ref mdb_copy_1
1810
+ \li \ref mdb_drop_1
1811
+ \li \ref mdb_dump_1
1812
+ \li \ref mdb_load_1
1813
+ \li \ref mdb_stat_1
1814
+ */
1815
+
1816
+ #endif /* _LMDB_H_ */
1817
+