@nxtedition/rocksdb 13.4.1 → 13.4.3

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/binding.cc CHANGED
@@ -922,21 +922,44 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
922
922
  rocksdb::BlockBasedTableOptions tableOptions;
923
923
  tableOptions.decouple_partitioned_filters = true;
924
924
 
925
+ std::shared_ptr<rocksdb::Cache> cache;
925
926
  {
926
927
  uint32_t cacheSize = 8 << 20;
927
928
  double compressedRatio = 0.0;
928
929
 
929
- // Compat
930
930
  NAPI_STATUS_RETURN(GetProperty(env, options, "cacheSize", cacheSize));
931
931
  NAPI_STATUS_RETURN(GetProperty(env, options, "cacheCompressedRatio", compressedRatio));
932
+
933
+ if (cacheSize == 0) {
934
+ cache = nullptr;
935
+ } else if (compressedRatio > 0.0) {
936
+ rocksdb::TieredCacheOptions options;
937
+ options.total_capacity = cacheSize;
938
+ options.compressed_secondary_ratio = compressedRatio;
939
+ options.comp_cache_opts.compression_type = rocksdb::CompressionType::kZSTD;
940
+ cache = rocksdb::NewTieredCache(options);
941
+ } else {
942
+ cache = rocksdb::HyperClockCacheOptions(cacheSize, 0).MakeSharedCache();
943
+ }
944
+ }
945
+
946
+ {
947
+ uint32_t cacheSize = -1;
948
+ double compressedRatio = 0.0;
949
+
950
+ NAPI_STATUS_RETURN(GetProperty(env, options, "cachePrepopulate", tableOptions.prepopulate_block_cache));
932
951
  NAPI_STATUS_RETURN(GetProperty(env, options, "prepopulateBlockCache", tableOptions.prepopulate_block_cache));
933
952
 
934
953
  NAPI_STATUS_RETURN(GetProperty(env, options, "blockCacheSize", cacheSize));
935
954
  NAPI_STATUS_RETURN(GetProperty(env, options, "blockCacheCompressedRatio", compressedRatio));
936
955
  NAPI_STATUS_RETURN(GetProperty(env, options, "blockCachePrepopulate", tableOptions.prepopulate_block_cache));
937
956
 
938
- if (cacheSize == 0) {
939
- tableOptions.no_block_cache = true;
957
+ if (cacheSize == -1) {
958
+ if (cache) {
959
+ tableOptions.block_cache = cache;
960
+ } else {
961
+ tableOptions.no_block_cache = true;
962
+ }
940
963
  } else if (compressedRatio > 0.0) {
941
964
  rocksdb::TieredCacheOptions options;
942
965
  options.total_capacity = cacheSize;
@@ -952,7 +975,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
952
975
  uint32_t cacheSize = -1;
953
976
  double compressedRatio = 0.0;
954
977
 
955
- // Compat
978
+ NAPI_STATUS_RETURN(GetProperty(env, options, "cachePrepopulate", columnOptions.prepopulate_blob_cache));
956
979
  NAPI_STATUS_RETURN(GetProperty(env, options, "prepopulateBlobCache", columnOptions.prepopulate_blob_cache));
957
980
 
958
981
  NAPI_STATUS_RETURN(GetProperty(env, options, "blobCacheSize", cacheSize));
@@ -960,7 +983,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
960
983
  NAPI_STATUS_RETURN(GetProperty(env, options, "blobCachePrepopulate", columnOptions.prepopulate_blob_cache));
961
984
 
962
985
  if (cacheSize == -1) {
963
- columnOptions.blob_cache = tableOptions.block_cache;
986
+ columnOptions.blob_cache = cache;
964
987
  } else if (cacheSize == 0) {
965
988
  columnOptions.blob_cache = nullptr;
966
989
  } else if (compressedRatio > 0.0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "13.4.1",
3
+ "version": "13.4.3",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
package/util.h CHANGED
@@ -38,12 +38,12 @@
38
38
  } \
39
39
  }
40
40
 
41
- #define ROCKS_STATUS_RETURN(call) \
42
- { \
43
- auto _status = (call); \
44
- if (!_status.ok()) { \
45
- return _status; \
46
- } \
41
+ #define ROCKS_STATUS_RETURN(call) \
42
+ { \
43
+ auto _status = (call); \
44
+ if (!_status.ok()) { \
45
+ return _status; \
46
+ } \
47
47
  }
48
48
 
49
49
  template <typename T>
@@ -249,7 +249,6 @@ static napi_status GetValue(napi_env env, napi_value value, double& result) {
249
249
  return napi_ok;
250
250
  }
251
251
 
252
-
253
252
  static napi_status GetValue(napi_env env, napi_value value, std::string& result) {
254
253
  return GetString(env, value, result);
255
254
  }
@@ -276,21 +275,27 @@ static napi_status GetValue(napi_env env, napi_value value, Encoding& result) {
276
275
 
277
276
  if (size == 6) {
278
277
  result = Encoding::Buffer;
278
+ return napi_ok;
279
279
  } else {
280
280
  result = Encoding::String;
281
+ return napi_ok;
281
282
  }
282
283
 
283
- return napi_ok;
284
+ return napi_invalid_arg;
284
285
  }
285
286
 
286
- static napi_status GetValue(napi_env env, napi_value value, rocksdb::BlockBasedTableOptions::PrepopulateBlockCache& result) {
287
+ static napi_status GetValue(napi_env env,
288
+ napi_value value,
289
+ rocksdb::BlockBasedTableOptions::PrepopulateBlockCache& result) {
287
290
  std::string str;
288
291
 
289
292
  if (GetValue(env, value, str) == napi_ok) {
290
293
  if (str == "flushOnly") {
291
294
  result = rocksdb::BlockBasedTableOptions::PrepopulateBlockCache::kFlushOnly;
295
+ return napi_ok;
292
296
  } else if (str == "disable") {
293
297
  result = rocksdb::BlockBasedTableOptions::PrepopulateBlockCache::kDisable;
298
+ return napi_ok;
294
299
  } else {
295
300
  return napi_invalid_arg;
296
301
  }
@@ -300,6 +305,7 @@ static napi_status GetValue(napi_env env, napi_value value, rocksdb::BlockBasedT
300
305
  if (GetValue(env, value, boolean) == napi_ok) {
301
306
  result = boolean ? rocksdb::BlockBasedTableOptions::PrepopulateBlockCache::kFlushOnly
302
307
  : rocksdb::BlockBasedTableOptions::PrepopulateBlockCache::kDisable;
308
+ return napi_ok;
303
309
  }
304
310
 
305
311
  return napi_invalid_arg;
@@ -311,8 +317,10 @@ static napi_status GetValue(napi_env env, napi_value value, rocksdb::Prepopulate
311
317
  if (GetValue(env, value, str) == napi_ok) {
312
318
  if (str == "flushOnly") {
313
319
  result = rocksdb::PrepopulateBlobCache::kFlushOnly;
320
+ return napi_ok;
314
321
  } else if (str == "disable") {
315
322
  result = rocksdb::PrepopulateBlobCache::kDisable;
323
+ return napi_ok;
316
324
  } else {
317
325
  return napi_invalid_arg;
318
326
  }
@@ -320,8 +328,8 @@ static napi_status GetValue(napi_env env, napi_value value, rocksdb::Prepopulate
320
328
 
321
329
  bool boolean;
322
330
  if (GetValue(env, value, boolean) == napi_ok) {
323
- result = boolean ? rocksdb::PrepopulateBlobCache::kFlushOnly
324
- : rocksdb::PrepopulateBlobCache::kDisable;
331
+ result = boolean ? rocksdb::PrepopulateBlobCache::kFlushOnly : rocksdb::PrepopulateBlobCache::kDisable;
332
+ return napi_ok;
325
333
  }
326
334
 
327
335
  return napi_invalid_arg;
@@ -333,27 +341,37 @@ static napi_status GetValue(napi_env env, napi_value value, rocksdb::Compression
333
341
  if (GetValue(env, value, str) == napi_ok) {
334
342
  if (str == "no") {
335
343
  result = rocksdb::CompressionType::kNoCompression;
344
+ return napi_ok;
336
345
  } else if (str == "snappy") {
337
346
  result = rocksdb::CompressionType::kSnappyCompression;
347
+ return napi_ok;
338
348
  } else if (str == "zlib") {
339
349
  result = rocksdb::CompressionType::kZlibCompression;
350
+ return napi_ok;
340
351
  } else if (str == "bzip2") {
341
352
  result = rocksdb::CompressionType::kBZip2Compression;
353
+ return napi_ok;
342
354
  } else if (str == "lz4") {
343
355
  result = rocksdb::CompressionType::kLZ4Compression;
356
+ return napi_ok;
344
357
  } else if (str == "lz4hc") {
345
358
  result = rocksdb::CompressionType::kLZ4HCCompression;
359
+ return napi_ok;
346
360
  } else if (str == "xpress") {
347
361
  result = rocksdb::CompressionType::kXpressCompression;
362
+ return napi_ok;
348
363
  } else if (str == "zstd") {
349
364
  result = rocksdb::CompressionType::kZSTD;
365
+ return napi_ok;
366
+ } else {
367
+ return napi_invalid_arg;
350
368
  }
351
369
  }
352
370
 
353
371
  bool boolean;
354
372
  if (GetValue(env, value, boolean) == napi_ok) {
355
- result = boolean ? rocksdb::kZSTD
356
- : rocksdb::kNoCompression;
373
+ result = boolean ? rocksdb::kZSTD : rocksdb::kNoCompression;
374
+ return napi_ok;
357
375
  }
358
376
 
359
377
  return napi_invalid_arg;