@nxtedition/rocksdb 7.0.60 → 7.0.63
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 +7 -5
- package/index.js +38 -21
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
package/binding.cc
CHANGED
|
@@ -408,7 +408,8 @@ struct BatchIterator : public rocksdb::WriteBatch::Handler {
|
|
|
408
408
|
|
|
409
409
|
napi_status Iterate(napi_env env, const rocksdb::WriteBatch& batch, napi_value* result) {
|
|
410
410
|
cache_.reserve(batch.Count());
|
|
411
|
-
|
|
411
|
+
|
|
412
|
+
batch.Iterate(this); // TODO (fix): Handle error?
|
|
412
413
|
|
|
413
414
|
napi_value putStr;
|
|
414
415
|
NAPI_STATUS_RETURN(napi_create_string_utf8(env, "put", NAPI_AUTO_LENGTH, &putStr));
|
|
@@ -455,6 +456,8 @@ struct BatchIterator : public rocksdb::WriteBatch::Handler {
|
|
|
455
456
|
NAPI_STATUS_RETURN(napi_set_element(env, *result, n * 4 + 3, nullVal));
|
|
456
457
|
}
|
|
457
458
|
|
|
459
|
+
cache_.clear();
|
|
460
|
+
|
|
458
461
|
return napi_ok;
|
|
459
462
|
}
|
|
460
463
|
|
|
@@ -1156,9 +1159,8 @@ NAPI_METHOD(db_open) {
|
|
|
1156
1159
|
"leveldown.open", env, callback, database, false,
|
|
1157
1160
|
[=](auto& handles, auto& database) -> rocksdb::Status {
|
|
1158
1161
|
rocksdb::DB* db = nullptr;
|
|
1159
|
-
const auto status = descriptors.empty()
|
|
1160
|
-
|
|
1161
|
-
: rocksdb::DB::Open(dbOptions, location, descriptors, &handles, &db);
|
|
1162
|
+
const auto status = descriptors.empty() ? rocksdb::DB::Open(dbOptions, location, &db)
|
|
1163
|
+
: rocksdb::DB::Open(dbOptions, location, descriptors, &handles, &db);
|
|
1162
1164
|
database.db_.reset(db);
|
|
1163
1165
|
return status;
|
|
1164
1166
|
},
|
|
@@ -1378,7 +1380,7 @@ NAPI_METHOD(db_get_many) {
|
|
|
1378
1380
|
keys2.emplace_back(key);
|
|
1379
1381
|
}
|
|
1380
1382
|
std::vector<rocksdb::Status> statuses;
|
|
1381
|
-
|
|
1383
|
+
|
|
1382
1384
|
statuses.resize(keys2.size());
|
|
1383
1385
|
values.resize(keys2.size());
|
|
1384
1386
|
|
package/index.js
CHANGED
|
@@ -66,7 +66,7 @@ class RocksLevel extends AbstractLevel {
|
|
|
66
66
|
this[kContext] = binding.db_init()
|
|
67
67
|
this[kColumns] = {}
|
|
68
68
|
|
|
69
|
-
// .updates(...) uses '
|
|
69
|
+
// .updates(...) uses 'update' listener.
|
|
70
70
|
this.setMaxListeners(100)
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -178,7 +178,11 @@ class RocksLevel extends AbstractLevel {
|
|
|
178
178
|
try {
|
|
179
179
|
const seq = this.sequence
|
|
180
180
|
binding.batch_write(this[kContext], context, options)
|
|
181
|
-
this.emit('
|
|
181
|
+
this.emit('update', {
|
|
182
|
+
rows: batch.toArray(),
|
|
183
|
+
count: batch.length,
|
|
184
|
+
sequence: seq + 1
|
|
185
|
+
})
|
|
182
186
|
process.nextTick(callback, null)
|
|
183
187
|
} catch (err) {
|
|
184
188
|
process.nextTick(callback, err)
|
|
@@ -343,17 +347,14 @@ class RocksLevel extends AbstractLevel {
|
|
|
343
347
|
|
|
344
348
|
const db = this
|
|
345
349
|
|
|
346
|
-
|
|
347
|
-
async function* _updates (options) {
|
|
350
|
+
async function * _updates (options) {
|
|
348
351
|
let first = true
|
|
349
|
-
for await (const update of db[kUpdates](options)) {
|
|
352
|
+
for await (const update of db[kUpdates]({ ...options, since: Math.max(0, options.since - 1024) })) {
|
|
350
353
|
if (first) {
|
|
351
354
|
if (update.sequence > options.since) {
|
|
352
355
|
// HACK
|
|
353
356
|
db.emit('warning', `Invalid update sequence ${update.sequence} > ${options.since}. Starting from 0.`)
|
|
354
|
-
|
|
355
|
-
yield update
|
|
356
|
-
}
|
|
357
|
+
first = null
|
|
357
358
|
break
|
|
358
359
|
} else {
|
|
359
360
|
first = false
|
|
@@ -361,6 +362,12 @@ class RocksLevel extends AbstractLevel {
|
|
|
361
362
|
}
|
|
362
363
|
yield update
|
|
363
364
|
}
|
|
365
|
+
|
|
366
|
+
if (first === null) {
|
|
367
|
+
for await (const update of db[kUpdates]({ ...options, since: 0 })) {
|
|
368
|
+
yield update
|
|
369
|
+
}
|
|
370
|
+
}
|
|
364
371
|
}
|
|
365
372
|
|
|
366
373
|
try {
|
|
@@ -371,22 +378,18 @@ class RocksLevel extends AbstractLevel {
|
|
|
371
378
|
objectMode: true,
|
|
372
379
|
readableHighWaterMark: 1024,
|
|
373
380
|
construct (callback) {
|
|
374
|
-
this._next = (
|
|
375
|
-
if (!this.push({
|
|
376
|
-
rows: batch.toArray(options),
|
|
377
|
-
count: batch.length,
|
|
378
|
-
sequence
|
|
379
|
-
})) {
|
|
381
|
+
this._next = (update) => {
|
|
382
|
+
if (!this.push(update)) {
|
|
380
383
|
this.push(null)
|
|
381
|
-
db.off('
|
|
384
|
+
db.off('update', this._next)
|
|
382
385
|
}
|
|
383
386
|
}
|
|
384
|
-
db.on('
|
|
387
|
+
db.on('update', this._next)
|
|
385
388
|
callback()
|
|
386
389
|
},
|
|
387
390
|
read () {},
|
|
388
391
|
destroy (err, callback) {
|
|
389
|
-
db.off('
|
|
392
|
+
db.off('update', this._next)
|
|
390
393
|
callback(err)
|
|
391
394
|
}
|
|
392
395
|
})
|
|
@@ -397,11 +400,23 @@ class RocksLevel extends AbstractLevel {
|
|
|
397
400
|
|
|
398
401
|
try {
|
|
399
402
|
if (since <= db.sequence) {
|
|
400
|
-
|
|
403
|
+
let first = true
|
|
404
|
+
for await (const update of _updates({
|
|
405
|
+
...options,
|
|
406
|
+
// HACK: https://github.com/facebook/rocksdb/issues/10476
|
|
407
|
+
since: Math.max(0, options.since - 2048)
|
|
408
|
+
})) {
|
|
401
409
|
if (ac.signal.aborted) {
|
|
402
410
|
throw new AbortError()
|
|
403
411
|
}
|
|
404
412
|
|
|
413
|
+
if (first) {
|
|
414
|
+
if (update.sequence > since) {
|
|
415
|
+
db.emit('warning', `Invalid updates sequence ${update.sequence} > ${options.since}.`)
|
|
416
|
+
}
|
|
417
|
+
first = false
|
|
418
|
+
}
|
|
419
|
+
|
|
405
420
|
if (update.sequence >= since) {
|
|
406
421
|
yield update
|
|
407
422
|
since = update.sequence + update.count
|
|
@@ -420,11 +435,13 @@ class RocksLevel extends AbstractLevel {
|
|
|
420
435
|
|
|
421
436
|
let first = true
|
|
422
437
|
for await (const update of buffer) {
|
|
438
|
+
if (ac.signal.aborted) {
|
|
439
|
+
throw new AbortError()
|
|
440
|
+
}
|
|
441
|
+
|
|
423
442
|
if (first) {
|
|
424
443
|
if (update.sequence > since) {
|
|
425
|
-
|
|
426
|
-
db.emit('warning', `Invalid batch sequence. Restarting.`)
|
|
427
|
-
break
|
|
444
|
+
db.emit('warning', `Invalid batch sequence ${update.sequence} > ${options.since}.`)
|
|
428
445
|
}
|
|
429
446
|
first = false
|
|
430
447
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|