rocksdb-native 3.8.0 → 3.9.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#ac350df")
12
+ fetch_package("github:holepunchto/librocksdb#bf9c031")
13
13
  fetch_package("github:holepunchto/libjstl#34a7894")
14
14
 
15
15
  add_bare_module(rocksdb_native_bare)
package/binding.cc CHANGED
@@ -24,6 +24,7 @@ using cb_on_iterator_read_t = js_function_t<
24
24
  std::vector<js_arraybuffer_t>,
25
25
  std::vector<js_arraybuffer_t>>;
26
26
  using cb_on_compact_range_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>>;
27
+ using cb_on_approximate_size_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>, uint64_t>;
27
28
  }; // namespace
28
29
 
29
30
  struct rocksdb_native_column_family_t {
@@ -147,6 +148,14 @@ struct rocksdb_native_compact_range_t {
147
148
  js_persistent_t<cb_on_compact_range_t> on_compact_range;
148
149
  };
149
150
 
151
+ struct rocksdb_native_approximate_size_t {
152
+ rocksdb_approximate_size_t handle;
153
+
154
+ js_env_t *env;
155
+ js_persistent_t<js_receiver_t> ctx;
156
+ js_persistent_t<cb_on_approximate_size_t> on_approximate_size;
157
+ };
158
+
150
159
  static void
151
160
  rocksdb_native__on_free(js_env_t *env, char *data) {
152
161
  free(data);
@@ -319,7 +328,11 @@ rocksdb_native_init(
319
328
  int32_t max_background_jobs,
320
329
  uint64_t bytes_per_sync,
321
330
  int32_t max_open_files,
322
- bool use_direct_reads
331
+ bool use_direct_reads,
332
+ bool avoid_unnecessary_blocking_io,
333
+ bool skip_stats_update_on_db_open,
334
+ bool use_direct_io_for_flush_and_compaction,
335
+ int32_t max_file_opening_threads
323
336
  ) {
324
337
  int err;
325
338
 
@@ -345,7 +358,11 @@ rocksdb_native_init(
345
358
  max_background_jobs,
346
359
  bytes_per_sync,
347
360
  max_open_files,
348
- use_direct_reads
361
+ use_direct_reads,
362
+ avoid_unnecessary_blocking_io,
363
+ skip_stats_update_on_db_open,
364
+ use_direct_io_for_flush_and_compaction,
365
+ max_file_opening_threads
349
366
  };
350
367
 
351
368
  err = rocksdb_init(loop, &db->handle);
@@ -634,7 +651,10 @@ rocksdb_native_column_family_init(
634
651
  int32_t bloom_before_level,
635
652
  uint32_t top_level_index_pinning_tier,
636
653
  uint32_t partition_pinning_tier,
637
- uint32_t unpartitioned_pinning_tier
654
+ uint32_t unpartitioned_pinning_tier,
655
+ bool optimize_filters_for_hits,
656
+ int32_t num_levels,
657
+ int32_t max_write_buffer_number
638
658
  ) {
639
659
  int err;
640
660
 
@@ -689,6 +709,9 @@ rocksdb_native_column_family_init(
689
709
  rocksdb_pinning_tier_t(top_level_index_pinning_tier),
690
710
  rocksdb_pinning_tier_t(partition_pinning_tier),
691
711
  rocksdb_pinning_tier_t(unpartitioned_pinning_tier),
712
+ optimize_filters_for_hits,
713
+ num_levels,
714
+ max_write_buffer_number
692
715
  }
693
716
  };
694
717
 
@@ -1178,6 +1201,8 @@ rocksdb_native_read(
1178
1201
  js_arraybuffer_span_of_t<rocksdb_native_read_batch_t, 1> req,
1179
1202
  js_array_t operations,
1180
1203
  std::optional<js_arraybuffer_t> snapshot,
1204
+ bool async_io,
1205
+ bool fill_cache,
1181
1206
  js_receiver_t ctx,
1182
1207
  cb_on_read_t on_read
1183
1208
  ) {
@@ -1233,6 +1258,8 @@ rocksdb_native_read(
1233
1258
 
1234
1259
  rocksdb_read_options_t options = {
1235
1260
  .version = 0,
1261
+ .async_io = async_io,
1262
+ .fill_cache = fill_cache
1236
1263
  };
1237
1264
 
1238
1265
  if (snapshot) {
@@ -1606,7 +1633,7 @@ rocksdb_native_compact_range(
1606
1633
  assert(err == 0);
1607
1634
 
1608
1635
  rocksdb_slice_t end_slice;
1609
- err = js_get_typedarray_info(env, start, end_slice.data, end_slice.len);
1636
+ err = js_get_typedarray_info(env, end, end_slice.data, end_slice.len);
1610
1637
  assert(err == 0);
1611
1638
 
1612
1639
  err = rocksdb_compact_range(&db->handle, &req->handle, column_family->handle, start_slice, end_slice, &options, rocksdb_native__on_compact_range);
@@ -1615,6 +1642,102 @@ rocksdb_native_compact_range(
1615
1642
  return handle;
1616
1643
  }
1617
1644
 
1645
+ static void
1646
+ rocksdb_native__on_approximate_size(rocksdb_approximate_size_t *handle, int status) {
1647
+ int err;
1648
+
1649
+ assert(status == 0);
1650
+
1651
+ rocksdb_native_approximate_size_t *req = (rocksdb_native_approximate_size_t *) handle->data;
1652
+
1653
+ rocksdb_native_t *db = (rocksdb_native_t *) req->handle.req.db;
1654
+
1655
+ js_env_t *env = req->env;
1656
+
1657
+ if (db->exiting) {
1658
+ req->on_approximate_size.reset();
1659
+ req->ctx.reset();
1660
+ } else {
1661
+ js_handle_scope_t *scope;
1662
+ err = js_open_handle_scope(env, &scope);
1663
+ assert(err == 0);
1664
+
1665
+ std::optional<js_string_t> error;
1666
+
1667
+ if (req->handle.error) {
1668
+ err = js_create_string(env, req->handle.error, error.emplace());
1669
+ assert(err == 0);
1670
+ }
1671
+
1672
+ js_receiver_t ctx;
1673
+ err = js_get_reference_value(env, req->ctx, ctx);
1674
+ assert(err == 0);
1675
+
1676
+ cb_on_approximate_size_t cb;
1677
+ err = js_get_reference_value(env, req->on_approximate_size, cb);
1678
+ assert(err == 0);
1679
+
1680
+ req->on_approximate_size.reset();
1681
+ req->ctx.reset();
1682
+
1683
+ js_call_function_with_checkpoint(env, cb, ctx, error, req->handle.result);
1684
+
1685
+ err = js_close_handle_scope(env, scope);
1686
+ assert(err == 0);
1687
+ }
1688
+ }
1689
+
1690
+ static js_arraybuffer_t
1691
+ rocksdb_native_approximate_size(
1692
+ js_env_t *env,
1693
+ js_arraybuffer_span_of_t<rocksdb_native_t, 1> db,
1694
+ js_arraybuffer_span_of_t<rocksdb_native_column_family_t, 1> column_family,
1695
+ js_typedarray_t<> start,
1696
+ js_typedarray_t<> end,
1697
+ bool include_memtables,
1698
+ bool include_files,
1699
+ double error_margin,
1700
+ js_receiver_t ctx,
1701
+ cb_on_approximate_size_t on_approximate_size
1702
+ ) {
1703
+ int err;
1704
+
1705
+ js_arraybuffer_t handle;
1706
+
1707
+ rocksdb_native_approximate_size_t *req;
1708
+ err = js_create_arraybuffer(env, req, handle);
1709
+ assert(err == 0);
1710
+
1711
+ req->env = env;
1712
+ req->handle.data = (void *) req;
1713
+
1714
+ err = js_create_reference(env, ctx, req->ctx);
1715
+ assert(err == 0);
1716
+
1717
+ err = js_create_reference(env, on_approximate_size, req->on_approximate_size);
1718
+ assert(err == 0);
1719
+
1720
+ rocksdb_approximate_size_options_t options = {
1721
+ .version = 0,
1722
+ .include_memtables = include_memtables,
1723
+ .include_files = include_files,
1724
+ .files_size_error_margin = error_margin,
1725
+ };
1726
+
1727
+ rocksdb_slice_t start_slice;
1728
+ err = js_get_typedarray_info(env, start, start_slice.data, start_slice.len);
1729
+ assert(err == 0);
1730
+
1731
+ rocksdb_slice_t end_slice;
1732
+ err = js_get_typedarray_info(env, end, end_slice.data, end_slice.len);
1733
+ assert(err == 0);
1734
+
1735
+ err = rocksdb_approximate_size(&db->handle, &req->handle, column_family->handle, start_slice, end_slice, &options, rocksdb_native__on_approximate_size);
1736
+ assert(err == 0);
1737
+
1738
+ return handle;
1739
+ }
1740
+
1618
1741
  static js_value_t *
1619
1742
  rocksdb_native_exports(js_env_t *env, js_value_t *exports) {
1620
1743
  int err;
@@ -1652,6 +1775,7 @@ rocksdb_native_exports(js_env_t *env, js_value_t *exports) {
1652
1775
  V("snapshotDestroy", rocksdb_native_snapshot_destroy)
1653
1776
 
1654
1777
  V("compactRange", rocksdb_native_compact_range)
1778
+ V("approximateSize", rocksdb_native_approximate_size)
1655
1779
  #undef V
1656
1780
 
1657
1781
  #define V(name, n) \
package/index.js CHANGED
@@ -189,6 +189,10 @@ class RocksDB {
189
189
  await this._state.compactRange(this, start, end, opts)
190
190
  }
191
191
 
192
+ async approximateSize(start, end, opts = {}) {
193
+ return this._state.approximateSize(this, start, end, opts)
194
+ }
195
+
192
196
  _ref() {
193
197
  if (this._snapshot) this._snapshot.ref()
194
198
  this._state.handles.inc()
package/lib/batch.js CHANGED
@@ -168,6 +168,15 @@ class RocksDBBatch {
168
168
  }
169
169
 
170
170
  exports.ReadBatch = class RocksDBReadBatch extends RocksDBBatch {
171
+ constructor(db, opts = {}) {
172
+ super(db, opts)
173
+
174
+ const { asyncIO = false, fillCache = true } = opts
175
+
176
+ this._asyncIO = asyncIO
177
+ this._fillCache = fillCache
178
+ }
179
+
171
180
  _init() {
172
181
  this._handle = binding.readInit()
173
182
  this._buffer = binding.readBuffer(this._handle, this._capacity)
@@ -190,6 +199,8 @@ exports.ReadBatch = class RocksDBReadBatch extends RocksDBBatch {
190
199
  this._handle,
191
200
  this._operations,
192
201
  this._db._snapshot ? this._db._snapshot._handle : undefined,
202
+ this._asyncIO,
203
+ this._fillCache,
193
204
  this,
194
205
  this._onread
195
206
  )
@@ -19,7 +19,10 @@ class RocksDBColumnFamily {
19
19
  filterPolicy = new BloomFilterPolicy(10),
20
20
  topLevelIndexPinningTier = constants.pinningTier.ALL,
21
21
  partitionPinningTier = constants.pinningTier.ALL,
22
- unpartitionedPinningTier = constants.pinningTier.ALL
22
+ unpartitionedPinningTier = constants.pinningTier.ALL,
23
+ optimizeFiltersForHits = false,
24
+ numLevels = 7,
25
+ maxWriteBufferNumber = 2
23
26
  } = opts
24
27
 
25
28
  this._name = name
@@ -37,7 +40,10 @@ class RocksDBColumnFamily {
37
40
  filterPolicy,
38
41
  topLevelIndexPinningTier,
39
42
  partitionPinningTier,
40
- unpartitionedPinningTier
43
+ unpartitionedPinningTier,
44
+ optimizeFiltersForHits,
45
+ numLevels,
46
+ maxWriteBufferNumber
41
47
  }
42
48
 
43
49
  const filterPolicyArguments = [0, 0, 0]
@@ -71,7 +77,10 @@ class RocksDBColumnFamily {
71
77
  ...filterPolicyArguments,
72
78
  topLevelIndexPinningTier,
73
79
  partitionPinningTier,
74
- unpartitionedPinningTier
80
+ unpartitionedPinningTier,
81
+ optimizeFiltersForHits,
82
+ numLevels,
83
+ maxWriteBufferNumber
75
84
  )
76
85
  }
77
86
 
package/lib/state.js CHANGED
@@ -23,7 +23,11 @@ module.exports = class RocksDBState extends ReadyResource {
23
23
  maxBackgroundJobs = 6,
24
24
  bytesPerSync = 1048576,
25
25
  maxOpenFiles = -1,
26
- useDirectReads = false
26
+ useDirectReads = false,
27
+ avoidUnnecessaryBlockingIO = false,
28
+ skipStatsUpdateOnOpen = false,
29
+ useDirectIOForFlushAndCompaction = false,
30
+ maxFileOpeningThreads = 16
27
31
  } = opts
28
32
 
29
33
  this.path = path
@@ -58,7 +62,11 @@ module.exports = class RocksDBState extends ReadyResource {
58
62
  maxBackgroundJobs,
59
63
  bytesPerSync,
60
64
  maxOpenFiles,
61
- useDirectReads
65
+ useDirectReads,
66
+ avoidUnnecessaryBlockingIO,
67
+ skipStatsUpdateOnOpen,
68
+ useDirectIOForFlushAndCompaction,
69
+ maxFileOpeningThreads
62
70
  )
63
71
  }
64
72
 
@@ -348,6 +356,48 @@ module.exports = class RocksDBState extends ReadyResource {
348
356
  }
349
357
  }
350
358
 
359
+ async approximateSize(db, start, end, opts) {
360
+ if (this.opened === false) await this.ready()
361
+
362
+ this.io.inc()
363
+
364
+ const {
365
+ includeMemtables = false,
366
+ includeFiles = true,
367
+ filesSizeErrorMargin = -1
368
+ } = opts
369
+
370
+ const req = { resolve: null, reject: null, handle: null }
371
+
372
+ const promise = new Promise((resolve, reject) => {
373
+ req.resolve = resolve
374
+ req.reject = reject
375
+ })
376
+
377
+ try {
378
+ req.handle = binding.approximateSize(
379
+ this._handle,
380
+ db._columnFamily._handle,
381
+ this._encodeKey(start),
382
+ this._encodeKey(end),
383
+ includeMemtables,
384
+ includeFiles,
385
+ filesSizeErrorMargin,
386
+ req,
387
+ onapproximatesize
388
+ )
389
+
390
+ return await promise
391
+ } finally {
392
+ this.io.dec()
393
+ }
394
+
395
+ function onapproximatesize(err, result) {
396
+ if (err) req.reject(new Error(err))
397
+ else req.resolve(result)
398
+ }
399
+ }
400
+
351
401
  _encodeKey(k) {
352
402
  if (this.db._keyEncoding) return c.encode(this.db._keyEncoding, k)
353
403
  if (typeof k === 'string') return Buffer.from(k)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",