rocksdb-native 3.10.1 → 3.11.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/CMakeLists.txt CHANGED
@@ -9,7 +9,7 @@ project(rocksdb_native C CXX)
9
9
 
10
10
  bare_target(target)
11
11
 
12
- fetch_package("github:holepunchto/librocksdb#1fa9c8c")
12
+ fetch_package("github:holepunchto/librocksdb#8adf3cf")
13
13
  fetch_package("github:holepunchto/libjstl#098664c")
14
14
 
15
15
  add_bare_module(rocksdb_native_bare)
package/binding.cc CHANGED
@@ -8,12 +8,6 @@
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
-
17
11
  using rocksdb_native_on_open_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>>;
18
12
  using rocksdb_native_on_close_t = js_function_t<void, js_receiver_t>;
19
13
  using rocksdb_native_on_suspend_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>>;
@@ -41,8 +35,6 @@ struct rocksdb_native_t {
41
35
  rocksdb_t handle;
42
36
  rocksdb_options_t options;
43
37
 
44
- int lock;
45
-
46
38
  js_env_t *env;
47
39
  js_persistent_t<js_receiver_t> ctx;
48
40
 
@@ -276,18 +268,17 @@ rocksdb_native__on_close(rocksdb_close_t *handle, int status) {
276
268
 
277
269
  auto env = req->env;
278
270
 
279
- auto lock = db->lock;
280
271
  auto teardown = db->teardown;
281
272
 
282
273
  if (db->exiting) {
283
- db->ctx.reset();
284
-
285
274
  if (db->closing) {
286
275
  req->on_close.reset();
287
276
  req->ctx.reset();
288
277
  } else {
289
278
  free(req);
290
279
  }
280
+
281
+ db->ctx.reset();
291
282
  } else {
292
283
  js_handle_scope_t *scope;
293
284
  err = js_open_handle_scope(env, &scope);
@@ -301,24 +292,17 @@ rocksdb_native__on_close(rocksdb_close_t *handle, int status) {
301
292
  err = js_get_reference_value(env, req->on_close, cb);
302
293
  assert(err == 0);
303
294
 
304
- db->ctx.reset();
305
295
  req->on_close.reset();
306
296
  req->ctx.reset();
307
297
 
298
+ db->ctx.reset();
299
+
308
300
  js_call_function_with_checkpoint(env, cb, ctx);
309
301
 
310
302
  err = js_close_handle_scope(env, scope);
311
303
  assert(err == 0);
312
304
  }
313
305
 
314
- if (lock != -1) {
315
- #ifdef _WIN32
316
- _close(lock);
317
- #else
318
- close(lock);
319
- #endif
320
- }
321
-
322
306
  err = js_finish_deferred_teardown_callback(teardown);
323
307
  assert(err == 0);
324
308
  }
@@ -357,8 +341,7 @@ rocksdb_native_init(
357
341
  bool avoid_unnecessary_blocking_io,
358
342
  bool skip_stats_update_on_db_open,
359
343
  bool use_direct_io_for_flush_and_compaction,
360
- int32_t max_file_opening_threads,
361
- int32_t lock
344
+ int32_t max_file_opening_threads
362
345
  ) {
363
346
  int err;
364
347
 
@@ -373,12 +356,11 @@ rocksdb_native_init(
373
356
  assert(err == 0);
374
357
 
375
358
  db->env = env;
376
- db->lock = lock;
377
359
  db->closing = false;
378
360
  db->exiting = false;
379
361
 
380
362
  db->options = (rocksdb_options_t) {
381
- 1,
363
+ 3,
382
364
  read_only,
383
365
  create_if_missing,
384
366
  create_missing_column_families,
@@ -389,7 +371,8 @@ rocksdb_native_init(
389
371
  avoid_unnecessary_blocking_io,
390
372
  skip_stats_update_on_db_open,
391
373
  use_direct_io_for_flush_and_compaction,
392
- max_file_opening_threads
374
+ max_file_opening_threads,
375
+ -1,
393
376
  };
394
377
 
395
378
  err = rocksdb_init(loop, &db->handle);
@@ -411,6 +394,7 @@ rocksdb_native_open(
411
394
  js_receiver_t self,
412
395
  char *path,
413
396
  js_array_t column_families_array,
397
+ int lock,
414
398
  js_receiver_t ctx,
415
399
  rocksdb_native_on_open_t on_open
416
400
  ) {
@@ -447,12 +431,20 @@ rocksdb_native_open(
447
431
  req->env = env;
448
432
  req->handle.data = req;
449
433
 
434
+ db->options.lock = lock;
435
+
450
436
  err = rocksdb_open(&db->handle, &req->handle, path, &db->options, column_families, handles, len, rocksdb_native__on_open);
451
437
 
452
438
  if (err < 0) {
453
439
  err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
454
440
  assert(err == 0);
455
441
 
442
+ if (lock >= 0) {
443
+ uv_fs_t fs;
444
+ err = uv_fs_close(NULL, &fs, lock, NULL);
445
+ assert(err == 0);
446
+ }
447
+
456
448
  throw js_pending_exception;
457
449
  }
458
450
 
@@ -1314,7 +1306,7 @@ rocksdb_native_read(
1314
1306
  }
1315
1307
 
1316
1308
  rocksdb_read_options_t options = {
1317
- .version = 0,
1309
+ .version = 1,
1318
1310
  .async_io = async_io,
1319
1311
  .fill_cache = fill_cache
1320
1312
  };
package/lib/state.js CHANGED
@@ -28,8 +28,7 @@ module.exports = class RocksDBState extends ReadyResource {
28
28
  skipStatsUpdateOnOpen = false,
29
29
  useDirectIOForFlushAndCompaction = false,
30
30
  maxFileOpeningThreads = 16,
31
- lock = -1,
32
- preopen = null
31
+ lock = null
33
32
  } = opts
34
33
 
35
34
  this.path = path
@@ -46,7 +45,7 @@ module.exports = class RocksDBState extends ReadyResource {
46
45
  this._updating = false
47
46
  this._updatingSignal = new SignalPromise()
48
47
  this._columnsFlushed = false
49
- this._preopen = preopen
48
+ this._lock = lock
50
49
  this._readBatches = []
51
50
  this._writeBatches = []
52
51
 
@@ -67,8 +66,7 @@ module.exports = class RocksDBState extends ReadyResource {
67
66
  avoidUnnecessaryBlockingIO,
68
67
  skipStatsUpdateOnOpen,
69
68
  useDirectIOForFlushAndCompaction,
70
- maxFileOpeningThreads,
71
- lock
69
+ maxFileOpeningThreads
72
70
  )
73
71
  }
74
72
 
@@ -138,9 +136,9 @@ module.exports = class RocksDBState extends ReadyResource {
138
136
  }
139
137
 
140
138
  async _open() {
141
- await Promise.resolve() // allow column families to populate if ondemand
139
+ await Promise.resolve() // Allow column families to populate if on-demand
142
140
 
143
- if (this._preopen) await this._preopen
141
+ if (this._lock) await this._lock.ready()
144
142
 
145
143
  const req = { resolve: null, reject: null, handle: null }
146
144
 
@@ -151,11 +149,14 @@ module.exports = class RocksDBState extends ReadyResource {
151
149
 
152
150
  this._columnsFlushed = true
153
151
 
152
+ const lock = this._lock === null ? -1 : this._lock.transfer()
153
+
154
154
  req.handle = binding.open(
155
155
  this._handle,
156
156
  this,
157
157
  this.path,
158
158
  this.columnFamilies.map((c) => c._handle),
159
+ lock,
159
160
  req,
160
161
  onopen
161
162
  )
@@ -196,7 +197,11 @@ module.exports = class RocksDBState extends ReadyResource {
196
197
 
197
198
  req.handle = binding.close(this._handle, req, onclose)
198
199
 
199
- await promise
200
+ try {
201
+ await promise
202
+ } finally {
203
+ if (this._lock) await this._lock.close()
204
+ }
200
205
 
201
206
  function onclose(err) {
202
207
  if (err) req.reject(new Error(err))
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.10.1",
3
+ "version": "3.11.1",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",
7
7
  "./package": "./package.json"
8
8
  },
9
+ "imports": {
10
+ "fs": "bare-fs",
11
+ "default": "fs"
12
+ },
9
13
  "files": [
10
14
  "index.js",
11
15
  "binding.cc",
@@ -47,10 +51,12 @@
47
51
  },
48
52
  "devDependencies": {
49
53
  "bare-compat-napi": "^1.3.0",
54
+ "bare-fs": "^4.5.0",
50
55
  "brittle": "^3.5.0",
51
56
  "cmake-bare": "^1.1.14",
52
57
  "cmake-fetch": "^1.0.1",
53
58
  "cmake-napi": "^1.0.6",
59
+ "fd-lock": "^2.0.0",
54
60
  "prettier": "^3.6.2",
55
61
  "prettier-config-holepunch": "^2.0.0"
56
62
  }