@ohos-ports/lmdb 2.8.6-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +580 -0
- package/SECURITY.md +12 -0
- package/bin/download-prebuilds.js +15 -0
- package/binding.gyp +113 -0
- package/build/Release/lmdb.node +0 -0
- package/caching.js +212 -0
- package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -0
- package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -0
- package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -0
- package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -0
- package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -0
- package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -0
- package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -0
- package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -0
- package/dependencies/lmdb/libraries/liblmdb/lmdb.h +1817 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb.c +12555 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -0
- package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -0
- package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
- package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -0
- package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -0
- package/dependencies/lmdb/libraries/liblmdb/module.c +101 -0
- package/dependencies/lmdb/libraries/liblmdb/module.h +16 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -0
- package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -0
- package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -0
- package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -0
- package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -0
- package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -0
- package/dependencies/lz4/LICENSE +11 -0
- package/dependencies/lz4/lib/LICENSE +24 -0
- package/dependencies/lz4/lib/Makefile +225 -0
- package/dependencies/lz4/lib/README.md +169 -0
- package/dependencies/lz4/lib/dll/example/Makefile +63 -0
- package/dependencies/lz4/lib/dll/example/README.md +69 -0
- package/dependencies/lz4/lib/dll/example/fullbench-dll.sln +25 -0
- package/dependencies/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
- package/dependencies/lz4/lib/dll/liblz4.def +62 -0
- package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -0
- package/dependencies/lz4/lib/liblz4.pc.in +14 -0
- package/dependencies/lz4/lib/lz4.c +2722 -0
- package/dependencies/lz4/lib/lz4.h +842 -0
- package/dependencies/lz4/lib/lz4file.c +311 -0
- package/dependencies/lz4/lib/lz4file.h +93 -0
- package/dependencies/lz4/lib/lz4frame.c +2078 -0
- package/dependencies/lz4/lib/lz4frame.h +692 -0
- package/dependencies/lz4/lib/lz4frame_static.h +47 -0
- package/dependencies/lz4/lib/lz4hc.c +1631 -0
- package/dependencies/lz4/lib/lz4hc.h +413 -0
- package/dependencies/lz4/lib/xxhash.c +1030 -0
- package/dependencies/lz4/lib/xxhash.h +328 -0
- package/dependencies/v8/v8-fast-api-calls-v16.h +791 -0
- package/dependencies/v8/v8-fast-api-calls.h +888 -0
- package/dict/dict.txt +1 -0
- package/dict/dict2.txt +1 -0
- package/dist/index.cjs +2950 -0
- package/dist/index.cjs.map +1 -0
- package/index.d.cts +420 -0
- package/index.d.ts +450 -0
- package/index.js +38 -0
- package/keys.js +116 -0
- package/level.js +27 -0
- package/native.js +85 -0
- package/node-index.js +32 -0
- package/open.js +448 -0
- package/package.json +124 -0
- package/read.js +833 -0
- package/rollup.config.js +12 -0
- package/src/compression.cpp +225 -0
- package/src/cursor.cpp +395 -0
- package/src/dbi.cpp +382 -0
- package/src/env.cpp +1030 -0
- package/src/lmdb-js.cpp +64 -0
- package/src/lmdb-js.h +633 -0
- package/src/misc.cpp +593 -0
- package/src/ordered-binary.cpp +46 -0
- package/src/txn.cpp +210 -0
- package/src/v8-functions.cpp +170 -0
- package/src/windows.c +35 -0
- package/src/writer.cpp +537 -0
- package/util/RangeIterable.js +236 -0
- package/util/set-optional-deps.cjs +14 -0
- package/util/when.js +8 -0
- package/write.js +912 -0
package/src/txn.cpp
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
#include "lmdb-js.h"
|
|
2
|
+
|
|
3
|
+
using namespace Napi;
|
|
4
|
+
|
|
5
|
+
TxnTracked::TxnTracked(MDB_txn *txn, unsigned int flags) {
|
|
6
|
+
this->txn = txn;
|
|
7
|
+
this->flags = flags;
|
|
8
|
+
parent = nullptr;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
TxnTracked::~TxnTracked() {
|
|
12
|
+
this->txn = nullptr;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
TxnWrap::TxnWrap(const Napi::CallbackInfo& info) : ObjectWrap<TxnWrap>(info) {
|
|
16
|
+
EnvWrap *ew;
|
|
17
|
+
napi_unwrap(info.Env(), info[0], (void**)&ew);
|
|
18
|
+
if (ew->env == nullptr) throwError(info.Env(), "Attempt to start a transaction on a database environment that is closed");
|
|
19
|
+
int flags = 0;
|
|
20
|
+
TxnWrap *parentTw;
|
|
21
|
+
if (info[1].IsBoolean() && ew->writeWorker) { // this is from a transaction callback
|
|
22
|
+
txn = ew->writeWorker->AcquireTxn(&flags);
|
|
23
|
+
parentTw = nullptr;
|
|
24
|
+
} else {
|
|
25
|
+
if (info[1].IsObject()) {
|
|
26
|
+
Object options = info[1].As<Object>();
|
|
27
|
+
|
|
28
|
+
// Get flags from options
|
|
29
|
+
|
|
30
|
+
setFlagFromValue(&flags, MDB_RDONLY, "readOnly", false, options);
|
|
31
|
+
} else if (info[1].IsNumber()) {
|
|
32
|
+
flags = info[1].As<Number>();
|
|
33
|
+
}
|
|
34
|
+
MDB_txn *parentTxn;
|
|
35
|
+
if (info[2].IsObject()) {
|
|
36
|
+
napi_unwrap(info.Env(), info[2], (void**) &parentTw);
|
|
37
|
+
parentTxn = parentTw->txn;
|
|
38
|
+
} else {
|
|
39
|
+
parentTxn = nullptr;
|
|
40
|
+
parentTw = nullptr;
|
|
41
|
+
// Check existence of current write transaction
|
|
42
|
+
if (0 == (flags & MDB_RDONLY)) {
|
|
43
|
+
if (ew->currentWriteTxn != nullptr) {
|
|
44
|
+
throwError(info.Env(), "You have already opened a write transaction in the current process, can't open a second one.");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
//fprintf(stderr, "begin sync txn");
|
|
48
|
+
auto writeWorker = ew->writeWorker;
|
|
49
|
+
if (writeWorker) {
|
|
50
|
+
parentTxn = writeWorker->AcquireTxn(&flags); // see if we have a paused transaction
|
|
51
|
+
// else we create a child transaction from the current batch transaction. TODO: Except in WRITEMAP mode, where we need to indicate that the transaction should not be committed
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//fprintf(stderr, "txn_begin from txn.cpp %u %p\n", flags, parentTxn);
|
|
56
|
+
if ((flags & MDB_RDONLY) && parentTxn) {
|
|
57
|
+
// if a txn is passed in, we check to see if it is up-to-date and can be reused
|
|
58
|
+
MDB_envinfo stat;
|
|
59
|
+
mdb_env_info(ew->env, &stat);
|
|
60
|
+
if (mdb_txn_id(parentTxn) == stat.me_last_txnid) {
|
|
61
|
+
txn = nullptr;
|
|
62
|
+
info.This().As<Object>().Set("address", Number::New(info.Env(), 0));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
parentTxn = nullptr;
|
|
66
|
+
}
|
|
67
|
+
int rc = mdb_txn_begin(ew->env, parentTxn, flags, &txn);
|
|
68
|
+
if (rc == MDB_READERS_FULL) { // try again after reader check, in case a dead process frees a slot
|
|
69
|
+
int dead;
|
|
70
|
+
mdb_reader_check(ew->env, &dead);
|
|
71
|
+
ew->consolidateTxns();
|
|
72
|
+
rc = mdb_txn_begin(ew->env, parentTxn, flags, &txn);
|
|
73
|
+
}
|
|
74
|
+
if (rc != 0) {
|
|
75
|
+
txn = nullptr;
|
|
76
|
+
throwLmdbError(info.Env(), rc);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Set the current write transaction
|
|
82
|
+
if (0 == (flags & MDB_RDONLY)) {
|
|
83
|
+
ew->currentWriteTxn = this;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
ew->readTxns.push_back(this);
|
|
87
|
+
ew->currentReadTxn = txn;
|
|
88
|
+
}
|
|
89
|
+
this->parentTw = parentTw;
|
|
90
|
+
this->flags = flags;
|
|
91
|
+
this->ew = ew;
|
|
92
|
+
this->env = ew->env;
|
|
93
|
+
info.This().As<Object>().Set("address", Number::New(info.Env(), (size_t) this));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
TxnWrap::~TxnWrap() {
|
|
97
|
+
// Close if not closed already
|
|
98
|
+
if (this->txn) {
|
|
99
|
+
mdb_txn_abort(txn);
|
|
100
|
+
this->removeFromEnvWrap();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void TxnWrap::removeFromEnvWrap() {
|
|
105
|
+
if (this->ew) {
|
|
106
|
+
if (this->ew->currentWriteTxn == this) {
|
|
107
|
+
this->ew->currentWriteTxn = this->parentTw;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
auto it = std::find(ew->readTxns.begin(), ew->readTxns.end(), this);
|
|
111
|
+
if (it != ew->readTxns.end()) {
|
|
112
|
+
ew->readTxns.erase(it);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
this->ew = nullptr;
|
|
116
|
+
}
|
|
117
|
+
this->txn = nullptr;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
Value TxnWrap::commit(const Napi::CallbackInfo& info) {
|
|
121
|
+
// this should only be used for committing read-only txns
|
|
122
|
+
if (!this->txn) {
|
|
123
|
+
return throwError(info.Env(), "The transaction is already closed.");
|
|
124
|
+
}
|
|
125
|
+
int rc = mdb_txn_commit(this->txn);
|
|
126
|
+
this->removeFromEnvWrap();
|
|
127
|
+
if (rc != 0) {
|
|
128
|
+
return throwLmdbError(info.Env(), rc);
|
|
129
|
+
}
|
|
130
|
+
return info.Env().Undefined();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
Value TxnWrap::abort(const Napi::CallbackInfo& info) {
|
|
134
|
+
if (!this->txn) {
|
|
135
|
+
return throwError(info.Env(), "The transaction is already closed.");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
mdb_txn_abort(this->txn);
|
|
139
|
+
this->removeFromEnvWrap();
|
|
140
|
+
return info.Env().Undefined();
|
|
141
|
+
}
|
|
142
|
+
NAPI_FUNCTION(resetTxn) {
|
|
143
|
+
ARGS(1)
|
|
144
|
+
GET_INT64_ARG(0);
|
|
145
|
+
TxnWrap* tw = (TxnWrap*) i64;
|
|
146
|
+
if (!tw->txn || !tw->getEnv()) {
|
|
147
|
+
THROW_ERROR("The transaction is already closed.");
|
|
148
|
+
} else {
|
|
149
|
+
tw->reset();
|
|
150
|
+
RETURN_UNDEFINED;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
void resetTxnFFI(double twPointer) {
|
|
154
|
+
TxnWrap* tw = (TxnWrap*) (size_t) twPointer;
|
|
155
|
+
if (tw->txn && tw->getEnv()) tw->reset();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
void TxnWrap::reset() {
|
|
159
|
+
ew->readTxnRenewed = false;
|
|
160
|
+
mdb_txn_reset(txn);
|
|
161
|
+
}
|
|
162
|
+
Value TxnWrap::renew(const Napi::CallbackInfo& info) {
|
|
163
|
+
if (!this->txn || !this->ew->env) {
|
|
164
|
+
return throwError(info.Env(), "The transaction is already closed.");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
int rc = mdb_txn_renew(this->txn);
|
|
168
|
+
if (rc != 0) {
|
|
169
|
+
return throwLmdbError(info.Env(), rc);
|
|
170
|
+
}
|
|
171
|
+
return info.Env().Undefined();
|
|
172
|
+
}
|
|
173
|
+
MDB_env* TxnWrap::getEnv() {
|
|
174
|
+
return this->ew->env;
|
|
175
|
+
}
|
|
176
|
+
void TxnWrap::setupExports(Napi::Env env, Object exports) {
|
|
177
|
+
// TxnWrap: Prepare constructor template
|
|
178
|
+
Function TxnClass = DefineClass(env, "Txn", {
|
|
179
|
+
// TxnWrap: Add functions to the prototype
|
|
180
|
+
TxnWrap::InstanceMethod("commit", &TxnWrap::commit),
|
|
181
|
+
TxnWrap::InstanceMethod("abort", &TxnWrap::abort),
|
|
182
|
+
TxnWrap::InstanceMethod("renew", &TxnWrap::renew),
|
|
183
|
+
});
|
|
184
|
+
exports.Set("Txn", TxnClass);
|
|
185
|
+
EXPORT_NAPI_FUNCTION("resetTxn", resetTxn);
|
|
186
|
+
EXPORT_FUNCTION_ADDRESS("resetTxnPtr", resetTxnFFI);
|
|
187
|
+
//txnTpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
188
|
+
}
|
|
189
|
+
// This file contains code from the node-lmdb project
|
|
190
|
+
// Copyright (c) 2013-2017 Timur Kristóf
|
|
191
|
+
// Copyright (c) 2021 Kristopher Tate
|
|
192
|
+
// Licensed to you under the terms of the MIT license
|
|
193
|
+
//
|
|
194
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
195
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
196
|
+
// in the Software without restriction, including without limitation the rights
|
|
197
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
198
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
199
|
+
// furnished to do so, subject to the following conditions:
|
|
200
|
+
|
|
201
|
+
// The above copyright notice and this permission notice shall be included in
|
|
202
|
+
// all copies or substantial portions of the Software.
|
|
203
|
+
|
|
204
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
205
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
206
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
207
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
208
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
209
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
210
|
+
// THE SOFTWARE.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
#include "lmdb-js.h"
|
|
2
|
+
#if ENABLE_V8_API
|
|
3
|
+
#include <string.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <v8.h>
|
|
6
|
+
#include <node.h>
|
|
7
|
+
|
|
8
|
+
#if NODE_VERSION_AT_LEAST(16,6,0)
|
|
9
|
+
#if NODE_VERSION_AT_LEAST(17,0,0)
|
|
10
|
+
#include "../dependencies/v8/v8-fast-api-calls.h"
|
|
11
|
+
#else
|
|
12
|
+
#include "../dependencies/v8/v8-fast-api-calls-v16.h"
|
|
13
|
+
#endif
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
using namespace v8;
|
|
17
|
+
int32_t getByBinaryFast(Local<v8::Object> instance, double dwPointer, uint32_t keySize, uint32_t ifNotTxnId, int64_t txnAddress) {
|
|
18
|
+
DbiWrap* dw = (DbiWrap*) (size_t) dwPointer;
|
|
19
|
+
return dw->doGetByBinary(keySize, ifNotTxnId, txnAddress);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//class NanWrap : public Nan::ObjectWrap {};
|
|
23
|
+
void getByBinaryV8(const FunctionCallbackInfo<v8::Value>& info) {
|
|
24
|
+
Isolate* isolate = Isolate::GetCurrent();
|
|
25
|
+
auto context = isolate->GetCurrentContext();
|
|
26
|
+
DbiWrap* dw = (DbiWrap*) (size_t) info[0]->NumberValue(context).FromJust();
|
|
27
|
+
info.GetReturnValue().Set(v8::Number::New(isolate, dw->doGetByBinary(
|
|
28
|
+
info[1]->Uint32Value(context).FromJust(),
|
|
29
|
+
info[2]->Uint32Value(context).FromJust(),
|
|
30
|
+
info[3]->NumberValue(context).FromJust())));
|
|
31
|
+
}
|
|
32
|
+
int32_t positionFast(Local<v8::Object> instance, double cwPointer, uint32_t flags, uint32_t offset, uint32_t keySize, uint64_t endKeyAddress) {
|
|
33
|
+
CursorWrap* cw = (CursorWrap*) (size_t) cwPointer;
|
|
34
|
+
DbiWrap* dw = cw->dw;
|
|
35
|
+
dw->getFast = true;
|
|
36
|
+
cw->flags = flags;
|
|
37
|
+
return cw->doPosition(offset, keySize, endKeyAddress);
|
|
38
|
+
}
|
|
39
|
+
void positionV8(const FunctionCallbackInfo<v8::Value>& info) {
|
|
40
|
+
Isolate* isolate = Isolate::GetCurrent();
|
|
41
|
+
CursorWrap* cw = (CursorWrap*) (size_t) info[0]->NumberValue(isolate->GetCurrentContext()).FromJust();
|
|
42
|
+
cw->flags = info[1]->Uint32Value(isolate->GetCurrentContext()).FromJust();
|
|
43
|
+
uint32_t offset = info[2]->Uint32Value(isolate->GetCurrentContext()).FromJust();
|
|
44
|
+
uint32_t keySize = info[3]->Uint32Value(isolate->GetCurrentContext()).FromJust();
|
|
45
|
+
uint64_t endKeyAddress = info[4]->IntegerValue(isolate->GetCurrentContext()).FromJust();
|
|
46
|
+
info.GetReturnValue().Set(v8::Number::New(isolate, cw->doPosition(offset, keySize, endKeyAddress)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
int32_t iterateFast(Local<v8::Object> instance, double cwPointer) {
|
|
50
|
+
CursorWrap* cw = (CursorWrap*) (size_t) cwPointer;
|
|
51
|
+
DbiWrap* dw = cw->dw;
|
|
52
|
+
dw->getFast = true;
|
|
53
|
+
MDB_val key, data;
|
|
54
|
+
int rc = mdb_cursor_get(cw->cursor, &key, &data, cw->iteratingOp);
|
|
55
|
+
return cw->returnEntry(rc, key, data);
|
|
56
|
+
}
|
|
57
|
+
void iterateV8(const FunctionCallbackInfo<v8::Value>& info) {
|
|
58
|
+
Isolate* isolate = Isolate::GetCurrent();
|
|
59
|
+
CursorWrap* cw = (CursorWrap*) (size_t) info[0]->NumberValue(isolate->GetCurrentContext()).FromJust();
|
|
60
|
+
DbiWrap* dw = cw->dw;
|
|
61
|
+
dw->getFast = true;
|
|
62
|
+
MDB_val key, data;
|
|
63
|
+
int rc = mdb_cursor_get(cw->cursor, &key, &data, cw->iteratingOp);
|
|
64
|
+
info.GetReturnValue().Set(v8::Number::New(isolate, cw->returnEntry(rc, key, data)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
int32_t writeFast(Local<v8::Object> instance, double ewPointer, uint64_t instructionAddress) {
|
|
68
|
+
EnvWrap* ew = (EnvWrap*) (size_t) ewPointer;
|
|
69
|
+
int rc;
|
|
70
|
+
if (instructionAddress)
|
|
71
|
+
rc = WriteWorker::DoWrites(ew->writeTxn->txn, ew, (uint32_t*)instructionAddress, nullptr);
|
|
72
|
+
else {
|
|
73
|
+
pthread_cond_signal(ew->writingCond);
|
|
74
|
+
rc = 0;
|
|
75
|
+
}
|
|
76
|
+
return rc;
|
|
77
|
+
// if (rc && !(rc == MDB_KEYEXIST || rc == MDB_NOTFOUND))
|
|
78
|
+
// options.fallback = true;
|
|
79
|
+
}
|
|
80
|
+
void writeV8(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
|
81
|
+
Isolate* isolate = Isolate::GetCurrent();
|
|
82
|
+
EnvWrap* ew = (EnvWrap*) (size_t) info[0]->NumberValue(isolate->GetCurrentContext()).FromJust();
|
|
83
|
+
uint64_t instructionAddress = info[1]->IntegerValue(isolate->GetCurrentContext()).FromJust();
|
|
84
|
+
int rc;
|
|
85
|
+
if (instructionAddress)
|
|
86
|
+
rc = WriteWorker::DoWrites(ew->writeTxn->txn, ew, (uint32_t*)instructionAddress, nullptr);
|
|
87
|
+
else {
|
|
88
|
+
pthread_cond_signal(ew->writingCond);
|
|
89
|
+
rc = 0;
|
|
90
|
+
}
|
|
91
|
+
info.GetReturnValue().Set(v8::Number::New(isolate, rc));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void resetTxnFast(Local<v8::Object> instance, double twPointer) {
|
|
95
|
+
TxnWrap* tw = (TxnWrap*) (size_t) twPointer;
|
|
96
|
+
tw->reset();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
void resetTxnV8(const FunctionCallbackInfo<v8::Value>& info) {
|
|
100
|
+
Isolate* isolate = Isolate::GetCurrent();
|
|
101
|
+
TxnWrap* tw = (TxnWrap*) (size_t) info[0]->NumberValue(isolate->GetCurrentContext()).FromJust();
|
|
102
|
+
tw->reset();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void noopFast(Local<v8::Object> instance) {
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
void noopV8(const FunctionCallbackInfo<v8::Value>& info) {
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
void clearKeptObjects(const FunctionCallbackInfo<v8::Value>& info) {
|
|
113
|
+
#if NODE_VERSION_AT_LEAST(14,0,0)
|
|
114
|
+
v8::Isolate::GetCurrent()->ClearKeptObjects();
|
|
115
|
+
#endif
|
|
116
|
+
}
|
|
117
|
+
void detachBuffer(const FunctionCallbackInfo<v8::Value>& info) {
|
|
118
|
+
#if NODE_VERSION_AT_LEAST(12,0,0)
|
|
119
|
+
v8::Local<v8::ArrayBuffer> v8Buffer = Local<v8::ArrayBuffer>::Cast(info[0]);
|
|
120
|
+
v8Buffer->Detach();
|
|
121
|
+
#endif
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#endif
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
#define EXPORT_FAST(exportName, slowName, fastName) {\
|
|
128
|
+
auto fast = CFunction::Make(fastName);\
|
|
129
|
+
exports->Set(isolate->GetCurrentContext(), v8::String::NewFromUtf8(isolate, exportName, NewStringType::kInternalized).ToLocalChecked(), FunctionTemplate::New(\
|
|
130
|
+
isolate, slowName, Local<v8::Value>(),\
|
|
131
|
+
Local<Signature>(), 0, ConstructorBehavior::kThrow,\
|
|
132
|
+
SideEffectType::kHasNoSideEffect, &fast)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());\
|
|
133
|
+
}
|
|
134
|
+
#define EXPORT_FUNCTION(exportName, funcName) \
|
|
135
|
+
exports->Set(isolate->GetCurrentContext(), v8::String::NewFromUtf8(isolate, exportName, NewStringType::kInternalized).ToLocalChecked(), FunctionTemplate::New(\
|
|
136
|
+
isolate, funcName, Local<v8::Value>(),\
|
|
137
|
+
Local<Signature>(), 0, ConstructorBehavior::kThrow,\
|
|
138
|
+
SideEffectType::kHasNoSideEffect)->GetFunction(isolate->GetCurrentContext()).ToLocalChecked());
|
|
139
|
+
NAPI_FUNCTION(enableDirectV8) {
|
|
140
|
+
ARGS(2)
|
|
141
|
+
#if ENABLE_V8_API
|
|
142
|
+
Isolate* isolate = Isolate::GetCurrent();
|
|
143
|
+
napi_value exportsValue = args[0];
|
|
144
|
+
Local<v8::Object> exports;
|
|
145
|
+
memcpy((void*) &exports, (void*) &exportsValue, sizeof(exportsValue));
|
|
146
|
+
#if NODE_VERSION_AT_LEAST(16,6,1)
|
|
147
|
+
bool useFastApi;
|
|
148
|
+
napi_get_value_bool(env, args[1], &useFastApi);
|
|
149
|
+
if (useFastApi) {
|
|
150
|
+
EXPORT_FAST("getByBinary", getByBinaryV8, getByBinaryFast);
|
|
151
|
+
EXPORT_FAST("position", positionV8, positionFast);
|
|
152
|
+
EXPORT_FAST("iterate", iterateV8, iterateFast);
|
|
153
|
+
EXPORT_FAST("write", writeV8, writeFast);
|
|
154
|
+
EXPORT_FAST("resetTxn", resetTxnV8, resetTxnFast);
|
|
155
|
+
EXPORT_FAST("noop", noopV8, noopFast);
|
|
156
|
+
} else {
|
|
157
|
+
#endif
|
|
158
|
+
EXPORT_FUNCTION("getByBinary", getByBinaryV8);
|
|
159
|
+
EXPORT_FUNCTION("position", positionV8);
|
|
160
|
+
EXPORT_FUNCTION("iterate", iterateV8);
|
|
161
|
+
EXPORT_FUNCTION("write", writeV8);
|
|
162
|
+
EXPORT_FUNCTION("noop", noopV8);
|
|
163
|
+
#if NODE_VERSION_AT_LEAST(16,6,1)
|
|
164
|
+
}
|
|
165
|
+
#endif
|
|
166
|
+
EXPORT_FUNCTION("clearKeptObjects", clearKeptObjects);
|
|
167
|
+
EXPORT_FUNCTION("detachBuffer", detachBuffer);
|
|
168
|
+
#endif
|
|
169
|
+
RETURN_UNDEFINED
|
|
170
|
+
}
|
package/src/windows.c
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#ifdef _WIN32
|
|
2
|
+
#include <windows.h>
|
|
3
|
+
#include <synchapi.h>
|
|
4
|
+
static int initializeMemoryPriority = 1;
|
|
5
|
+
static MEMORY_PRIORITY_INFORMATION lowMemPriority;
|
|
6
|
+
static MEMORY_PRIORITY_INFORMATION normalMemPriority;
|
|
7
|
+
int lowerMemoryPriority(int priority) {
|
|
8
|
+
if (initializeMemoryPriority) {
|
|
9
|
+
GetThreadInformation(GetCurrentThread(), ThreadMemoryPriority, &normalMemPriority, sizeof(normalMemPriority));
|
|
10
|
+
// fprintf(stderr, "initialized memory %u setting to %u\n", normalMemPriority.MemoryPriority, priority);
|
|
11
|
+
ZeroMemory(&lowMemPriority, sizeof(lowMemPriority));
|
|
12
|
+
lowMemPriority.MemoryPriority = priority;
|
|
13
|
+
initializeMemoryPriority = 0;
|
|
14
|
+
}
|
|
15
|
+
void* instruction;
|
|
16
|
+
void* pointer;
|
|
17
|
+
WaitOnAddress(instruction, pointer, 8, INFINITE);
|
|
18
|
+
|
|
19
|
+
return SetThreadInformation(GetCurrentThread(), ThreadMemoryPriority, &lowMemPriority, sizeof(lowMemPriority));
|
|
20
|
+
}
|
|
21
|
+
int setProcessMemoryPriority(int priority) {
|
|
22
|
+
if (initializeMemoryPriority) {
|
|
23
|
+
GetThreadInformation(GetCurrentThread(), ThreadMemoryPriority, &normalMemPriority, sizeof(normalMemPriority));
|
|
24
|
+
// fprintf(stderr, "initialized memory %u setting to %u\n", normalMemPriority.MemoryPriority, priority);
|
|
25
|
+
ZeroMemory(&lowMemPriority, sizeof(lowMemPriority));
|
|
26
|
+
lowMemPriority.MemoryPriority = priority;
|
|
27
|
+
initializeMemoryPriority = 0;
|
|
28
|
+
}
|
|
29
|
+
return SetProcessInformation(GetCurrentProcess(), ProcessMemoryPriority, &lowMemPriority, sizeof(lowMemPriority));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
int restoreMemoryPriority() {
|
|
33
|
+
return SetThreadInformation(GetCurrentThread(), ThreadMemoryPriority, &normalMemPriority, sizeof(normalMemPriority));
|
|
34
|
+
}
|
|
35
|
+
#endif
|