rocksdb-native 3.10.1 → 3.11.0

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#65ec235")
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,7 +268,6 @@ 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) {
@@ -311,14 +302,6 @@ rocksdb_native__on_close(rocksdb_close_t *handle, int status) {
311
302
  assert(err == 0);
312
303
  }
313
304
 
314
- if (lock != -1) {
315
- #ifdef _WIN32
316
- _close(lock);
317
- #else
318
- close(lock);
319
- #endif
320
- }
321
-
322
305
  err = js_finish_deferred_teardown_callback(teardown);
323
306
  assert(err == 0);
324
307
  }
@@ -357,8 +340,7 @@ rocksdb_native_init(
357
340
  bool avoid_unnecessary_blocking_io,
358
341
  bool skip_stats_update_on_db_open,
359
342
  bool use_direct_io_for_flush_and_compaction,
360
- int32_t max_file_opening_threads,
361
- int32_t lock
343
+ int32_t max_file_opening_threads
362
344
  ) {
363
345
  int err;
364
346
 
@@ -373,12 +355,11 @@ rocksdb_native_init(
373
355
  assert(err == 0);
374
356
 
375
357
  db->env = env;
376
- db->lock = lock;
377
358
  db->closing = false;
378
359
  db->exiting = false;
379
360
 
380
361
  db->options = (rocksdb_options_t) {
381
- 1,
362
+ 3,
382
363
  read_only,
383
364
  create_if_missing,
384
365
  create_missing_column_families,
@@ -389,7 +370,8 @@ rocksdb_native_init(
389
370
  avoid_unnecessary_blocking_io,
390
371
  skip_stats_update_on_db_open,
391
372
  use_direct_io_for_flush_and_compaction,
392
- max_file_opening_threads
373
+ max_file_opening_threads,
374
+ -1,
393
375
  };
394
376
 
395
377
  err = rocksdb_init(loop, &db->handle);
@@ -411,6 +393,7 @@ rocksdb_native_open(
411
393
  js_receiver_t self,
412
394
  char *path,
413
395
  js_array_t column_families_array,
396
+ int lock,
414
397
  js_receiver_t ctx,
415
398
  rocksdb_native_on_open_t on_open
416
399
  ) {
@@ -447,12 +430,20 @@ rocksdb_native_open(
447
430
  req->env = env;
448
431
  req->handle.data = req;
449
432
 
433
+ db->options.lock = lock;
434
+
450
435
  err = rocksdb_open(&db->handle, &req->handle, path, &db->options, column_families, handles, len, rocksdb_native__on_open);
451
436
 
452
437
  if (err < 0) {
453
438
  err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
454
439
  assert(err == 0);
455
440
 
441
+ if (lock >= 0) {
442
+ uv_fs_t fs;
443
+ err = uv_fs_close(NULL, &fs, lock, NULL);
444
+ assert(err == 0);
445
+ }
446
+
456
447
  throw js_pending_exception;
457
448
  }
458
449
 
@@ -1314,7 +1305,7 @@ rocksdb_native_read(
1314
1305
  }
1315
1306
 
1316
1307
  rocksdb_read_options_t options = {
1317
- .version = 0,
1308
+ .version = 1,
1318
1309
  .async_io = async_io,
1319
1310
  .fill_cache = fill_cache
1320
1311
  };
package/lib/state.js CHANGED
@@ -28,7 +28,7 @@ module.exports = class RocksDBState extends ReadyResource {
28
28
  skipStatsUpdateOnOpen = false,
29
29
  useDirectIOForFlushAndCompaction = false,
30
30
  maxFileOpeningThreads = 16,
31
- lock = -1,
31
+ lock = null,
32
32
  preopen = null
33
33
  } = opts
34
34
 
@@ -46,6 +46,7 @@ module.exports = class RocksDBState extends ReadyResource {
46
46
  this._updating = false
47
47
  this._updatingSignal = new SignalPromise()
48
48
  this._columnsFlushed = false
49
+ this._lock = lock
49
50
  this._preopen = preopen
50
51
  this._readBatches = []
51
52
  this._writeBatches = []
@@ -67,8 +68,7 @@ module.exports = class RocksDBState extends ReadyResource {
67
68
  avoidUnnecessaryBlockingIO,
68
69
  skipStatsUpdateOnOpen,
69
70
  useDirectIOForFlushAndCompaction,
70
- maxFileOpeningThreads,
71
- lock
71
+ maxFileOpeningThreads
72
72
  )
73
73
  }
74
74
 
@@ -138,7 +138,9 @@ module.exports = class RocksDBState extends ReadyResource {
138
138
  }
139
139
 
140
140
  async _open() {
141
- await Promise.resolve() // allow column families to populate if ondemand
141
+ await Promise.resolve() // Allow column families to populate if on-demand
142
+
143
+ if (this._lock) await this._lock.ready()
142
144
 
143
145
  if (this._preopen) await this._preopen
144
146
 
@@ -151,11 +153,14 @@ module.exports = class RocksDBState extends ReadyResource {
151
153
 
152
154
  this._columnsFlushed = true
153
155
 
156
+ const lock = this._lock === null ? -1 : this._lock.transfer()
157
+
154
158
  req.handle = binding.open(
155
159
  this._handle,
156
160
  this,
157
161
  this.path,
158
162
  this.columnFamilies.map((c) => c._handle),
163
+ lock,
159
164
  req,
160
165
  onopen
161
166
  )
@@ -196,7 +201,11 @@ module.exports = class RocksDBState extends ReadyResource {
196
201
 
197
202
  req.handle = binding.close(this._handle, req, onclose)
198
203
 
199
- await promise
204
+ try {
205
+ await promise
206
+ } finally {
207
+ if (this._lock) await this._lock.close()
208
+ }
200
209
 
201
210
  function onclose(err) {
202
211
  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.0",
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
  }