@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.
- package/LICENSE +20 -20
- package/README.md +72 -28
- package/SECURITY.md +12 -12
- package/bin/download-prebuilds.js +15 -0
- package/binding.gyp +115 -111
- package/build/Release/lmdb.node +0 -0
- package/caching.js +212 -156
- package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -20
- package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -1631
- package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -47
- package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -136
- package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -183
- package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -14
- package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -121
- package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -192
- package/dependencies/lmdb/libraries/liblmdb/lmdb.h +28 -3
- package/dependencies/lmdb/libraries/liblmdb/mdb.c +157 -31
- package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -74
- package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -106
- package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -53
- package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -154
- package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -94
- package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -333
- package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -97
- package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -530
- package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -83
- package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -276
- package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
- package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -452
- package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -208
- package/dependencies/lmdb/libraries/liblmdb/module.c +101 -101
- package/dependencies/lmdb/libraries/liblmdb/module.h +16 -16
- package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -178
- package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -124
- package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -133
- package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -168
- package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -135
- package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -141
- package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -190
- package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -189
- package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -177
- package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -73
- package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -62
- package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -27
- package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -20
- package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -1631
- package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -47
- package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -192
- package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -1653
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -11359
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -61
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -84
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -81
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -319
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -84
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -492
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -70
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -264
- package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -421
- package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -200
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -177
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -124
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -133
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -168
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -135
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -141
- package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -73
- package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -62
- package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -27
- package/dependencies/lz4/LICENSE +11 -11
- package/dependencies/lz4/lib/LICENSE +24 -24
- package/dependencies/lz4/lib/Makefile +225 -0
- package/dependencies/lz4/lib/README.md +169 -137
- package/dependencies/lz4/lib/dll/example/Makefile +63 -0
- package/dependencies/lz4/lib/dll/example/README.md +69 -69
- package/dependencies/lz4/lib/dll/liblz4.def +62 -62
- package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -35
- package/dependencies/lz4/lib/liblz4.pc.in +14 -14
- package/dependencies/lz4/lib/lz4.c +2722 -2495
- package/dependencies/lz4/lib/lz4.h +842 -774
- package/dependencies/lz4/lib/lz4file.c +311 -0
- package/dependencies/lz4/lib/lz4file.h +93 -0
- package/dependencies/lz4/lib/lz4frame.c +2078 -1899
- package/dependencies/lz4/lib/lz4frame.h +692 -623
- package/dependencies/lz4/lib/lz4frame_static.h +47 -47
- package/dependencies/lz4/lib/lz4hc.c +1631 -1615
- package/dependencies/lz4/lib/lz4hc.h +413 -413
- package/dependencies/lz4/lib/xxhash.c +1030 -1030
- package/dependencies/lz4/lib/xxhash.h +328 -328
- package/dependencies/v8/v8-fast-api-calls-v16.h +790 -790
- package/dependencies/v8/v8-fast-api-calls.h +784 -888
- package/dist/index.cjs +1050 -584
- package/dist/index.cjs.map +1 -1
- package/index.d.cts +420 -0
- package/index.d.ts +450 -385
- package/index.js +38 -37
- package/keys.js +116 -102
- package/level.js +26 -26
- package/native.js +8 -5
- package/node-index.js +21 -17
- package/open.js +51 -17
- package/package.json +63 -21
- package/read.js +338 -95
- package/src/compression.cpp +12 -9
- package/src/cursor.cpp +82 -31
- package/src/dbi.cpp +78 -40
- package/src/env.cpp +336 -68
- package/src/lmdb-js.cpp +64 -64
- package/src/lmdb-js.h +83 -49
- package/src/misc.cpp +297 -28
- package/src/ordered-binary.cpp +46 -46
- package/src/txn.cpp +210 -257
- package/src/v8-functions.cpp +170 -166
- package/src/windows.c +34 -34
- package/src/writer.cpp +169 -84
- package/util/RangeIterable.js +112 -17
- package/util/set-optional-deps.cjs +14 -10
- package/util/when.js +8 -8
- package/write.js +145 -121
- package/dependencies/lmdb-data-v1/libraries/liblmdb/Makefile +0 -118
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_drop.1 +0 -40
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_drop.c +0 -135
- package/rollup.config.js +0 -12
package/src/lmdb-js.cpp
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
#include "lmdb-js.h"
|
|
2
|
-
|
|
3
|
-
using namespace Napi;
|
|
4
|
-
|
|
5
|
-
int Logging::initLogging() {
|
|
6
|
-
char* logging = getenv("LMDB_JS_LOGGING");
|
|
7
|
-
if (logging)
|
|
8
|
-
fprintf(stderr, "Start logging for lmdb-js\n");
|
|
9
|
-
return !!logging;
|
|
10
|
-
}
|
|
11
|
-
int Logging::debugLogging = Logging::initLogging();
|
|
12
|
-
|
|
13
|
-
Object InitAll(Napi::Env env, Object exports) {
|
|
14
|
-
if (Logging::debugLogging)
|
|
15
|
-
fprintf(stderr, "Start initialization\n");
|
|
16
|
-
// Initializes the module
|
|
17
|
-
// Export Env as constructor for EnvWrap
|
|
18
|
-
EnvWrap::setupExports(env, exports);
|
|
19
|
-
|
|
20
|
-
// Export Cursor as constructor for CursorWrap
|
|
21
|
-
CursorWrap::setupExports(env, exports);
|
|
22
|
-
TxnWrap::setupExports(env, exports);
|
|
23
|
-
DbiWrap::setupExports(env, exports);
|
|
24
|
-
CursorWrap::setupExports(env, exports);
|
|
25
|
-
Compression::setupExports(env, exports);
|
|
26
|
-
|
|
27
|
-
// Export misc things
|
|
28
|
-
setupExportMisc(env, exports);
|
|
29
|
-
if (Logging::debugLogging)
|
|
30
|
-
fprintf(stderr, "Finished initialization\n");
|
|
31
|
-
return exports;
|
|
32
|
-
}
|
|
33
|
-
NAPI_MODULE_INIT() {
|
|
34
|
-
Value exp = Value::From(env, exports);
|
|
35
|
-
return InitAll(env, exp.As<Object>());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
#ifndef _WIN32
|
|
39
|
-
extern "C" void node_module_register(void* m) {
|
|
40
|
-
//fprintf(stderr, "This is just a dummy function to be called if node isn't there so deno can load this module\n");
|
|
41
|
-
}
|
|
42
|
-
#endif
|
|
43
|
-
|
|
44
|
-
// This file contains code from the node-lmdb project
|
|
45
|
-
// Copyright (c) 2013-2017 Timur Kristóf
|
|
46
|
-
// Licensed to you under the terms of the MIT license
|
|
47
|
-
//
|
|
48
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
49
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
50
|
-
// in the Software without restriction, including without limitation the rights
|
|
51
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
52
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
53
|
-
// furnished to do so, subject to the following conditions:
|
|
54
|
-
|
|
55
|
-
// The above copyright notice and this permission notice shall be included in
|
|
56
|
-
// all copies or substantial portions of the Software.
|
|
57
|
-
|
|
58
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
59
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
60
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
61
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
62
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
63
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
64
|
-
// THE SOFTWARE.
|
|
1
|
+
#include "lmdb-js.h"
|
|
2
|
+
|
|
3
|
+
using namespace Napi;
|
|
4
|
+
|
|
5
|
+
int Logging::initLogging() {
|
|
6
|
+
char* logging = getenv("LMDB_JS_LOGGING");
|
|
7
|
+
if (logging)
|
|
8
|
+
fprintf(stderr, "Start logging for lmdb-js\n");
|
|
9
|
+
return !!logging;
|
|
10
|
+
}
|
|
11
|
+
int Logging::debugLogging = Logging::initLogging();
|
|
12
|
+
|
|
13
|
+
Object InitAll(Napi::Env env, Object exports) {
|
|
14
|
+
if (Logging::debugLogging)
|
|
15
|
+
fprintf(stderr, "Start initialization\n");
|
|
16
|
+
// Initializes the module
|
|
17
|
+
// Export Env as constructor for EnvWrap
|
|
18
|
+
EnvWrap::setupExports(env, exports);
|
|
19
|
+
|
|
20
|
+
// Export Cursor as constructor for CursorWrap
|
|
21
|
+
CursorWrap::setupExports(env, exports);
|
|
22
|
+
TxnWrap::setupExports(env, exports);
|
|
23
|
+
DbiWrap::setupExports(env, exports);
|
|
24
|
+
CursorWrap::setupExports(env, exports);
|
|
25
|
+
Compression::setupExports(env, exports);
|
|
26
|
+
|
|
27
|
+
// Export misc things
|
|
28
|
+
setupExportMisc(env, exports);
|
|
29
|
+
if (Logging::debugLogging)
|
|
30
|
+
fprintf(stderr, "Finished initialization\n");
|
|
31
|
+
return exports;
|
|
32
|
+
}
|
|
33
|
+
NAPI_MODULE_INIT() {
|
|
34
|
+
Value exp = Value::From(env, exports);
|
|
35
|
+
return InitAll(env, exp.As<Object>());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#ifndef _WIN32
|
|
39
|
+
extern "C" void node_module_register(void* m) {
|
|
40
|
+
//fprintf(stderr, "This is just a dummy function to be called if node isn't there so deno can load this module\n");
|
|
41
|
+
}
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
// This file contains code from the node-lmdb project
|
|
45
|
+
// Copyright (c) 2013-2017 Timur Kristóf
|
|
46
|
+
// Licensed to you under the terms of the MIT license
|
|
47
|
+
//
|
|
48
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
49
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
50
|
+
// in the Software without restriction, including without limitation the rights
|
|
51
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
52
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
53
|
+
// furnished to do so, subject to the following conditions:
|
|
54
|
+
|
|
55
|
+
// The above copyright notice and this permission notice shall be included in
|
|
56
|
+
// all copies or substantial portions of the Software.
|
|
57
|
+
|
|
58
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
59
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
60
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
61
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
62
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
63
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
64
|
+
// THE SOFTWARE.
|
package/src/lmdb-js.h
CHANGED
|
@@ -1,31 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
// This file is part of lmdb-js
|
|
3
|
-
// Copyright (c) 2013-2017 Timur Kristóf
|
|
4
|
-
// Licensed to you under the terms of the MIT license
|
|
5
|
-
//
|
|
6
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
// in the Software without restriction, including without limitation the rights
|
|
9
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
// furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
// The above copyright notice and this permission notice shall be included in
|
|
14
|
-
// all copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
-
// THE SOFTWARE.
|
|
23
|
-
|
|
24
1
|
#ifndef NODE_LMDB_H
|
|
25
2
|
#define NODE_LMDB_H
|
|
26
3
|
|
|
27
4
|
#include <vector>
|
|
5
|
+
#include <unordered_map>
|
|
28
6
|
#include <algorithm>
|
|
7
|
+
#include <ctime>
|
|
29
8
|
#include <napi.h>
|
|
30
9
|
#include <node_api.h>
|
|
31
10
|
|
|
@@ -37,6 +16,9 @@
|
|
|
37
16
|
|
|
38
17
|
using namespace Napi;
|
|
39
18
|
|
|
19
|
+
// set the threshold of when to use shared buffers (for uncompressed entries larger than this value)
|
|
20
|
+
const size_t SHARED_BUFFER_THRESHOLD = 0x4000;
|
|
21
|
+
|
|
40
22
|
#ifndef __CPTHREAD_H__
|
|
41
23
|
#define __CPTHREAD_H__
|
|
42
24
|
|
|
@@ -53,6 +35,9 @@ typedef void pthread_condattr_t;
|
|
|
53
35
|
typedef HANDLE pthread_t;
|
|
54
36
|
typedef CONDITION_VARIABLE pthread_cond_t;
|
|
55
37
|
|
|
38
|
+
#endif
|
|
39
|
+
#ifndef mdb_size_t
|
|
40
|
+
typedef size_t mdb_size_t;
|
|
56
41
|
#endif
|
|
57
42
|
|
|
58
43
|
#define NAPI_FUNCTION(name) napi_value name(napi_env env, napi_callback_info info)
|
|
@@ -61,6 +46,7 @@ typedef CONDITION_VARIABLE pthread_cond_t;
|
|
|
61
46
|
napi_value args[count];\
|
|
62
47
|
napi_get_cb_info(env, info, &argc, args, NULL, NULL);
|
|
63
48
|
#define GET_UINT32_ARG(target, position) napi_get_value_uint32(env, args[position], (uint32_t*) &target)
|
|
49
|
+
#define GET_INT32_ARG(target, position) napi_get_value_int32(env, args[position], (int32_t*) &target)
|
|
64
50
|
#define GET_INT64_ARG(position)\
|
|
65
51
|
int64_t i64;\
|
|
66
52
|
napi_get_value_int64(env, args[position], &i64);
|
|
@@ -78,20 +64,22 @@ typedef CONDITION_VARIABLE pthread_cond_t;
|
|
|
78
64
|
napi_define_properties(env, exports, 1, &desc); }
|
|
79
65
|
|
|
80
66
|
#ifdef _WIN32
|
|
81
|
-
|
|
67
|
+
const uint64_t TICKS_PER_SECOND = 1000;
|
|
82
68
|
int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
|
|
83
69
|
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
|
84
70
|
int pthread_mutex_lock(pthread_mutex_t *mutex);
|
|
85
71
|
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
|
86
72
|
|
|
87
|
-
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
|
|
88
73
|
int pthread_cond_destroy(pthread_cond_t *cond);
|
|
89
74
|
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
|
|
90
75
|
int pthread_cond_signal(pthread_cond_t *cond);
|
|
91
76
|
int pthread_cond_broadcast(pthread_cond_t *cond);
|
|
92
|
-
|
|
77
|
+
#else
|
|
78
|
+
const uint64_t TICKS_PER_SECOND = 1000000000;
|
|
93
79
|
#endif
|
|
80
|
+
uint64_t get_time64();
|
|
94
81
|
|
|
82
|
+
int cond_init(pthread_cond_t *cond);
|
|
95
83
|
int cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, uint64_t ns);
|
|
96
84
|
|
|
97
85
|
#endif /* __CPTHREAD_H__ */
|
|
@@ -145,16 +133,20 @@ void consoleLogN(int n);
|
|
|
145
133
|
void setFlagFromValue(int *flags, int flag, const char *name, bool defaultValue, Object options);
|
|
146
134
|
void writeValueToEntry(const Value &str, MDB_val *val);
|
|
147
135
|
LmdbKeyType keyTypeFromOptions(const Value &val, LmdbKeyType defaultKeyType = LmdbKeyType::DefaultKey);
|
|
148
|
-
|
|
136
|
+
int getVersionAndUncompress(MDB_val &data, DbiWrap* dw);
|
|
149
137
|
int compareFast(const MDB_val *a, const MDB_val *b);
|
|
150
|
-
|
|
151
|
-
|
|
138
|
+
napi_value setGlobalBuffer(napi_env env, napi_callback_info info);
|
|
139
|
+
napi_value lmdbError(napi_env env, napi_callback_info info);
|
|
152
140
|
napi_value createBufferForAddress(napi_env env, napi_callback_info info);
|
|
153
|
-
napi_value
|
|
141
|
+
napi_value getBufferAddress(napi_env env, napi_callback_info info);
|
|
142
|
+
napi_value getAddress(napi_env env, napi_callback_info info);
|
|
154
143
|
napi_value detachBuffer(napi_env env, napi_callback_info info);
|
|
144
|
+
napi_value enableThreadSafeCalls(napi_env env, napi_callback_info info);
|
|
145
|
+
napi_value startRead(napi_env env, napi_callback_info info);
|
|
146
|
+
napi_value setReadCallback(napi_env env, napi_callback_info info);
|
|
155
147
|
Value getAddress(const CallbackInfo& info);
|
|
156
148
|
Value lmdbNativeFunctions(const CallbackInfo& info);
|
|
157
|
-
|
|
149
|
+
napi_value enableDirectV8(napi_env env, napi_callback_info info);
|
|
158
150
|
|
|
159
151
|
#ifndef thread_local
|
|
160
152
|
#ifdef __GNUC__
|
|
@@ -194,6 +186,7 @@ class SharedEnv {
|
|
|
194
186
|
uint64_t dev;
|
|
195
187
|
uint64_t inode;
|
|
196
188
|
int count;
|
|
189
|
+
bool hasWrites;
|
|
197
190
|
};
|
|
198
191
|
|
|
199
192
|
const int INTERRUPT_BATCH = 9998;
|
|
@@ -203,6 +196,7 @@ const int RESUME_BATCH = 9996;
|
|
|
203
196
|
const int USER_HAS_LOCK = 9995;
|
|
204
197
|
const int SEPARATE_FLUSHED = 1;
|
|
205
198
|
const int DELETE_ON_CLOSE = 2;
|
|
199
|
+
const int OPEN_FAILED = 0x10000;
|
|
206
200
|
|
|
207
201
|
class WriteWorker {
|
|
208
202
|
public:
|
|
@@ -212,28 +206,21 @@ class WriteWorker {
|
|
|
212
206
|
MDB_txn* AcquireTxn(int* flags);
|
|
213
207
|
void UnlockTxn();
|
|
214
208
|
int WaitForCallbacks(MDB_txn** txn, bool allowCommit, uint32_t* target);
|
|
215
|
-
virtual void ReportError(const char* error);
|
|
216
209
|
virtual void SendUpdate();
|
|
217
210
|
int interruptionStatus;
|
|
218
211
|
bool finishedProgress;
|
|
212
|
+
int resultCode;
|
|
219
213
|
bool hasError;
|
|
214
|
+
napi_ref callback;
|
|
215
|
+
napi_async_work work;
|
|
216
|
+
napi_threadsafe_function progress;
|
|
220
217
|
EnvWrap* envForTxn;
|
|
221
218
|
virtual ~WriteWorker();
|
|
222
219
|
uint32_t* instructions;
|
|
223
220
|
int progressStatus;
|
|
224
221
|
MDB_env* env;
|
|
225
222
|
static int DoWrites(MDB_txn* txn, EnvWrap* envForTxn, uint32_t* instruction, WriteWorker* worker);
|
|
226
|
-
|
|
227
|
-
class AsyncWriteWorker : public WriteWorker, public AsyncProgressWorker<char> {
|
|
228
|
-
public:
|
|
229
|
-
AsyncWriteWorker(MDB_env* env, EnvWrap* envForTxn, uint32_t* instructions, const Function& callback);
|
|
230
|
-
void Execute(const AsyncProgressWorker::ExecutionProgress& execution);
|
|
231
|
-
void OnProgress(const char* data, size_t count);
|
|
232
|
-
void OnOK();
|
|
233
|
-
void ReportError(const char* error);
|
|
234
|
-
void SendUpdate();
|
|
235
|
-
private:
|
|
236
|
-
ExecutionProgress* executionProgress;
|
|
223
|
+
static bool threadSafeCallsEnabled;
|
|
237
224
|
};
|
|
238
225
|
class TxnTracked {
|
|
239
226
|
public:
|
|
@@ -244,6 +231,8 @@ class TxnTracked {
|
|
|
244
231
|
TxnTracked *parent;
|
|
245
232
|
};
|
|
246
233
|
|
|
234
|
+
|
|
235
|
+
typedef void* (get_shared_buffers_t)();
|
|
247
236
|
/*
|
|
248
237
|
`Env`
|
|
249
238
|
Represents a database environment.
|
|
@@ -252,8 +241,23 @@ class TxnTracked {
|
|
|
252
241
|
typedef struct env_tracking_t {
|
|
253
242
|
pthread_mutex_t* envsLock;
|
|
254
243
|
std::vector<SharedEnv> envs;
|
|
244
|
+
get_shared_buffers_t* getSharedBuffers;
|
|
255
245
|
} env_tracking_t;
|
|
256
246
|
|
|
247
|
+
typedef struct buffer_info_t { // definition of a buffer that is available/used in JS
|
|
248
|
+
int32_t id;
|
|
249
|
+
bool isSharedMap;
|
|
250
|
+
char* end;
|
|
251
|
+
MDB_env* env;
|
|
252
|
+
napi_ref ref;
|
|
253
|
+
} buffer_info_t;
|
|
254
|
+
|
|
255
|
+
typedef struct js_buffers_t { // there is one instance of this for each JS (worker) thread, holding all the active buffers
|
|
256
|
+
std::unordered_map<char*, buffer_info_t> buffers;
|
|
257
|
+
int nextId;
|
|
258
|
+
pthread_mutex_t modification_lock;
|
|
259
|
+
} js_buffers_t;
|
|
260
|
+
|
|
257
261
|
class EnvWrap : public ObjectWrap<EnvWrap> {
|
|
258
262
|
private:
|
|
259
263
|
// List of open read transactions
|
|
@@ -266,7 +270,8 @@ private:
|
|
|
266
270
|
|
|
267
271
|
// Cleans up stray transactions
|
|
268
272
|
void cleanupStrayTxns();
|
|
269
|
-
|
|
273
|
+
void consolidateTxns();
|
|
274
|
+
static void cleanupEnvWraps(void* data);
|
|
270
275
|
|
|
271
276
|
friend class TxnWrap;
|
|
272
277
|
friend class DbiWrap;
|
|
@@ -277,6 +282,7 @@ public:
|
|
|
277
282
|
// The wrapped object
|
|
278
283
|
MDB_env *env;
|
|
279
284
|
// Current write transaction
|
|
285
|
+
static thread_local js_buffers_t* sharedBuffers;
|
|
280
286
|
static env_tracking_t* envTracking;
|
|
281
287
|
TxnWrap *currentWriteTxn;
|
|
282
288
|
TxnTracked *writeTxn;
|
|
@@ -287,14 +293,18 @@ public:
|
|
|
287
293
|
MDB_txn* currentReadTxn;
|
|
288
294
|
WriteWorker* writeWorker;
|
|
289
295
|
bool readTxnRenewed;
|
|
296
|
+
bool hasWrites;
|
|
297
|
+
bool trackMetrics;
|
|
298
|
+
uint64_t timeTxnWaiting;
|
|
290
299
|
unsigned int jsFlags;
|
|
291
300
|
char* keyBuffer;
|
|
292
301
|
int pageSize;
|
|
293
|
-
|
|
302
|
+
time_t lastReaderCheck;
|
|
303
|
+
MDB_txn* getReadTxn(int64_t tw_address = 0);
|
|
294
304
|
|
|
295
305
|
// Sets up exports for the Env constructor
|
|
296
306
|
static void setupExports(Napi::Env env, Object exports);
|
|
297
|
-
void closeEnv();
|
|
307
|
+
void closeEnv(bool hasLock = false);
|
|
298
308
|
int openEnv(int flags, int jsFlags, const char* path, char* keyBuffer, Compression* compression, int maxDbs,
|
|
299
309
|
int maxReaders, mdb_size_t mapSize, int pageSize, char* encryptionKey);
|
|
300
310
|
|
|
@@ -391,10 +401,11 @@ public:
|
|
|
391
401
|
* Callback to be executed after the sync is complete.
|
|
392
402
|
*/
|
|
393
403
|
Napi::Value startWriting(const CallbackInfo& info);
|
|
404
|
+
Napi::Value resumeWriting(const CallbackInfo& info);
|
|
394
405
|
static napi_value compress(napi_env env, napi_callback_info info);
|
|
395
406
|
static napi_value write(napi_env env, napi_callback_info info);
|
|
396
407
|
static napi_value onExit(napi_env env, napi_callback_info info);
|
|
397
|
-
|
|
408
|
+
static int32_t toSharedBuffer(MDB_env* env, uint32_t* keyBuffer, MDB_val data);
|
|
398
409
|
};
|
|
399
410
|
|
|
400
411
|
const int TXN_ABORTABLE = 1;
|
|
@@ -434,6 +445,7 @@ public:
|
|
|
434
445
|
// Remove the current TxnWrap from its EnvWrap
|
|
435
446
|
void removeFromEnvWrap();
|
|
436
447
|
int begin(EnvWrap *ew, unsigned int flags);
|
|
448
|
+
MDB_env* getEnv();
|
|
437
449
|
|
|
438
450
|
/*
|
|
439
451
|
Commits the transaction.
|
|
@@ -460,7 +472,7 @@ public:
|
|
|
460
472
|
static void setupExports(Napi::Env env, Object exports);
|
|
461
473
|
};
|
|
462
474
|
|
|
463
|
-
const int HAS_VERSIONS =
|
|
475
|
+
const int HAS_VERSIONS = 0x100;
|
|
464
476
|
/*
|
|
465
477
|
`Dbi`
|
|
466
478
|
Represents a database instance in an environment.
|
|
@@ -517,7 +529,7 @@ public:
|
|
|
517
529
|
Napi::Value stat(const CallbackInfo& info);
|
|
518
530
|
int prefetch(uint32_t* keys);
|
|
519
531
|
int open(int flags, char* name, bool hasVersions, LmdbKeyType keyType, Compression* compression);
|
|
520
|
-
int32_t doGetByBinary(uint32_t keySize);
|
|
532
|
+
int32_t doGetByBinary(uint32_t keySize, uint32_t ifNotTxnId, int64_t txnAddress);
|
|
521
533
|
static void setupExports(Napi::Env env, Object exports);
|
|
522
534
|
};
|
|
523
535
|
|
|
@@ -597,3 +609,25 @@ public:
|
|
|
597
609
|
};
|
|
598
610
|
|
|
599
611
|
#endif // NODE_LMDB_H
|
|
612
|
+
|
|
613
|
+
// Portions of this file are from node-lmdb
|
|
614
|
+
// Copyright (c) 2013-2017 Timur Kristóf
|
|
615
|
+
// Licensed to you under the terms of the MIT license
|
|
616
|
+
//
|
|
617
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
618
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
619
|
+
// in the Software without restriction, including without limitation the rights
|
|
620
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
621
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
622
|
+
// furnished to do so, subject to the following conditions:
|
|
623
|
+
|
|
624
|
+
// The above copyright notice and this permission notice shall be included in
|
|
625
|
+
// all copies or substantial portions of the Software.
|
|
626
|
+
|
|
627
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
628
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
629
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
630
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
631
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
632
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
633
|
+
// THE SOFTWARE.
|