rocksdb-native 3.7.5 → 3.8.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 +1 -1
- package/binding.cc +103 -0
- package/index.js +13 -0
- package/lib/state.js +45 -0
- package/package.json +1 -1
- package/prebuilds/android-arm/rocksdb-native.bare +0 -0
- package/prebuilds/android-arm64/rocksdb-native.bare +0 -0
- package/prebuilds/android-ia32/rocksdb-native.bare +0 -0
- package/prebuilds/android-x64/rocksdb-native.bare +0 -0
- package/prebuilds/darwin-arm64/rocksdb-native.bare +0 -0
- package/prebuilds/darwin-arm64/rocksdb-native.node +0 -0
- package/prebuilds/darwin-x64/rocksdb-native.bare +0 -0
- package/prebuilds/darwin-x64/rocksdb-native.node +0 -0
- package/prebuilds/ios-arm64/rocksdb-native.bare +0 -0
- package/prebuilds/ios-arm64-simulator/rocksdb-native.bare +0 -0
- package/prebuilds/ios-x64-simulator/rocksdb-native.bare +0 -0
- package/prebuilds/linux-arm64/rocksdb-native.bare +0 -0
- package/prebuilds/linux-arm64/rocksdb-native.node +0 -0
- package/prebuilds/linux-x64/rocksdb-native.bare +0 -0
- package/prebuilds/linux-x64/rocksdb-native.node +0 -0
- package/prebuilds/win32-arm64/rocksdb-native.bare +0 -0
- package/prebuilds/win32-arm64/rocksdb-native.node +0 -0
- package/prebuilds/win32-x64/rocksdb-native.bare +0 -0
- package/prebuilds/win32-x64/rocksdb-native.node +0 -0
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#
|
|
12
|
+
fetch_package("github:holepunchto/librocksdb#ac350df")
|
|
13
13
|
fetch_package("github:holepunchto/libjstl#34a7894")
|
|
14
14
|
|
|
15
15
|
add_bare_module(rocksdb_native_bare)
|
package/binding.cc
CHANGED
|
@@ -23,6 +23,7 @@ using cb_on_iterator_read_t = js_function_t<
|
|
|
23
23
|
std::optional<js_string_t>,
|
|
24
24
|
std::vector<js_arraybuffer_t>,
|
|
25
25
|
std::vector<js_arraybuffer_t>>;
|
|
26
|
+
using cb_on_compact_range_t = js_function_t<void, js_receiver_t, std::optional<js_string_t>>;
|
|
26
27
|
}; // namespace
|
|
27
28
|
|
|
28
29
|
struct rocksdb_native_column_family_t {
|
|
@@ -138,6 +139,14 @@ struct rocksdb_native_snapshot_t {
|
|
|
138
139
|
rocksdb_snapshot_t handle;
|
|
139
140
|
};
|
|
140
141
|
|
|
142
|
+
struct rocksdb_native_compact_range_t {
|
|
143
|
+
rocksdb_compact_range_t handle;
|
|
144
|
+
|
|
145
|
+
js_env_t *env;
|
|
146
|
+
js_persistent_t<js_receiver_t> ctx;
|
|
147
|
+
js_persistent_t<cb_on_compact_range_t> on_compact_range;
|
|
148
|
+
};
|
|
149
|
+
|
|
141
150
|
static void
|
|
142
151
|
rocksdb_native__on_free(js_env_t *env, char *data) {
|
|
143
152
|
free(data);
|
|
@@ -1514,6 +1523,98 @@ rocksdb_native_snapshot_destroy(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_
|
|
|
1514
1523
|
rocksdb_snapshot_destroy(&snapshot->handle);
|
|
1515
1524
|
}
|
|
1516
1525
|
|
|
1526
|
+
static void
|
|
1527
|
+
rocksdb_native__on_compact_range(rocksdb_compact_range_t *handle, int status) {
|
|
1528
|
+
int err;
|
|
1529
|
+
|
|
1530
|
+
assert(status == 0);
|
|
1531
|
+
|
|
1532
|
+
rocksdb_native_compact_range_t *req = (rocksdb_native_compact_range_t *) handle->data;
|
|
1533
|
+
|
|
1534
|
+
rocksdb_native_t *db = (rocksdb_native_t *) req->handle.req.db;
|
|
1535
|
+
|
|
1536
|
+
js_env_t *env = req->env;
|
|
1537
|
+
|
|
1538
|
+
if (db->exiting) {
|
|
1539
|
+
req->on_compact_range.reset();
|
|
1540
|
+
req->ctx.reset();
|
|
1541
|
+
} else {
|
|
1542
|
+
js_handle_scope_t *scope;
|
|
1543
|
+
err = js_open_handle_scope(env, &scope);
|
|
1544
|
+
assert(err == 0);
|
|
1545
|
+
|
|
1546
|
+
std::optional<js_string_t> error;
|
|
1547
|
+
|
|
1548
|
+
if (req->handle.error) {
|
|
1549
|
+
err = js_create_string(env, req->handle.error, error.emplace());
|
|
1550
|
+
assert(err == 0);
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
js_receiver_t ctx;
|
|
1554
|
+
err = js_get_reference_value(env, req->ctx, ctx);
|
|
1555
|
+
assert(err == 0);
|
|
1556
|
+
|
|
1557
|
+
cb_on_compact_range_t cb;
|
|
1558
|
+
err = js_get_reference_value(env, req->on_compact_range, cb);
|
|
1559
|
+
assert(err == 0);
|
|
1560
|
+
|
|
1561
|
+
req->on_compact_range.reset();
|
|
1562
|
+
req->ctx.reset();
|
|
1563
|
+
|
|
1564
|
+
js_call_function_with_checkpoint(env, cb, ctx, error);
|
|
1565
|
+
|
|
1566
|
+
err = js_close_handle_scope(env, scope);
|
|
1567
|
+
assert(err == 0);
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
static js_arraybuffer_t
|
|
1572
|
+
rocksdb_native_compact_range(
|
|
1573
|
+
js_env_t *env,
|
|
1574
|
+
js_arraybuffer_span_of_t<rocksdb_native_t, 1> db,
|
|
1575
|
+
js_arraybuffer_span_of_t<rocksdb_native_column_family_t, 1> column_family,
|
|
1576
|
+
js_typedarray_t<> start,
|
|
1577
|
+
js_typedarray_t<> end,
|
|
1578
|
+
bool exclusive,
|
|
1579
|
+
js_receiver_t ctx,
|
|
1580
|
+
cb_on_compact_range_t on_compact_range
|
|
1581
|
+
) {
|
|
1582
|
+
int err;
|
|
1583
|
+
|
|
1584
|
+
js_arraybuffer_t handle;
|
|
1585
|
+
|
|
1586
|
+
rocksdb_native_compact_range_t *req;
|
|
1587
|
+
err = js_create_arraybuffer(env, req, handle);
|
|
1588
|
+
assert(err == 0);
|
|
1589
|
+
|
|
1590
|
+
req->env = env;
|
|
1591
|
+
req->handle.data = (void *) req;
|
|
1592
|
+
|
|
1593
|
+
err = js_create_reference(env, ctx, req->ctx);
|
|
1594
|
+
assert(err == 0);
|
|
1595
|
+
|
|
1596
|
+
err = js_create_reference(env, on_compact_range, req->on_compact_range);
|
|
1597
|
+
assert(err == 0);
|
|
1598
|
+
|
|
1599
|
+
rocksdb_compact_range_options_t options = {
|
|
1600
|
+
.version = 0,
|
|
1601
|
+
.exclusive_manual_compaction = exclusive
|
|
1602
|
+
};
|
|
1603
|
+
|
|
1604
|
+
rocksdb_slice_t start_slice;
|
|
1605
|
+
err = js_get_typedarray_info(env, start, start_slice.data, start_slice.len);
|
|
1606
|
+
assert(err == 0);
|
|
1607
|
+
|
|
1608
|
+
rocksdb_slice_t end_slice;
|
|
1609
|
+
err = js_get_typedarray_info(env, end, end_slice.data, end_slice.len);
|
|
1610
|
+
assert(err == 0);
|
|
1611
|
+
|
|
1612
|
+
err = rocksdb_compact_range(&db->handle, &req->handle, column_family->handle, start_slice, end_slice, &options, rocksdb_native__on_compact_range);
|
|
1613
|
+
assert(err == 0);
|
|
1614
|
+
|
|
1615
|
+
return handle;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1517
1618
|
static js_value_t *
|
|
1518
1619
|
rocksdb_native_exports(js_env_t *env, js_value_t *exports) {
|
|
1519
1620
|
int err;
|
|
@@ -1549,6 +1650,8 @@ rocksdb_native_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1549
1650
|
|
|
1550
1651
|
V("snapshotCreate", rocksdb_native_snapshot_create)
|
|
1551
1652
|
V("snapshotDestroy", rocksdb_native_snapshot_destroy)
|
|
1653
|
+
|
|
1654
|
+
V("compactRange", rocksdb_native_compact_range)
|
|
1552
1655
|
#undef V
|
|
1553
1656
|
|
|
1554
1657
|
#define V(name, n) \
|
package/index.js
CHANGED
|
@@ -176,6 +176,19 @@ class RocksDB {
|
|
|
176
176
|
await batch.flush()
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
async compactRange(start = null, end = null, opts = {}) {
|
|
180
|
+
if (typeof end === 'object' && end !== null) {
|
|
181
|
+
opts = end
|
|
182
|
+
end = null
|
|
183
|
+
} else if (typeof start === 'object' && start !== null) {
|
|
184
|
+
opts = start
|
|
185
|
+
start = null
|
|
186
|
+
end = null
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
await this._state.compactRange(this, start, end, opts)
|
|
190
|
+
}
|
|
191
|
+
|
|
179
192
|
_ref() {
|
|
180
193
|
if (this._snapshot) this._snapshot.ref()
|
|
181
194
|
this._state.handles.inc()
|
package/lib/state.js
CHANGED
|
@@ -2,11 +2,13 @@ const ReadyResource = require('ready-resource')
|
|
|
2
2
|
const RefCounter = require('refcounter')
|
|
3
3
|
const rrp = require('resolve-reject-promise')
|
|
4
4
|
const SignalPromise = require('signal-promise')
|
|
5
|
+
const c = require('compact-encoding')
|
|
5
6
|
const { ReadBatch, WriteBatch } = require('./batch')
|
|
6
7
|
const ColumnFamily = require('./column-family')
|
|
7
8
|
const binding = require('../binding')
|
|
8
9
|
|
|
9
10
|
const MAX_BATCH_REUSE = 64
|
|
11
|
+
const empty = Buffer.alloc(0)
|
|
10
12
|
|
|
11
13
|
module.exports = class RocksDBState extends ReadyResource {
|
|
12
14
|
constructor(db, path, opts) {
|
|
@@ -309,4 +311,47 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
309
311
|
else req.resolve()
|
|
310
312
|
}
|
|
311
313
|
}
|
|
314
|
+
|
|
315
|
+
async compactRange(db, start, end, opts) {
|
|
316
|
+
if (this.opened === false) await this.ready()
|
|
317
|
+
|
|
318
|
+
this.io.inc()
|
|
319
|
+
|
|
320
|
+
const { exclusive = false } = opts
|
|
321
|
+
|
|
322
|
+
const req = { resolve: null, reject: null, handle: null }
|
|
323
|
+
|
|
324
|
+
const promise = new Promise((resolve, reject) => {
|
|
325
|
+
req.resolve = resolve
|
|
326
|
+
req.reject = reject
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
req.handle = binding.compactRange(
|
|
331
|
+
this._handle,
|
|
332
|
+
db._columnFamily._handle,
|
|
333
|
+
this._encodeKey(start),
|
|
334
|
+
this._encodeKey(end),
|
|
335
|
+
exclusive,
|
|
336
|
+
req,
|
|
337
|
+
oncompactrange
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
await promise
|
|
341
|
+
} finally {
|
|
342
|
+
this.io.dec()
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function oncompactrange(err) {
|
|
346
|
+
if (err) req.reject(new Error(err))
|
|
347
|
+
else req.resolve()
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
_encodeKey(k) {
|
|
352
|
+
if (this.db._keyEncoding) return c.encode(this.db._keyEncoding, k)
|
|
353
|
+
if (typeof k === 'string') return Buffer.from(k)
|
|
354
|
+
if (k === null) return empty
|
|
355
|
+
return k
|
|
356
|
+
}
|
|
312
357
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|