@nxtedition/rocksdb 7.0.61 → 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
@@ -67,7 +67,7 @@ class RocksLevel extends AbstractLevel {
67
67
  this[kContext] = binding.db_init()
68
68
  this[kColumns] = {}
69
69
 
70
- // .updates(...) uses 'write' listener.
70
+ // .updates(...) uses 'update' listener.
71
71
  this.setMaxListeners(100)
72
72
  }
73
73
 
@@ -179,7 +179,11 @@ class RocksLevel extends AbstractLevel {
179
179
  try {
180
180
  const seq = this.sequence
181
181
  binding.batch_write(this[kContext], context, options)
182
- this.emit('write', batch, seq + 1)
182
+ this.emit('update', {
183
+ rows: batch.toArray(),
184
+ count: batch.length,
185
+ sequence: seq + 1
186
+ })
183
187
  process.nextTick(callback, null)
184
188
  } catch (err) {
185
189
  process.nextTick(callback, err)
@@ -345,16 +349,14 @@ class RocksLevel extends AbstractLevel {
345
349
  const db = this
346
350
 
347
351
  // HACK: https://github.com/facebook/rocksdb/issues/10476
348
- async function* _updates (options) {
352
+ async function * _updates (options) {
349
353
  let first = true
350
- for await (const update of db[kUpdates](options)) {
354
+ for await (const update of db[kUpdates]({ ...options, since: Math.max(0, options.since - 1024) })) {
351
355
  if (first) {
352
356
  if (update.sequence > options.since) {
353
357
  // HACK
354
358
  db.emit('warning', `Invalid update sequence ${update.sequence} > ${options.since}. Starting from 0.`)
355
- for await (const update of db[kUpdates]({ ...options, since: 0 })) {
356
- yield update
357
- }
359
+ first = null
358
360
  break
359
361
  } else {
360
362
  first = false
@@ -362,6 +364,12 @@ class RocksLevel extends AbstractLevel {
362
364
  }
363
365
  yield update
364
366
  }
367
+
368
+ if (first === null) {
369
+ for await (const update of db[kUpdates]({ ...options, since: 0 })) {
370
+ yield update
371
+ }
372
+ }
365
373
  }
366
374
 
367
375
  try {
@@ -374,22 +382,18 @@ class RocksLevel extends AbstractLevel {
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
  })
@@ -427,7 +431,7 @@ class RocksLevel extends AbstractLevel {
427
431
  if (first) {
428
432
  if (update.sequence > since) {
429
433
  // HACK
430
- db.emit('warning', `Invalid batch sequence. Restarting.`)
434
+ db.emit('warning', `Invalid batch sequence ${update.sequence} > ${options.since}. Starting from ${since}.`)
431
435
  break
432
436
  }
433
437
  first = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "7.0.61",
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