rocksdb-native 3.10.0 → 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
@@ -359,7 +359,7 @@ rocksdb_native_init(
359
359
  db->exiting = false;
360
360
 
361
361
  db->options = (rocksdb_options_t) {
362
- 1,
362
+ 3,
363
363
  read_only,
364
364
  create_if_missing,
365
365
  create_missing_column_families,
@@ -370,7 +370,8 @@ rocksdb_native_init(
370
370
  avoid_unnecessary_blocking_io,
371
371
  skip_stats_update_on_db_open,
372
372
  use_direct_io_for_flush_and_compaction,
373
- max_file_opening_threads
373
+ max_file_opening_threads,
374
+ -1,
374
375
  };
375
376
 
376
377
  err = rocksdb_init(loop, &db->handle);
@@ -392,6 +393,7 @@ rocksdb_native_open(
392
393
  js_receiver_t self,
393
394
  char *path,
394
395
  js_array_t column_families_array,
396
+ int lock,
395
397
  js_receiver_t ctx,
396
398
  rocksdb_native_on_open_t on_open
397
399
  ) {
@@ -428,12 +430,20 @@ rocksdb_native_open(
428
430
  req->env = env;
429
431
  req->handle.data = req;
430
432
 
433
+ db->options.lock = lock;
434
+
431
435
  err = rocksdb_open(&db->handle, &req->handle, path, &db->options, column_families, handles, len, rocksdb_native__on_open);
432
436
 
433
437
  if (err < 0) {
434
438
  err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
435
439
  assert(err == 0);
436
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
+
437
447
  throw js_pending_exception;
438
448
  }
439
449
 
@@ -1295,7 +1305,7 @@ rocksdb_native_read(
1295
1305
  }
1296
1306
 
1297
1307
  rocksdb_read_options_t options = {
1298
- .version = 0,
1308
+ .version = 1,
1299
1309
  .async_io = async_io,
1300
1310
  .fill_cache = fill_cache
1301
1311
  };
@@ -1790,6 +1800,13 @@ rocksdb_native_approximate_size(
1790
1800
  return handle;
1791
1801
  }
1792
1802
 
1803
+ static void
1804
+ rocksdb_native__on_snapshot_teardown(void *data) {
1805
+ auto snapshot = reinterpret_cast<rocksdb_native_snapshot_t *>(data);
1806
+
1807
+ rocksdb_snapshot_destroy(&snapshot->handle);
1808
+ }
1809
+
1793
1810
  static js_arraybuffer_t
1794
1811
  rocksdb_native_snapshot_create(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_native_t, 1> db) {
1795
1812
  int err;
@@ -1809,12 +1826,20 @@ rocksdb_native_snapshot_create(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_n
1809
1826
  throw js_pending_exception;
1810
1827
  }
1811
1828
 
1829
+ err = js_add_teardown_callback(env, rocksdb_native__on_snapshot_teardown, snapshot);
1830
+ assert(err == 0);
1831
+
1812
1832
  return handle;
1813
1833
  }
1814
1834
 
1815
1835
  static void
1816
1836
  rocksdb_native_snapshot_destroy(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_native_snapshot_t, 1> snapshot) {
1837
+ int err;
1838
+
1817
1839
  rocksdb_snapshot_destroy(&snapshot->handle);
1840
+
1841
+ err = js_remove_teardown_callback(env, rocksdb_native__on_snapshot_teardown, snapshot);
1842
+ assert(err == 0);
1818
1843
  }
1819
1844
 
1820
1845
  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/state.js CHANGED
@@ -28,6 +28,7 @@ module.exports = class RocksDBState extends ReadyResource {
28
28
  skipStatsUpdateOnOpen = false,
29
29
  useDirectIOForFlushAndCompaction = false,
30
30
  maxFileOpeningThreads = 16,
31
+ lock = null,
31
32
  preopen = null
32
33
  } = opts
33
34
 
@@ -45,6 +46,7 @@ module.exports = class RocksDBState extends ReadyResource {
45
46
  this._updating = false
46
47
  this._updatingSignal = new SignalPromise()
47
48
  this._columnsFlushed = false
49
+ this._lock = lock
48
50
  this._preopen = preopen
49
51
  this._readBatches = []
50
52
  this._writeBatches = []
@@ -136,7 +138,9 @@ module.exports = class RocksDBState extends ReadyResource {
136
138
  }
137
139
 
138
140
  async _open() {
139
- 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()
140
144
 
141
145
  if (this._preopen) await this._preopen
142
146
 
@@ -149,11 +153,14 @@ module.exports = class RocksDBState extends ReadyResource {
149
153
 
150
154
  this._columnsFlushed = true
151
155
 
156
+ const lock = this._lock === null ? -1 : this._lock.transfer()
157
+
152
158
  req.handle = binding.open(
153
159
  this._handle,
154
160
  this,
155
161
  this.path,
156
162
  this.columnFamilies.map((c) => c._handle),
163
+ lock,
157
164
  req,
158
165
  onopen
159
166
  )
@@ -194,7 +201,11 @@ module.exports = class RocksDBState extends ReadyResource {
194
201
 
195
202
  req.handle = binding.close(this._handle, req, onclose)
196
203
 
197
- await promise
204
+ try {
205
+ await promise
206
+ } finally {
207
+ if (this._lock) await this._lock.close()
208
+ }
198
209
 
199
210
  function onclose(err) {
200
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.0",
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
  }