@nxtedition/rocksdb 15.3.0 → 15.4.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/.claude/settings.local.json +2 -1
- package/binding.cc +59 -2
- package/cache.js +17 -0
- package/index.js +3 -1
- package/package.json +1 -1
package/binding.cc
CHANGED
|
@@ -812,7 +812,7 @@ static void FinalizeDatabase(napi_env env, void* data, void* hint) {
|
|
|
812
812
|
}
|
|
813
813
|
|
|
814
814
|
NAPI_METHOD(db_init) {
|
|
815
|
-
NAPI_ARGV(
|
|
815
|
+
NAPI_ARGV(2);
|
|
816
816
|
|
|
817
817
|
Database* database = nullptr;
|
|
818
818
|
|
|
@@ -1024,7 +1024,35 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
1024
1024
|
tableOptions.decouple_partitioned_filters = true;
|
|
1025
1025
|
|
|
1026
1026
|
std::shared_ptr<rocksdb::Cache> cache;
|
|
1027
|
+
|
|
1027
1028
|
{
|
|
1029
|
+
napi_value cacheValue;
|
|
1030
|
+
NAPI_STATUS_RETURN(napi_get_named_property(env, options, "cache", &cacheValue));
|
|
1031
|
+
|
|
1032
|
+
napi_valuetype cacheType;
|
|
1033
|
+
NAPI_STATUS_RETURN(napi_typeof(env, cacheValue, &cacheType));
|
|
1034
|
+
|
|
1035
|
+
if (cacheType == napi_object) {
|
|
1036
|
+
napi_value handleValue;
|
|
1037
|
+
NAPI_STATUS_RETURN(napi_get_named_property(env, cacheValue, "handle", &handleValue));
|
|
1038
|
+
|
|
1039
|
+
bool lossless;
|
|
1040
|
+
int64_t ptr;
|
|
1041
|
+
NAPI_STATUS_RETURN(napi_get_value_bigint_int64(env, handleValue, &ptr, &lossless));
|
|
1042
|
+
|
|
1043
|
+
cache = *reinterpret_cast<std::shared_ptr<rocksdb::Cache>*>(ptr);
|
|
1044
|
+
} else if (cacheType == napi_bigint) {
|
|
1045
|
+
bool lossless;
|
|
1046
|
+
int64_t ptr;
|
|
1047
|
+
NAPI_STATUS_RETURN(napi_get_value_bigint_int64(env, cacheValue, &ptr, &lossless));
|
|
1048
|
+
|
|
1049
|
+
cache = *reinterpret_cast<std::shared_ptr<rocksdb::Cache>*>(ptr);
|
|
1050
|
+
} else if (cacheType != napi_undefined && cacheType != napi_null) {
|
|
1051
|
+
return napi_invalid_arg;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
if (!cache) {
|
|
1028
1056
|
uint32_t cacheSize = 8 << 20;
|
|
1029
1057
|
double compressedRatio = 0.0;
|
|
1030
1058
|
|
|
@@ -1032,7 +1060,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
1032
1060
|
NAPI_STATUS_RETURN(GetProperty(env, options, "cacheCompressedRatio", compressedRatio));
|
|
1033
1061
|
|
|
1034
1062
|
if (cacheSize == 0) {
|
|
1035
|
-
|
|
1063
|
+
// Do nothing...
|
|
1036
1064
|
} else if (compressedRatio > 0.0) {
|
|
1037
1065
|
rocksdb::TieredCacheOptions options;
|
|
1038
1066
|
options.cache_type = rocksdb::PrimaryCacheType::kCacheTypeHCC;
|
|
@@ -2248,6 +2276,32 @@ NAPI_METHOD(db_compact_range) {
|
|
|
2248
2276
|
return 0;
|
|
2249
2277
|
}
|
|
2250
2278
|
|
|
2279
|
+
NAPI_METHOD(cache_init) {
|
|
2280
|
+
NAPI_ARGV(1);
|
|
2281
|
+
|
|
2282
|
+
size_t capacity = 32 * 1024 * 1024; // 32 MiB
|
|
2283
|
+
NAPI_STATUS_THROWS(GetProperty(env, argv[0], "capacity", capacity));
|
|
2284
|
+
|
|
2285
|
+
auto cache = new std::shared_ptr<rocksdb::Cache>(rocksdb::HyperClockCacheOptions(capacity, 0).MakeSharedCache());
|
|
2286
|
+
|
|
2287
|
+
napi_value result;
|
|
2288
|
+
NAPI_STATUS_THROWS(napi_create_external(env, cache, Finalize<std::shared_ptr<rocksdb::Cache>>, cache, &result));
|
|
2289
|
+
|
|
2290
|
+
return result;
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
NAPI_METHOD(cache_get_handle) {
|
|
2294
|
+
NAPI_ARGV(1);
|
|
2295
|
+
|
|
2296
|
+
std::shared_ptr<rocksdb::Cache>* cache;
|
|
2297
|
+
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&cache)));
|
|
2298
|
+
|
|
2299
|
+
napi_value result;
|
|
2300
|
+
NAPI_STATUS_THROWS(napi_create_bigint_int64(env, reinterpret_cast<intptr_t>(cache), &result));
|
|
2301
|
+
|
|
2302
|
+
return result;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2251
2305
|
NAPI_INIT() {
|
|
2252
2306
|
NAPI_EXPORT_FUNCTION(db_init);
|
|
2253
2307
|
NAPI_EXPORT_FUNCTION(db_open);
|
|
@@ -2286,4 +2340,7 @@ NAPI_INIT() {
|
|
|
2286
2340
|
NAPI_EXPORT_FUNCTION(batch_merge);
|
|
2287
2341
|
NAPI_EXPORT_FUNCTION(batch_count);
|
|
2288
2342
|
NAPI_EXPORT_FUNCTION(batch_iterate);
|
|
2343
|
+
|
|
2344
|
+
NAPI_EXPORT_FUNCTION(cache_init);
|
|
2345
|
+
NAPI_EXPORT_FUNCTION(cache_get_handle);
|
|
2289
2346
|
}
|
package/cache.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const binding = require('./binding')
|
|
4
|
+
|
|
5
|
+
const kCacheContext = Symbol('cacheContext')
|
|
6
|
+
|
|
7
|
+
class RocksCache {
|
|
8
|
+
constructor(optionsOrHandle = {}) {
|
|
9
|
+
this[kCacheContext] = binding.cache_init(optionsOrHandle)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get handle () {
|
|
13
|
+
return binding.cache_get_handle(this[kCacheContext])
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.RocksCache = RocksCache
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const { AbstractLevel } = require('abstract-level')
|
|
|
5
5
|
const ModuleError = require('module-error')
|
|
6
6
|
const binding = require('./binding')
|
|
7
7
|
const { ChainedBatch } = require('./chained-batch')
|
|
8
|
+
const { RocksCache } = require('./cache')
|
|
8
9
|
const { Iterator } = require('./iterator')
|
|
9
10
|
const fs = require('node:fs')
|
|
10
11
|
const assert = require('node:assert')
|
|
@@ -20,7 +21,7 @@ const { kRef, kUnref } = require('./util')
|
|
|
20
21
|
const kEmpty = {}
|
|
21
22
|
|
|
22
23
|
class RocksLevel extends AbstractLevel {
|
|
23
|
-
constructor (locationOrHandle, options) {
|
|
24
|
+
constructor (locationOrHandle, { ...options } = {}) {
|
|
24
25
|
super({
|
|
25
26
|
encodings: {
|
|
26
27
|
buffer: true,
|
|
@@ -339,3 +340,4 @@ class RocksLevel extends AbstractLevel {
|
|
|
339
340
|
}
|
|
340
341
|
|
|
341
342
|
exports.RocksLevel = RocksLevel
|
|
343
|
+
exports.RocksCache = RocksCache
|