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