@ohos-ports/lmdb 2.5.3 → 2.8.5-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 (124) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +72 -28
  3. package/SECURITY.md +12 -12
  4. package/bin/download-prebuilds.js +15 -0
  5. package/binding.gyp +115 -111
  6. package/build/Release/lmdb.node +0 -0
  7. package/caching.js +212 -156
  8. package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -20
  9. package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -1631
  10. package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -47
  11. package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -136
  12. package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -183
  13. package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -14
  14. package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -121
  15. package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -192
  16. package/dependencies/lmdb/libraries/liblmdb/lmdb.h +28 -3
  17. package/dependencies/lmdb/libraries/liblmdb/mdb.c +157 -31
  18. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -74
  19. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -106
  20. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -53
  21. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -154
  22. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -94
  23. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -333
  24. package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -97
  25. package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -530
  26. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -83
  27. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -276
  28. package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
  29. package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -452
  30. package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -208
  31. package/dependencies/lmdb/libraries/liblmdb/module.c +101 -101
  32. package/dependencies/lmdb/libraries/liblmdb/module.h +16 -16
  33. package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -178
  34. package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -124
  35. package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -133
  36. package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -168
  37. package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -135
  38. package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -141
  39. package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -190
  40. package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -189
  41. package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -177
  42. package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -73
  43. package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -62
  44. package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -27
  45. package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
  46. package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -20
  47. package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -1631
  48. package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -47
  49. package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -192
  50. package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -1653
  51. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -11359
  52. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -61
  53. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -84
  54. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -81
  55. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -319
  56. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -84
  57. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -492
  58. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -70
  59. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -264
  60. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -421
  61. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -200
  62. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -177
  63. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -124
  64. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -133
  65. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -168
  66. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -135
  67. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -141
  68. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -73
  69. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -62
  70. package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -27
  71. package/dependencies/lz4/LICENSE +11 -11
  72. package/dependencies/lz4/lib/LICENSE +24 -24
  73. package/dependencies/lz4/lib/Makefile +225 -0
  74. package/dependencies/lz4/lib/README.md +169 -137
  75. package/dependencies/lz4/lib/dll/example/Makefile +63 -0
  76. package/dependencies/lz4/lib/dll/example/README.md +69 -69
  77. package/dependencies/lz4/lib/dll/liblz4.def +62 -62
  78. package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -35
  79. package/dependencies/lz4/lib/liblz4.pc.in +14 -14
  80. package/dependencies/lz4/lib/lz4.c +2722 -2495
  81. package/dependencies/lz4/lib/lz4.h +842 -774
  82. package/dependencies/lz4/lib/lz4file.c +311 -0
  83. package/dependencies/lz4/lib/lz4file.h +93 -0
  84. package/dependencies/lz4/lib/lz4frame.c +2078 -1899
  85. package/dependencies/lz4/lib/lz4frame.h +692 -623
  86. package/dependencies/lz4/lib/lz4frame_static.h +47 -47
  87. package/dependencies/lz4/lib/lz4hc.c +1631 -1615
  88. package/dependencies/lz4/lib/lz4hc.h +413 -413
  89. package/dependencies/lz4/lib/xxhash.c +1030 -1030
  90. package/dependencies/lz4/lib/xxhash.h +328 -328
  91. package/dependencies/v8/v8-fast-api-calls-v16.h +790 -790
  92. package/dependencies/v8/v8-fast-api-calls.h +784 -888
  93. package/dist/index.cjs +1050 -584
  94. package/dist/index.cjs.map +1 -1
  95. package/index.d.cts +420 -0
  96. package/index.d.ts +450 -385
  97. package/index.js +38 -37
  98. package/keys.js +116 -102
  99. package/level.js +26 -26
  100. package/native.js +8 -5
  101. package/node-index.js +21 -17
  102. package/open.js +51 -17
  103. package/package.json +63 -21
  104. package/read.js +338 -95
  105. package/src/compression.cpp +12 -9
  106. package/src/cursor.cpp +82 -31
  107. package/src/dbi.cpp +78 -40
  108. package/src/env.cpp +336 -68
  109. package/src/lmdb-js.cpp +64 -64
  110. package/src/lmdb-js.h +83 -49
  111. package/src/misc.cpp +297 -28
  112. package/src/ordered-binary.cpp +46 -46
  113. package/src/txn.cpp +210 -257
  114. package/src/v8-functions.cpp +170 -166
  115. package/src/windows.c +34 -34
  116. package/src/writer.cpp +169 -84
  117. package/util/RangeIterable.js +112 -17
  118. package/util/set-optional-deps.cjs +14 -10
  119. package/util/when.js +8 -8
  120. package/write.js +145 -121
  121. package/dependencies/lmdb-data-v1/libraries/liblmdb/Makefile +0 -118
  122. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_drop.1 +0 -40
  123. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_drop.c +0 -135
  124. package/rollup.config.js +0 -12
@@ -1,192 +1,192 @@
1
- /*
2
- * Copyright 2015-2021 Howard Chu, Symas Corp.
3
- * All rights reserved.
4
- *
5
- * Redistribution and use in source and binary forms, with or without
6
- * modification, are permitted only as authorized by the OpenLDAP
7
- * Public License.
8
- *
9
- * A copy of this license is available in the file LICENSE in the
10
- * top-level directory of the distribution or, alternatively, at
11
- * <http://www.OpenLDAP.org/license.html>.
12
- */
13
- /** @page starting Getting Started
14
-
15
- LMDB is compact, fast, powerful, and robust and implements a simplified
16
- variant of the BerkeleyDB (BDB) API. (BDB is also very powerful, and verbosely
17
- documented in its own right.) After reading this page, the main
18
- \ref mdb documentation should make sense. Thanks to Bert Hubert
19
- for creating the
20
- <a href="https://github.com/ahupowerdns/ahutils/blob/master/lmdb-semantics.md">
21
- initial version</a> of this writeup.
22
-
23
- Everything starts with an environment, created by #mdb_env_create().
24
- Once created, this environment must also be opened with #mdb_env_open().
25
-
26
- #mdb_env_open() gets passed a name which is interpreted as a directory
27
- path. Note that this directory must exist already, it is not created
28
- for you. Within that directory, a lock file and a storage file will be
29
- generated. If you don't want to use a directory, you can pass the
30
- #MDB_NOSUBDIR option, in which case the path you provided is used
31
- directly as the data file, and another file with a "-lock" suffix
32
- added will be used for the lock file.
33
-
34
- Once the environment is open, a transaction can be created within it
35
- using #mdb_txn_begin(). Transactions may be read-write or read-only,
36
- and read-write transactions may be nested. A transaction must only
37
- be used by one thread at a time. Transactions are always required,
38
- even for read-only access. The transaction provides a consistent
39
- view of the data.
40
-
41
- Once a transaction has been created, a database can be opened within it
42
- using #mdb_dbi_open(). If only one database will ever be used in the
43
- environment, a NULL can be passed as the database name. For named
44
- databases, the #MDB_CREATE flag must be used to create the database
45
- if it doesn't already exist. Also, #mdb_env_set_maxdbs() must be
46
- called after #mdb_env_create() and before #mdb_env_open() to set the
47
- maximum number of named databases you want to support.
48
-
49
- Note: a single transaction can open multiple databases. Generally
50
- databases should only be opened once, by the first transaction in
51
- the process. After the first transaction completes, the database
52
- handles can freely be used by all subsequent transactions.
53
-
54
- Within a transaction, #mdb_get() and #mdb_put() can store single
55
- key/value pairs if that is all you need to do (but see \ref Cursors
56
- below if you want to do more).
57
-
58
- A key/value pair is expressed as two #MDB_val structures. This struct
59
- has two fields, \c mv_size and \c mv_data. The data is a \c void pointer to
60
- an array of \c mv_size bytes.
61
-
62
- Because LMDB is very efficient (and usually zero-copy), the data returned
63
- in an #MDB_val structure may be memory-mapped straight from disk. In
64
- other words <b>look but do not touch</b> (or free() for that matter).
65
- Once a transaction is closed, the values can no longer be used, so
66
- make a copy if you need to keep them after that.
67
-
68
- @section Cursors Cursors
69
-
70
- To do more powerful things, we must use a cursor.
71
-
72
- Within the transaction, a cursor can be created with #mdb_cursor_open().
73
- With this cursor we can store/retrieve/delete (multiple) values using
74
- #mdb_cursor_get(), #mdb_cursor_put(), and #mdb_cursor_del().
75
-
76
- #mdb_cursor_get() positions itself depending on the cursor operation
77
- requested, and for some operations, on the supplied key. For example,
78
- to list all key/value pairs in a database, use operation #MDB_FIRST for
79
- the first call to #mdb_cursor_get(), and #MDB_NEXT on subsequent calls,
80
- until the end is hit.
81
-
82
- To retrieve all keys starting from a specified key value, use #MDB_SET.
83
- For more cursor operations, see the \ref mdb docs.
84
-
85
- When using #mdb_cursor_put(), either the function will position the
86
- cursor for you based on the \b key, or you can use operation
87
- #MDB_CURRENT to use the current position of the cursor. Note that
88
- \b key must then match the current position's key.
89
-
90
- @subsection summary Summarizing the Opening
91
-
92
- So we have a cursor in a transaction which opened a database in an
93
- environment which is opened from a filesystem after it was
94
- separately created.
95
-
96
- Or, we create an environment, open it from a filesystem, create a
97
- transaction within it, open a database within that transaction,
98
- and create a cursor within all of the above.
99
-
100
- Got it?
101
-
102
- @section thrproc Threads and Processes
103
-
104
- LMDB uses POSIX locks on files, and these locks have issues if one
105
- process opens a file multiple times. Because of this, do not
106
- #mdb_env_open() a file multiple times from a single process. Instead,
107
- share the LMDB environment that has opened the file across all threads.
108
- Otherwise, if a single process opens the same environment multiple times,
109
- closing it once will remove all the locks held on it, and the other
110
- instances will be vulnerable to corruption from other processes.
111
-
112
- Also note that a transaction is tied to one thread by default using
113
- Thread Local Storage. If you want to pass read-only transactions across
114
- threads, you can use the #MDB_NOTLS option on the environment.
115
-
116
- @section txns Transactions, Rollbacks, etc.
117
-
118
- To actually get anything done, a transaction must be committed using
119
- #mdb_txn_commit(). Alternatively, all of a transaction's operations
120
- can be discarded using #mdb_txn_abort(). In a read-only transaction,
121
- any cursors will \b not automatically be freed. In a read-write
122
- transaction, all cursors will be freed and must not be used again.
123
-
124
- For read-only transactions, obviously there is nothing to commit to
125
- storage. The transaction still must eventually be aborted to close
126
- any database handle(s) opened in it, or committed to keep the
127
- database handles around for reuse in new transactions.
128
-
129
- In addition, as long as a transaction is open, a consistent view of
130
- the database is kept alive, which requires storage. A read-only
131
- transaction that no longer requires this consistent view should
132
- be terminated (committed or aborted) when the view is no longer
133
- needed (but see below for an optimization).
134
-
135
- There can be multiple simultaneously active read-only transactions
136
- but only one that can write. Once a single read-write transaction
137
- is opened, all further attempts to begin one will block until the
138
- first one is committed or aborted. This has no effect on read-only
139
- transactions, however, and they may continue to be opened at any time.
140
-
141
- @section dupkeys Duplicate Keys
142
-
143
- #mdb_get() and #mdb_put() respectively have no and only some support
144
- for multiple key/value pairs with identical keys. If there are multiple
145
- values for a key, #mdb_get() will only return the first value.
146
-
147
- When multiple values for one key are required, pass the #MDB_DUPSORT
148
- flag to #mdb_dbi_open(). In an #MDB_DUPSORT database, by default
149
- #mdb_put() will not replace the value for a key if the key existed
150
- already. Instead it will add the new value to the key. In addition,
151
- #mdb_del() will pay attention to the value field too, allowing for
152
- specific values of a key to be deleted.
153
-
154
- Finally, additional cursor operations become available for
155
- traversing through and retrieving duplicate values.
156
-
157
- @section optim Some Optimization
158
-
159
- If you frequently begin and abort read-only transactions, as an
160
- optimization, it is possible to only reset and renew a transaction.
161
-
162
- #mdb_txn_reset() releases any old copies of data kept around for
163
- a read-only transaction. To reuse this reset transaction, call
164
- #mdb_txn_renew() on it. Any cursors in this transaction must also
165
- be renewed using #mdb_cursor_renew().
166
-
167
- Note that #mdb_txn_reset() is similar to #mdb_txn_abort() and will
168
- close any databases you opened within the transaction.
169
-
170
- To permanently free a transaction, reset or not, use #mdb_txn_abort().
171
-
172
- @section cleanup Cleaning Up
173
-
174
- For read-only transactions, any cursors created within it must
175
- be closed using #mdb_cursor_close().
176
-
177
- It is very rarely necessary to close a database handle, and in
178
- general they should just be left open.
179
-
180
- @section onward The Full API
181
-
182
- The full \ref mdb documentation lists further details, like how to:
183
-
184
- \li size a database (the default limits are intentionally small)
185
- \li drop and clean a database
186
- \li detect and report errors
187
- \li optimize (bulk) loading speed
188
- \li (temporarily) reduce robustness to gain even more speed
189
- \li gather statistics about the database
190
- \li define custom sort orders
191
-
192
- */
1
+ /*
2
+ * Copyright 2015-2021 Howard Chu, Symas Corp.
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted only as authorized by the OpenLDAP
7
+ * Public License.
8
+ *
9
+ * A copy of this license is available in the file LICENSE in the
10
+ * top-level directory of the distribution or, alternatively, at
11
+ * <http://www.OpenLDAP.org/license.html>.
12
+ */
13
+ /** @page starting Getting Started
14
+
15
+ LMDB is compact, fast, powerful, and robust and implements a simplified
16
+ variant of the BerkeleyDB (BDB) API. (BDB is also very powerful, and verbosely
17
+ documented in its own right.) After reading this page, the main
18
+ \ref mdb documentation should make sense. Thanks to Bert Hubert
19
+ for creating the
20
+ <a href="https://github.com/ahupowerdns/ahutils/blob/master/lmdb-semantics.md">
21
+ initial version</a> of this writeup.
22
+
23
+ Everything starts with an environment, created by #mdb_env_create().
24
+ Once created, this environment must also be opened with #mdb_env_open().
25
+
26
+ #mdb_env_open() gets passed a name which is interpreted as a directory
27
+ path. Note that this directory must exist already, it is not created
28
+ for you. Within that directory, a lock file and a storage file will be
29
+ generated. If you don't want to use a directory, you can pass the
30
+ #MDB_NOSUBDIR option, in which case the path you provided is used
31
+ directly as the data file, and another file with a "-lock" suffix
32
+ added will be used for the lock file.
33
+
34
+ Once the environment is open, a transaction can be created within it
35
+ using #mdb_txn_begin(). Transactions may be read-write or read-only,
36
+ and read-write transactions may be nested. A transaction must only
37
+ be used by one thread at a time. Transactions are always required,
38
+ even for read-only access. The transaction provides a consistent
39
+ view of the data.
40
+
41
+ Once a transaction has been created, a database can be opened within it
42
+ using #mdb_dbi_open(). If only one database will ever be used in the
43
+ environment, a NULL can be passed as the database name. For named
44
+ databases, the #MDB_CREATE flag must be used to create the database
45
+ if it doesn't already exist. Also, #mdb_env_set_maxdbs() must be
46
+ called after #mdb_env_create() and before #mdb_env_open() to set the
47
+ maximum number of named databases you want to support.
48
+
49
+ Note: a single transaction can open multiple databases. Generally
50
+ databases should only be opened once, by the first transaction in
51
+ the process. After the first transaction completes, the database
52
+ handles can freely be used by all subsequent transactions.
53
+
54
+ Within a transaction, #mdb_get() and #mdb_put() can store single
55
+ key/value pairs if that is all you need to do (but see \ref Cursors
56
+ below if you want to do more).
57
+
58
+ A key/value pair is expressed as two #MDB_val structures. This struct
59
+ has two fields, \c mv_size and \c mv_data. The data is a \c void pointer to
60
+ an array of \c mv_size bytes.
61
+
62
+ Because LMDB is very efficient (and usually zero-copy), the data returned
63
+ in an #MDB_val structure may be memory-mapped straight from disk. In
64
+ other words <b>look but do not touch</b> (or free() for that matter).
65
+ Once a transaction is closed, the values can no longer be used, so
66
+ make a copy if you need to keep them after that.
67
+
68
+ @section Cursors Cursors
69
+
70
+ To do more powerful things, we must use a cursor.
71
+
72
+ Within the transaction, a cursor can be created with #mdb_cursor_open().
73
+ With this cursor we can store/retrieve/delete (multiple) values using
74
+ #mdb_cursor_get(), #mdb_cursor_put(), and #mdb_cursor_del().
75
+
76
+ #mdb_cursor_get() positions itself depending on the cursor operation
77
+ requested, and for some operations, on the supplied key. For example,
78
+ to list all key/value pairs in a database, use operation #MDB_FIRST for
79
+ the first call to #mdb_cursor_get(), and #MDB_NEXT on subsequent calls,
80
+ until the end is hit.
81
+
82
+ To retrieve all keys starting from a specified key value, use #MDB_SET.
83
+ For more cursor operations, see the \ref mdb docs.
84
+
85
+ When using #mdb_cursor_put(), either the function will position the
86
+ cursor for you based on the \b key, or you can use operation
87
+ #MDB_CURRENT to use the current position of the cursor. Note that
88
+ \b key must then match the current position's key.
89
+
90
+ @subsection summary Summarizing the Opening
91
+
92
+ So we have a cursor in a transaction which opened a database in an
93
+ environment which is opened from a filesystem after it was
94
+ separately created.
95
+
96
+ Or, we create an environment, open it from a filesystem, create a
97
+ transaction within it, open a database within that transaction,
98
+ and create a cursor within all of the above.
99
+
100
+ Got it?
101
+
102
+ @section thrproc Threads and Processes
103
+
104
+ LMDB uses POSIX locks on files, and these locks have issues if one
105
+ process opens a file multiple times. Because of this, do not
106
+ #mdb_env_open() a file multiple times from a single process. Instead,
107
+ share the LMDB environment that has opened the file across all threads.
108
+ Otherwise, if a single process opens the same environment multiple times,
109
+ closing it once will remove all the locks held on it, and the other
110
+ instances will be vulnerable to corruption from other processes.
111
+
112
+ Also note that a transaction is tied to one thread by default using
113
+ Thread Local Storage. If you want to pass read-only transactions across
114
+ threads, you can use the #MDB_NOTLS option on the environment.
115
+
116
+ @section txns Transactions, Rollbacks, etc.
117
+
118
+ To actually get anything done, a transaction must be committed using
119
+ #mdb_txn_commit(). Alternatively, all of a transaction's operations
120
+ can be discarded using #mdb_txn_abort(). In a read-only transaction,
121
+ any cursors will \b not automatically be freed. In a read-write
122
+ transaction, all cursors will be freed and must not be used again.
123
+
124
+ For read-only transactions, obviously there is nothing to commit to
125
+ storage. The transaction still must eventually be aborted to close
126
+ any database handle(s) opened in it, or committed to keep the
127
+ database handles around for reuse in new transactions.
128
+
129
+ In addition, as long as a transaction is open, a consistent view of
130
+ the database is kept alive, which requires storage. A read-only
131
+ transaction that no longer requires this consistent view should
132
+ be terminated (committed or aborted) when the view is no longer
133
+ needed (but see below for an optimization).
134
+
135
+ There can be multiple simultaneously active read-only transactions
136
+ but only one that can write. Once a single read-write transaction
137
+ is opened, all further attempts to begin one will block until the
138
+ first one is committed or aborted. This has no effect on read-only
139
+ transactions, however, and they may continue to be opened at any time.
140
+
141
+ @section dupkeys Duplicate Keys
142
+
143
+ #mdb_get() and #mdb_put() respectively have no and only some support
144
+ for multiple key/value pairs with identical keys. If there are multiple
145
+ values for a key, #mdb_get() will only return the first value.
146
+
147
+ When multiple values for one key are required, pass the #MDB_DUPSORT
148
+ flag to #mdb_dbi_open(). In an #MDB_DUPSORT database, by default
149
+ #mdb_put() will not replace the value for a key if the key existed
150
+ already. Instead it will add the new value to the key. In addition,
151
+ #mdb_del() will pay attention to the value field too, allowing for
152
+ specific values of a key to be deleted.
153
+
154
+ Finally, additional cursor operations become available for
155
+ traversing through and retrieving duplicate values.
156
+
157
+ @section optim Some Optimization
158
+
159
+ If you frequently begin and abort read-only transactions, as an
160
+ optimization, it is possible to only reset and renew a transaction.
161
+
162
+ #mdb_txn_reset() releases any old copies of data kept around for
163
+ a read-only transaction. To reuse this reset transaction, call
164
+ #mdb_txn_renew() on it. Any cursors in this transaction must also
165
+ be renewed using #mdb_cursor_renew().
166
+
167
+ Note that #mdb_txn_reset() is similar to #mdb_txn_abort() and will
168
+ close any databases you opened within the transaction.
169
+
170
+ To permanently free a transaction, reset or not, use #mdb_txn_abort().
171
+
172
+ @section cleanup Cleaning Up
173
+
174
+ For read-only transactions, any cursors created within it must
175
+ be closed using #mdb_cursor_close().
176
+
177
+ It is very rarely necessary to close a database handle, and in
178
+ general they should just be left open.
179
+
180
+ @section onward The Full API
181
+
182
+ The full \ref mdb documentation lists further details, like how to:
183
+
184
+ \li size a database (the default limits are intentionally small)
185
+ \li drop and clean a database
186
+ \li detect and report errors
187
+ \li optimize (bulk) loading speed
188
+ \li (temporarily) reduce robustness to gain even more speed
189
+ \li gather statistics about the database
190
+ \li define custom sort orders
191
+
192
+ */
@@ -169,6 +169,7 @@
169
169
  #include <sys/types.h>
170
170
  #include <inttypes.h>
171
171
  #include <limits.h>
172
+ #include <time.h>
172
173
 
173
174
  #ifdef __cplusplus
174
175
  extern "C" {
@@ -374,7 +375,9 @@ typedef void (MDB_sum_func)(const MDB_val *src, MDB_val *dst, const MDB_val *key
374
375
  /** don't use a single mmap, remap individual chunks (needs MDB_RPAGE_CACHE) */
375
376
  #define MDB_REMAP_CHUNKS 0x4000000
376
377
  /** Don't consult boot_id and assume that only the "flushed" txn is valid */
377
- #define MDB_SAFE_RESTORE 0x8000000
378
+ #define MDB_SAFE_RESTORE 0x800
379
+ /** Track metrics for this env */
380
+ #define MDB_TRACK_METRICS 0x400
378
381
  /** Use the overlapping sync strategy */
379
382
  #define MDB_OVERLAPPINGSYNC_SYNC = 0x02
380
383
  /** @} */
@@ -532,10 +535,28 @@ typedef enum MDB_cursor_op {
532
535
  #define MDB_CRYPTO_FAIL (-30777)
533
536
  /** Environment encryption mismatch */
534
537
  #define MDB_ENV_ENCRYPTION (-30776)
538
+ /** Unable to acquire a robust mutex */
539
+ #define MDB_LOCK_FAILURE (-30775)
540
+ /** The transaction was empty (not an error, but informative) */
541
+ #define MDB_EMPTY_TXN (-30774)
535
542
  /** The last defined error code */
536
- #define MDB_LAST_ERRCODE MDB_ENV_ENCRYPTION
543
+ #define MDB_LAST_ERRCODE MDB_EMPTY_TXN
537
544
  /** @} */
538
545
 
546
+ typedef struct MDB_metrics {
547
+ mdb_size_t puts;
548
+ mdb_size_t deletes;
549
+ mdb_size_t txns;
550
+ mdb_size_t page_flushes;
551
+ mdb_size_t writes;
552
+ mdb_size_t pages_written;
553
+ uint64_t clock_txn;
554
+ uint64_t time_during_txns;
555
+ uint64_t time_start_txns;
556
+ uint64_t time_page_flushes;
557
+ uint64_t time_sync;
558
+ } MDB_metrics;
559
+
539
560
  /** @brief Statistics for a database in the environment */
540
561
  typedef struct MDB_stat {
541
562
  unsigned int ms_psize; /**< Size of a database page.
@@ -1038,7 +1059,9 @@ int mdb_env_set_assert(MDB_env *env, MDB_assert_func *func);
1038
1059
 
1039
1060
  //<lmdb-js>
1040
1061
  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);
1062
+ typedef void (MDB_txn_visible)(const void* ctx);
1063
+ int mdb_env_set_callback(MDB_env *env, MDB_check_fd *func);
1064
+ int mdb_txn_set_callback(MDB_txn *txn, MDB_txn_visible *func, void* ctx);
1042
1065
  //</lmdb-js>
1043
1066
 
1044
1067
  #if MDB_RPAGE_CACHE
@@ -1423,6 +1446,8 @@ int mdb_set_relctx(MDB_txn *txn, MDB_dbi dbi, void *ctx);
1423
1446
  * <li>EINVAL - an invalid parameter was specified.
1424
1447
  * </ul>
1425
1448
  */
1449
+ int mdb_get_with_txn(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, mdb_size_t *txn_id);
1450
+
1426
1451
  int mdb_get(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data);
1427
1452
 
1428
1453
  /** @brief Store items into a database.