@nxtedition/rocksdb 7.0.62 → 7.0.65
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/binding.cc +437 -914
- package/binding.gyp +50 -79
- package/deps/rocksdb/rocksdb/db/wal_manager.cc +4 -0
- package/index.js +58 -134
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
- package/util.h +339 -0
package/binding.gyp
CHANGED
|
@@ -1,83 +1,54 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
"variables": {"openssl_fips": "0"},
|
|
3
|
+
"targets": [
|
|
4
|
+
{
|
|
5
|
+
"target_name": "leveldown",
|
|
6
|
+
"conditions": [
|
|
7
|
+
[
|
|
8
|
+
"OS == 'linux'",
|
|
9
|
+
{
|
|
10
|
+
"cflags": [
|
|
11
|
+
"-msse4.2",
|
|
12
|
+
"-mpclmul",
|
|
13
|
+
"-mavx",
|
|
14
|
+
"-mavx2",
|
|
15
|
+
"-mbmi",
|
|
16
|
+
"-mlzcnt"
|
|
17
|
+
],
|
|
18
|
+
"ccflags": ["-flto"],
|
|
19
|
+
"cflags!": ["-fno-exceptions"],
|
|
20
|
+
"cflags_cc!": ["-fno-exceptions"],
|
|
21
|
+
"ldflags": ["-flto", "-fuse-linker-plugin"]
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"OS == 'mac'",
|
|
26
|
+
{
|
|
27
|
+
"xcode_settings": {
|
|
28
|
+
"WARNING_CFLAGS": [
|
|
29
|
+
"-Wno-sign-compare",
|
|
30
|
+
"-Wno-unused-variable",
|
|
31
|
+
"-Wno-unused-function",
|
|
32
|
+
"-Wno-ignored-qualifiers"
|
|
33
|
+
],
|
|
34
|
+
"OTHER_CPLUSPLUSFLAGS": [
|
|
35
|
+
"-mmacosx-version-min=12.2.1",
|
|
36
|
+
"-std=c++20",
|
|
37
|
+
"-fno-omit-frame-pointer",
|
|
38
|
+
"-momit-leaf-frame-pointer",
|
|
39
|
+
"-arch x86_64",
|
|
40
|
+
"-arch arm64"
|
|
41
|
+
],
|
|
42
|
+
"GCC_ENABLE_CPP_RTTI": "YES",
|
|
43
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
44
|
+
"MACOSX_DEPLOYMENT_TARGET": "12.2.1"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
22
47
|
]
|
|
23
|
-
},
|
|
24
|
-
"VCLinkerTool": {
|
|
25
|
-
"AdditionalDependencies": ["Shlwapi.lib", "rpcrt4.lib"]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"cflags": ["-std=c++20"],
|
|
31
|
-
"cflags!": ["-fno-rtti"],
|
|
32
|
-
"cflags_cc!": ["-fno-rtti"],
|
|
33
|
-
"cflags_cc+": ["-frtti"]
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
[
|
|
37
|
-
"OS == 'linux'",
|
|
38
|
-
{
|
|
39
|
-
"cflags": [
|
|
40
|
-
"-msse4.2",
|
|
41
|
-
"-mpclmul",
|
|
42
|
-
"-mavx",
|
|
43
|
-
"-mavx2",
|
|
44
|
-
"-mbmi",
|
|
45
|
-
"-mlzcnt"
|
|
46
48
|
],
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
],
|
|
53
|
-
[
|
|
54
|
-
"OS == 'mac'",
|
|
55
|
-
{
|
|
56
|
-
"xcode_settings": {
|
|
57
|
-
"WARNING_CFLAGS": [
|
|
58
|
-
"-Wno-sign-compare",
|
|
59
|
-
"-Wno-unused-variable",
|
|
60
|
-
"-Wno-unused-function",
|
|
61
|
-
"-Wno-ignored-qualifiers"
|
|
62
|
-
],
|
|
63
|
-
"OTHER_CPLUSPLUSFLAGS": [
|
|
64
|
-
"-mmacosx-version-min=12.2.1",
|
|
65
|
-
"-std=c++20",
|
|
66
|
-
"-fno-omit-frame-pointer",
|
|
67
|
-
"-momit-leaf-frame-pointer",
|
|
68
|
-
"-arch x86_64",
|
|
69
|
-
"-arch arm64"
|
|
70
|
-
],
|
|
71
|
-
"GCC_ENABLE_CPP_RTTI": "YES",
|
|
72
|
-
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
73
|
-
"MACOSX_DEPLOYMENT_TARGET": "12.2.1"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
]
|
|
77
|
-
],
|
|
78
|
-
"dependencies": ["<(module_root_dir)/deps/rocksdb/rocksdb.gyp:rocksdb"],
|
|
79
|
-
"include_dirs": ["<!(node -e \"require('napi-macros')\")"],
|
|
80
|
-
"sources": ["binding.cc"]
|
|
81
|
-
}
|
|
82
|
-
]
|
|
49
|
+
"dependencies": ["<(module_root_dir)/deps/rocksdb/rocksdb.gyp:rocksdb"],
|
|
50
|
+
"include_dirs": ["<!(node -e \"require('napi-macros')\")"],
|
|
51
|
+
"sources": ["binding.cc"]
|
|
52
|
+
}
|
|
53
|
+
]
|
|
83
54
|
}
|
|
@@ -120,6 +120,10 @@ Status WalManager::GetUpdatesSince(
|
|
|
120
120
|
return s;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
std::sort(std::begin(*wal_files), std::end(*wal_files), [](auto& lhs, auto& rhs) {
|
|
124
|
+
return lhs->StartSequence() > rhs->StartSequence();
|
|
125
|
+
});
|
|
126
|
+
|
|
123
127
|
s = RetainProbableWalFiles(*wal_files, seq);
|
|
124
128
|
if (!s.ok()) {
|
|
125
129
|
return s;
|
package/index.js
CHANGED
|
@@ -11,13 +11,16 @@ const { Iterator } = require('./iterator')
|
|
|
11
11
|
const { Readable } = require('readable-stream')
|
|
12
12
|
const os = require('os')
|
|
13
13
|
const AbortController = require('abort-controller')
|
|
14
|
-
const assert = require('assert')
|
|
15
14
|
|
|
16
15
|
const kContext = Symbol('context')
|
|
17
16
|
const kColumns = Symbol('columns')
|
|
18
17
|
const kLocation = Symbol('location')
|
|
19
18
|
const kPromise = Symbol('promise')
|
|
20
19
|
const kUpdates = Symbol('updates')
|
|
20
|
+
const kRef = Symbol('ref')
|
|
21
|
+
const kUnref = Symbol('unref')
|
|
22
|
+
const kRefs = Symbol('refs')
|
|
23
|
+
const kPendingClose = Symbol('pendingClose')
|
|
21
24
|
|
|
22
25
|
const EMPTY = {}
|
|
23
26
|
|
|
@@ -67,6 +70,9 @@ class RocksLevel extends AbstractLevel {
|
|
|
67
70
|
this[kContext] = binding.db_init()
|
|
68
71
|
this[kColumns] = {}
|
|
69
72
|
|
|
73
|
+
this[kRefs] = 0
|
|
74
|
+
this[kPendingClose] = null
|
|
75
|
+
|
|
70
76
|
// .updates(...) uses 'update' listener.
|
|
71
77
|
this.setMaxListeners(100)
|
|
72
78
|
}
|
|
@@ -102,8 +108,23 @@ class RocksLevel extends AbstractLevel {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
|
|
111
|
+
[kRef] () {
|
|
112
|
+
this[kRefs]++
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
[kUnref] () {
|
|
116
|
+
this[kRefs]--
|
|
117
|
+
if (this[kRefs] === 0 && this[kPendingClose]) {
|
|
118
|
+
this[kPendingClose]()
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
105
122
|
_close (callback) {
|
|
106
|
-
|
|
123
|
+
if (this[kRefs]) {
|
|
124
|
+
this[kPendingClose] = callback
|
|
125
|
+
} else {
|
|
126
|
+
binding.db_close(this[kContext], callback)
|
|
127
|
+
}
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
_put (key, value, options, callback) {
|
|
@@ -138,9 +159,14 @@ class RocksLevel extends AbstractLevel {
|
|
|
138
159
|
callback = fromCallback(callback, kPromise)
|
|
139
160
|
|
|
140
161
|
try {
|
|
141
|
-
|
|
162
|
+
this[kRef]()
|
|
163
|
+
binding.db_get_many(this[kContext], keys, options ?? EMPTY, (err, val) => {
|
|
164
|
+
callback(err, val)
|
|
165
|
+
this[kUnref]()
|
|
166
|
+
})
|
|
142
167
|
} catch (err) {
|
|
143
168
|
process.nextTick(callback, err)
|
|
169
|
+
this[kUnref]()
|
|
144
170
|
}
|
|
145
171
|
|
|
146
172
|
return callback[kPromise]
|
|
@@ -223,36 +249,6 @@ class RocksLevel extends AbstractLevel {
|
|
|
223
249
|
return binding.db_get_property(this[kContext], property)
|
|
224
250
|
}
|
|
225
251
|
|
|
226
|
-
async getCurrentWALFile () {
|
|
227
|
-
if (this.status !== 'open') {
|
|
228
|
-
throw new ModuleError('Database is not open', {
|
|
229
|
-
code: 'LEVEL_DATABASE_NOT_OPEN'
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return binding.db_get_current_wal_file(this[kContext])
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
async getSortedWALFiles () {
|
|
237
|
-
if (this.status !== 'open') {
|
|
238
|
-
throw new ModuleError('Database is not open', {
|
|
239
|
-
code: 'LEVEL_DATABASE_NOT_OPEN'
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return binding.db_get_sorted_wal_files(this[kContext])
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async flushWAL (options) {
|
|
247
|
-
if (this.status !== 'open') {
|
|
248
|
-
throw new ModuleError('Database is not open', {
|
|
249
|
-
code: 'LEVEL_DATABASE_NOT_OPEN'
|
|
250
|
-
})
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
binding.db_flush_wal(this[kContext], options)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
252
|
async query (options) {
|
|
257
253
|
if (this.status !== 'open') {
|
|
258
254
|
throw new ModuleError('Database is not open', {
|
|
@@ -260,17 +256,9 @@ class RocksLevel extends AbstractLevel {
|
|
|
260
256
|
})
|
|
261
257
|
}
|
|
262
258
|
|
|
263
|
-
const context = binding.iterator_init(this[kContext], options)
|
|
264
|
-
const resource = {
|
|
265
|
-
callback: null,
|
|
266
|
-
close (callback) {
|
|
267
|
-
this.callback = callback
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
259
|
+
const context = binding.iterator_init(this[kContext], options ?? {})
|
|
271
260
|
try {
|
|
272
|
-
this
|
|
273
|
-
|
|
261
|
+
this[kRef]()
|
|
274
262
|
const limit = options.limit ?? 1000
|
|
275
263
|
return await new Promise((resolve, reject) => binding.iterator_nextv(context, limit, (err, rows, finished) => {
|
|
276
264
|
if (err) {
|
|
@@ -284,11 +272,8 @@ class RocksLevel extends AbstractLevel {
|
|
|
284
272
|
}
|
|
285
273
|
}))
|
|
286
274
|
} finally {
|
|
287
|
-
this.detachResource(resource)
|
|
288
275
|
binding.iterator_close(context)
|
|
289
|
-
|
|
290
|
-
resource.callback()
|
|
291
|
-
}
|
|
276
|
+
this[kUnref]()
|
|
292
277
|
}
|
|
293
278
|
}
|
|
294
279
|
|
|
@@ -348,35 +333,9 @@ class RocksLevel extends AbstractLevel {
|
|
|
348
333
|
|
|
349
334
|
const db = this
|
|
350
335
|
|
|
351
|
-
// HACK: https://github.com/facebook/rocksdb/issues/10476
|
|
352
|
-
async function * _updates (options) {
|
|
353
|
-
let first = true
|
|
354
|
-
for await (const update of db[kUpdates]({ ...options, since: Math.max(0, options.since - 1024) })) {
|
|
355
|
-
if (first) {
|
|
356
|
-
if (update.sequence > options.since) {
|
|
357
|
-
// HACK
|
|
358
|
-
db.emit('warning', `Invalid update sequence ${update.sequence} > ${options.since}. Starting from 0.`)
|
|
359
|
-
first = null
|
|
360
|
-
break
|
|
361
|
-
} else {
|
|
362
|
-
first = false
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
yield update
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (first === null) {
|
|
369
|
-
for await (const update of db[kUpdates]({ ...options, since: 0 })) {
|
|
370
|
-
yield update
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
336
|
try {
|
|
376
337
|
let since = options.since
|
|
377
|
-
|
|
378
|
-
assert(retryCount < 8)
|
|
379
|
-
|
|
338
|
+
while (true) {
|
|
380
339
|
const buffer = new Readable({
|
|
381
340
|
signal: ac.signal,
|
|
382
341
|
objectMode: true,
|
|
@@ -404,15 +363,23 @@ class RocksLevel extends AbstractLevel {
|
|
|
404
363
|
|
|
405
364
|
try {
|
|
406
365
|
if (since <= db.sequence) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
366
|
+
let first = true
|
|
367
|
+
for await (const update of db[kUpdates]({
|
|
368
|
+
...options,
|
|
369
|
+
signal: ac.signal,
|
|
370
|
+
// HACK: https://github.com/facebook/rocksdb/issues/10476
|
|
371
|
+
since: Math.max(0, options.since)
|
|
372
|
+
})) {
|
|
373
|
+
if (first) {
|
|
374
|
+
if (update.sequence > since) {
|
|
375
|
+
db.emit('warning', `Invalid updates sequence ${update.sequence} > ${options.since}.`)
|
|
376
|
+
}
|
|
377
|
+
first = false
|
|
410
378
|
}
|
|
411
379
|
|
|
412
380
|
if (update.sequence >= since) {
|
|
413
381
|
yield update
|
|
414
382
|
since = update.sequence + update.count
|
|
415
|
-
retryCount = 0
|
|
416
383
|
}
|
|
417
384
|
}
|
|
418
385
|
}
|
|
@@ -430,16 +397,13 @@ class RocksLevel extends AbstractLevel {
|
|
|
430
397
|
for await (const update of buffer) {
|
|
431
398
|
if (first) {
|
|
432
399
|
if (update.sequence > since) {
|
|
433
|
-
|
|
434
|
-
db.emit('warning', `Invalid batch sequence ${update.sequence} > ${options.since}. Starting from ${since}.`)
|
|
435
|
-
break
|
|
400
|
+
db.emit('warning', `Invalid batch sequence ${update.sequence} > ${options.since}.`)
|
|
436
401
|
}
|
|
437
402
|
first = false
|
|
438
403
|
}
|
|
439
404
|
if (update.sequence >= since) {
|
|
440
405
|
yield update
|
|
441
406
|
since = update.sequence + update.count
|
|
442
|
-
retryCount = 0
|
|
443
407
|
}
|
|
444
408
|
}
|
|
445
409
|
}
|
|
@@ -449,72 +413,32 @@ class RocksLevel extends AbstractLevel {
|
|
|
449
413
|
}
|
|
450
414
|
}
|
|
451
415
|
|
|
452
|
-
async * [kUpdates] (options) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
this.db.attachResource(this)
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
async next () {
|
|
463
|
-
if (this.closed) {
|
|
464
|
-
return {}
|
|
416
|
+
async * [kUpdates] ({ signal, ...options }) {
|
|
417
|
+
const context = binding.updates_init(this[kContext], options)
|
|
418
|
+
this[kRef]()
|
|
419
|
+
try {
|
|
420
|
+
while (true) {
|
|
421
|
+
if (signal?.aborted) {
|
|
422
|
+
throw new AbortError()
|
|
465
423
|
}
|
|
466
424
|
|
|
467
|
-
|
|
468
|
-
this.promise = null
|
|
425
|
+
const entry = await new Promise((resolve, reject) => binding.updates_next(context, (err, rows, sequence, count) => {
|
|
469
426
|
if (err) {
|
|
470
|
-
|
|
427
|
+
reject(err)
|
|
471
428
|
} else {
|
|
472
429
|
resolve({ rows, sequence, count })
|
|
473
430
|
}
|
|
474
431
|
}))
|
|
475
432
|
|
|
476
|
-
return this.promise
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
async close (callback) {
|
|
480
|
-
try {
|
|
481
|
-
await this.promise
|
|
482
|
-
} catch {
|
|
483
|
-
// Do nothing...
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
try {
|
|
487
|
-
if (!this.closed) {
|
|
488
|
-
this.closed = true
|
|
489
|
-
binding.updates_close(this.context)
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
if (callback) {
|
|
493
|
-
process.nextTick(callback)
|
|
494
|
-
}
|
|
495
|
-
} catch (err) {
|
|
496
|
-
if (callback) {
|
|
497
|
-
process.nextTick(callback, err)
|
|
498
|
-
} else {
|
|
499
|
-
throw err
|
|
500
|
-
}
|
|
501
|
-
} finally {
|
|
502
|
-
this.db.detachResource(this)
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const updates = new Updates(this, options)
|
|
508
|
-
try {
|
|
509
|
-
while (true) {
|
|
510
|
-
const entry = await updates.next()
|
|
511
433
|
if (!entry.rows) {
|
|
512
434
|
return
|
|
513
435
|
}
|
|
436
|
+
|
|
514
437
|
yield entry
|
|
515
438
|
}
|
|
516
439
|
} finally {
|
|
517
|
-
|
|
440
|
+
binding.updates_close(context)
|
|
441
|
+
this[kUnref]()
|
|
518
442
|
}
|
|
519
443
|
}
|
|
520
444
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|