rocksdb-native 3.9.3 → 3.10.1

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
@@ -8,6 +8,12 @@
8
8
  #include <utf.h>
9
9
  #include <uv.h>
10
10
 
11
+ #ifdef _WIN32
12
+ #include <io.h>
13
+ #else
14
+ #include <unistd.h>
15
+ #endif
16
+
11
17
  using rocksdb_native_on_open_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>>;
12
18
  using rocksdb_native_on_close_t = js_function_t<void, js_receiver_t>;
13
19
  using rocksdb_native_on_suspend_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>>;
@@ -35,6 +41,8 @@ struct rocksdb_native_t {
35
41
  rocksdb_t handle;
36
42
  rocksdb_options_t options;
37
43
 
44
+ int lock;
45
+
38
46
  js_env_t *env;
39
47
  js_persistent_t<js_receiver_t> ctx;
40
48
 
@@ -268,6 +276,7 @@ rocksdb_native__on_close(rocksdb_close_t *handle, int status) {
268
276
 
269
277
  auto env = req->env;
270
278
 
279
+ auto lock = db->lock;
271
280
  auto teardown = db->teardown;
272
281
 
273
282
  if (db->exiting) {
@@ -302,6 +311,14 @@ rocksdb_native__on_close(rocksdb_close_t *handle, int status) {
302
311
  assert(err == 0);
303
312
  }
304
313
 
314
+ if (lock != -1) {
315
+ #ifdef _WIN32
316
+ _close(lock);
317
+ #else
318
+ close(lock);
319
+ #endif
320
+ }
321
+
305
322
  err = js_finish_deferred_teardown_callback(teardown);
306
323
  assert(err == 0);
307
324
  }
@@ -340,7 +357,8 @@ rocksdb_native_init(
340
357
  bool avoid_unnecessary_blocking_io,
341
358
  bool skip_stats_update_on_db_open,
342
359
  bool use_direct_io_for_flush_and_compaction,
343
- int32_t max_file_opening_threads
360
+ int32_t max_file_opening_threads,
361
+ int32_t lock
344
362
  ) {
345
363
  int err;
346
364
 
@@ -355,6 +373,7 @@ rocksdb_native_init(
355
373
  assert(err == 0);
356
374
 
357
375
  db->env = env;
376
+ db->lock = lock;
358
377
  db->closing = false;
359
378
  db->exiting = false;
360
379
 
@@ -1790,6 +1809,13 @@ rocksdb_native_approximate_size(
1790
1809
  return handle;
1791
1810
  }
1792
1811
 
1812
+ static void
1813
+ rocksdb_native__on_snapshot_teardown(void *data) {
1814
+ auto snapshot = reinterpret_cast<rocksdb_native_snapshot_t *>(data);
1815
+
1816
+ rocksdb_snapshot_destroy(&snapshot->handle);
1817
+ }
1818
+
1793
1819
  static js_arraybuffer_t
1794
1820
  rocksdb_native_snapshot_create(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_native_t, 1> db) {
1795
1821
  int err;
@@ -1809,12 +1835,20 @@ rocksdb_native_snapshot_create(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_n
1809
1835
  throw js_pending_exception;
1810
1836
  }
1811
1837
 
1838
+ err = js_add_teardown_callback(env, rocksdb_native__on_snapshot_teardown, snapshot);
1839
+ assert(err == 0);
1840
+
1812
1841
  return handle;
1813
1842
  }
1814
1843
 
1815
1844
  static void
1816
1845
  rocksdb_native_snapshot_destroy(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_native_snapshot_t, 1> snapshot) {
1846
+ int err;
1847
+
1817
1848
  rocksdb_snapshot_destroy(&snapshot->handle);
1849
+
1850
+ err = js_remove_teardown_callback(env, rocksdb_native__on_snapshot_teardown, snapshot);
1851
+ assert(err == 0);
1818
1852
  }
1819
1853
 
1820
1854
  static js_value_t *
package/index.js CHANGED
@@ -79,6 +79,8 @@ class RocksDB {
79
79
  }
80
80
 
81
81
  async close({ force } = {}) {
82
+ if (!this._state.opened) await this._state.ready()
83
+
82
84
  if (this._index !== -1) this._state.removeSession(this)
83
85
 
84
86
  if (force) {
package/lib/batch.js CHANGED
@@ -214,18 +214,14 @@ exports.ReadBatch = class RocksDBReadBatch extends RocksDBBatch {
214
214
  let applied = true
215
215
 
216
216
  for (let i = 0, n = this._promises.length; i < n; i++) {
217
- const promise = this._promises[i]
218
- if (promise === null) continue
219
-
220
217
  const err = errs[i]
218
+ if (err) applied = false
221
219
 
222
- if (err) {
223
- applied = false
220
+ const promise = this._promises[i]
221
+ if (promise === null) continue
224
222
 
225
- promise.reject(new Error(err))
226
- } else {
227
- promise.resolve(values[i] ? this._decodeValue(Buffer.from(values[i])) : null)
228
- }
223
+ if (err) promise.reject(new Error(err))
224
+ else promise.resolve(values[i] ? this._decodeValue(Buffer.from(values[i])) : null)
229
225
  }
230
226
 
231
227
  this._onfinished(applied ? null : new Error('Batch was not applied'))
@@ -274,19 +270,14 @@ exports.WriteBatch = class RocksDBWriteBatch extends RocksDBBatch {
274
270
  }
275
271
 
276
272
  _onwrite(err) {
277
- let applied = true
273
+ const applied = !err
278
274
 
279
275
  for (let i = 0, n = this._promises.length; i < n; i++) {
280
276
  const promise = this._promises[i]
281
277
  if (promise === null) continue
282
278
 
283
- if (err) {
284
- applied = false
285
-
286
- promise.reject(new Error(err))
287
- } else {
288
- promise.resolve()
289
- }
279
+ if (err) promise.reject(new Error(err))
280
+ else promise.resolve()
290
281
  }
291
282
 
292
283
  this._onfinished(applied ? null : new Error('Batch was not applied'))
package/lib/state.js CHANGED
@@ -27,7 +27,9 @@ module.exports = class RocksDBState extends ReadyResource {
27
27
  avoidUnnecessaryBlockingIO = false,
28
28
  skipStatsUpdateOnOpen = false,
29
29
  useDirectIOForFlushAndCompaction = false,
30
- maxFileOpeningThreads = 16
30
+ maxFileOpeningThreads = 16,
31
+ lock = -1,
32
+ preopen = null
31
33
  } = opts
32
34
 
33
35
  this.path = path
@@ -44,6 +46,7 @@ module.exports = class RocksDBState extends ReadyResource {
44
46
  this._updating = false
45
47
  this._updatingSignal = new SignalPromise()
46
48
  this._columnsFlushed = false
49
+ this._preopen = preopen
47
50
  this._readBatches = []
48
51
  this._writeBatches = []
49
52
 
@@ -64,7 +67,8 @@ module.exports = class RocksDBState extends ReadyResource {
64
67
  avoidUnnecessaryBlockingIO,
65
68
  skipStatsUpdateOnOpen,
66
69
  useDirectIOForFlushAndCompaction,
67
- maxFileOpeningThreads
70
+ maxFileOpeningThreads,
71
+ lock
68
72
  )
69
73
  }
70
74
 
@@ -136,6 +140,8 @@ module.exports = class RocksDBState extends ReadyResource {
136
140
  async _open() {
137
141
  await Promise.resolve() // allow column families to populate if ondemand
138
142
 
143
+ if (this._preopen) await this._preopen
144
+
139
145
  const req = { resolve: null, reject: null, handle: null }
140
146
 
141
147
  const promise = new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.9.3",
3
+ "version": "3.10.1",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",