@nxtedition/rocksdb 7.0.59 → 7.0.62

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 CHANGED
@@ -407,8 +407,10 @@ struct BatchIterator : public rocksdb::WriteBatch::Handler {
407
407
  valueAsBuffer_(valueAsBuffer) {}
408
408
 
409
409
  napi_status Iterate(napi_env env, const rocksdb::WriteBatch& batch, napi_value* result) {
410
+ cache_.clear();
410
411
  cache_.reserve(batch.Count());
411
- batch.Iterate(this); // TODO (fix): Error?
412
+
413
+ batch.Iterate(this); // TODO (fix): Handle error?
412
414
 
413
415
  napi_value putStr;
414
416
  NAPI_STATUS_RETURN(napi_create_string_utf8(env, "put", NAPI_AUTO_LENGTH, &putStr));
@@ -1156,9 +1158,8 @@ NAPI_METHOD(db_open) {
1156
1158
  "leveldown.open", env, callback, database, false,
1157
1159
  [=](auto& handles, auto& database) -> rocksdb::Status {
1158
1160
  rocksdb::DB* db = nullptr;
1159
- const auto status = descriptors.empty()
1160
- ? rocksdb::DB::Open(dbOptions, location, &db)
1161
- : rocksdb::DB::Open(dbOptions, location, descriptors, &handles, &db);
1161
+ const auto status = descriptors.empty() ? rocksdb::DB::Open(dbOptions, location, &db)
1162
+ : rocksdb::DB::Open(dbOptions, location, descriptors, &handles, &db);
1162
1163
  database.db_.reset(db);
1163
1164
  return status;
1164
1165
  },
@@ -1378,7 +1379,7 @@ NAPI_METHOD(db_get_many) {
1378
1379
  keys2.emplace_back(key);
1379
1380
  }
1380
1381
  std::vector<rocksdb::Status> statuses;
1381
-
1382
+
1382
1383
  statuses.resize(keys2.size());
1383
1384
  values.resize(keys2.size());
1384
1385
 
package/index.js CHANGED
@@ -11,6 +11,7 @@ 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')
14
15
 
15
16
  const kContext = Symbol('context')
16
17
  const kColumns = Symbol('columns')
@@ -66,7 +67,7 @@ class RocksLevel extends AbstractLevel {
66
67
  this[kContext] = binding.db_init()
67
68
  this[kColumns] = {}
68
69
 
69
- // .updates(...) uses 'write' listener.
70
+ // .updates(...) uses 'update' listener.
70
71
  this.setMaxListeners(100)
71
72
  }
72
73
 
@@ -178,7 +179,11 @@ class RocksLevel extends AbstractLevel {
178
179
  try {
179
180
  const seq = this.sequence
180
181
  binding.batch_write(this[kContext], context, options)
181
- this.emit('write', batch, seq + 1)
182
+ this.emit('update', {
183
+ rows: batch.toArray(),
184
+ count: batch.length,
185
+ sequence: seq + 1
186
+ })
182
187
  process.nextTick(callback, null)
183
188
  } catch (err) {
184
189
  process.nextTick(callback, err)
@@ -344,11 +349,12 @@ class RocksLevel extends AbstractLevel {
344
349
  const db = this
345
350
 
346
351
  // HACK: https://github.com/facebook/rocksdb/issues/10476
347
- async function* _updates (options) {
352
+ async function * _updates (options) {
348
353
  let first = true
349
- for await (const update of db[kUpdates](options)) {
354
+ for await (const update of db[kUpdates]({ ...options, since: Math.max(0, options.since - 1024) })) {
350
355
  if (first) {
351
356
  if (update.sequence > options.since) {
357
+ // HACK
352
358
  db.emit('warning', `Invalid update sequence ${update.sequence} > ${options.since}. Starting from 0.`)
353
359
  first = null
354
360
  break
@@ -368,28 +374,26 @@ class RocksLevel extends AbstractLevel {
368
374
 
369
375
  try {
370
376
  let since = options.since
371
- while (true) {
377
+ for (let retryCount = 0; true; retryCount++) {
378
+ assert(retryCount < 8)
379
+
372
380
  const buffer = new Readable({
373
381
  signal: ac.signal,
374
382
  objectMode: true,
375
383
  readableHighWaterMark: 1024,
376
384
  construct (callback) {
377
- this._next = (batch, sequence) => {
378
- if (!this.push({
379
- rows: batch.toArray(options),
380
- count: batch.length,
381
- sequence
382
- })) {
385
+ this._next = (update) => {
386
+ if (!this.push(update)) {
383
387
  this.push(null)
384
- db.off('write', this._next)
388
+ db.off('update', this._next)
385
389
  }
386
390
  }
387
- db.on('write', this._next)
391
+ db.on('update', this._next)
388
392
  callback()
389
393
  },
390
394
  read () {},
391
395
  destroy (err, callback) {
392
- db.off('write', this._next)
396
+ db.off('update', this._next)
393
397
  callback(err)
394
398
  }
395
399
  })
@@ -408,6 +412,7 @@ class RocksLevel extends AbstractLevel {
408
412
  if (update.sequence >= since) {
409
413
  yield update
410
414
  since = update.sequence + update.count
415
+ retryCount = 0
411
416
  }
412
417
  }
413
418
  }
@@ -421,10 +426,20 @@ class RocksLevel extends AbstractLevel {
421
426
  return
422
427
  }
423
428
 
429
+ let first = true
424
430
  for await (const update of buffer) {
431
+ if (first) {
432
+ if (update.sequence > since) {
433
+ // HACK
434
+ db.emit('warning', `Invalid batch sequence ${update.sequence} > ${options.since}. Starting from ${since}.`)
435
+ break
436
+ }
437
+ first = false
438
+ }
425
439
  if (update.sequence >= since) {
426
440
  yield update
427
441
  since = update.sequence + update.count
442
+ retryCount = 0
428
443
  }
429
444
  }
430
445
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "7.0.59",
3
+ "version": "7.0.62",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
Binary file