@nxtedition/rocksdb 13.1.0 → 13.1.2

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
@@ -18,8 +18,6 @@
18
18
  #include <rocksdb/table.h>
19
19
  #include <rocksdb/write_batch.h>
20
20
 
21
- #include <re2/re2.h>
22
-
23
21
  #include <iostream>
24
22
  #include <memory>
25
23
  #include <optional>
@@ -412,7 +410,6 @@ class Iterator final : public BaseIterator {
412
410
  bool first_ = true;
413
411
  const Encoding keyEncoding_;
414
412
  const Encoding valueEncoding_;
415
- std::unique_ptr<re2::RE2> expr_;
416
413
 
417
414
  public:
418
415
  Iterator(Database* database,
@@ -428,18 +425,13 @@ class Iterator final : public BaseIterator {
428
425
  const size_t highWaterMarkBytes,
429
426
  Encoding keyEncoding = Encoding::Invalid,
430
427
  Encoding valueEncoding = Encoding::Invalid,
431
- rocksdb::ReadOptions readOptions = {},
432
- const std::string& selector = "")
428
+ rocksdb::ReadOptions readOptions = {})
433
429
  : BaseIterator(database, column, reverse, lt, lte, gt, gte, limit, readOptions),
434
430
  keys_(keys),
435
431
  values_(values),
436
432
  highWaterMarkBytes_(highWaterMarkBytes),
437
433
  keyEncoding_(keyEncoding),
438
434
  valueEncoding_(valueEncoding) {
439
- if (selector != "") {
440
- // TODO (fix): Pool selectors?
441
- expr_.reset(new re2::RE2(selector));
442
- }
443
435
  }
444
436
 
445
437
  void Seek(const rocksdb::Slice& target) override {
@@ -513,9 +505,6 @@ class Iterator final : public BaseIterator {
513
505
  readOptions.ignore_range_deletions = false;
514
506
  NAPI_STATUS_THROWS(GetProperty(env, options, "ignoreRangeDeletions", readOptions.ignore_range_deletions));
515
507
 
516
- std::string selector;
517
- NAPI_STATUS_THROWS(GetProperty(env, options, "selector", selector));
518
-
519
508
  // uint32_t timeout = 0;
520
509
  // NAPI_STATUS_THROWS(GetProperty(env, options, "timeout", timeout));
521
510
 
@@ -524,7 +513,7 @@ class Iterator final : public BaseIterator {
524
513
  // : std::chrono::microseconds::zero();
525
514
 
526
515
  return std::make_unique<Iterator>(database, column, reverse, keys, values, limit, lt, lte, gt, gte,
527
- highWaterMarkBytes, keyEncoding, valueEncoding, readOptions, selector);
516
+ highWaterMarkBytes, keyEncoding, valueEncoding, readOptions);
528
517
  }
529
518
 
530
519
  napi_value nextv(napi_env env, uint32_t count, uint32_t timeout, napi_value callback) {
@@ -559,28 +548,26 @@ class Iterator final : public BaseIterator {
559
548
  break;
560
549
  }
561
550
 
562
- if (!expr_ || re2::RE2::PartialMatch(CurrentKey().ToStringView(), *expr_)) {
563
- if (keys_ && values_) {
564
- rocksdb::PinnableSlice k;
565
- k.PinSelf(CurrentKey());
566
- state.keys.push_back(std::move(k));
567
-
568
- rocksdb::PinnableSlice v;
569
- v.PinSelf(CurrentValue());
570
- state.values.push_back(std::move(v));
571
- } else if (keys_) {
572
- rocksdb::PinnableSlice k;
573
- k.PinSelf(CurrentKey());
574
- state.keys.push_back(std::move(k));
575
- } else if (values_) {
576
- rocksdb::PinnableSlice v;
577
- v.PinSelf(CurrentValue());
578
- state.values.push_back(std::move(v));
579
- } else {
580
- assert(false);
581
- }
582
- state.count += 1;
551
+ if (keys_ && values_) {
552
+ rocksdb::PinnableSlice k;
553
+ k.PinSelf(CurrentKey());
554
+ state.keys.push_back(std::move(k));
555
+
556
+ rocksdb::PinnableSlice v;
557
+ v.PinSelf(CurrentValue());
558
+ state.values.push_back(std::move(v));
559
+ } else if (keys_) {
560
+ rocksdb::PinnableSlice k;
561
+ k.PinSelf(CurrentKey());
562
+ state.keys.push_back(std::move(k));
563
+ } else if (values_) {
564
+ rocksdb::PinnableSlice v;
565
+ v.PinSelf(CurrentValue());
566
+ state.values.push_back(std::move(v));
567
+ } else {
568
+ assert(false);
583
569
  }
570
+ state.count += 1;
584
571
 
585
572
  bytesRead += CurrentKey().size() + CurrentValue().size();
586
573
  if (bytesRead > highWaterMarkBytes_) {
@@ -661,31 +648,29 @@ class Iterator final : public BaseIterator {
661
648
  break;
662
649
  }
663
650
 
664
- if (!expr_ || re2::RE2::PartialMatch(CurrentKey().ToStringView(), *expr_)) {
665
- napi_value key;
666
- napi_value val;
667
-
668
- if (keys_ && values_) {
669
- const auto k = CurrentKey();
670
- const auto v = CurrentValue();
671
- NAPI_STATUS_THROWS(Convert(env, &k, keyEncoding_, key));
672
- NAPI_STATUS_THROWS(Convert(env, &v, valueEncoding_, val));
673
- } else if (keys_) {
674
- const auto k = CurrentKey();
675
- NAPI_STATUS_THROWS(Convert(env, &k, keyEncoding_, key));
676
- NAPI_STATUS_THROWS(napi_get_undefined(env, &val));
677
- } else if (values_) {
678
- const auto v = CurrentValue();
679
- NAPI_STATUS_THROWS(napi_get_undefined(env, &key));
680
- NAPI_STATUS_THROWS(Convert(env, &v, valueEncoding_, val));
681
- } else {
682
- assert(false);
683
- }
651
+ napi_value key;
652
+ napi_value val;
684
653
 
685
- NAPI_STATUS_THROWS(napi_set_element(env, rows, idx++, key));
686
- NAPI_STATUS_THROWS(napi_set_element(env, rows, idx++, val));
654
+ if (keys_ && values_) {
655
+ const auto k = CurrentKey();
656
+ const auto v = CurrentValue();
657
+ NAPI_STATUS_THROWS(Convert(env, &k, keyEncoding_, key));
658
+ NAPI_STATUS_THROWS(Convert(env, &v, valueEncoding_, val));
659
+ } else if (keys_) {
660
+ const auto k = CurrentKey();
661
+ NAPI_STATUS_THROWS(Convert(env, &k, keyEncoding_, key));
662
+ NAPI_STATUS_THROWS(napi_get_undefined(env, &val));
663
+ } else if (values_) {
664
+ const auto v = CurrentValue();
665
+ NAPI_STATUS_THROWS(napi_get_undefined(env, &key));
666
+ NAPI_STATUS_THROWS(Convert(env, &v, valueEncoding_, val));
667
+ } else {
668
+ assert(false);
687
669
  }
688
670
 
671
+ NAPI_STATUS_THROWS(napi_set_element(env, rows, idx++, key));
672
+ NAPI_STATUS_THROWS(napi_set_element(env, rows, idx++, val));
673
+
689
674
  bytesRead += CurrentKey().size() + CurrentValue().size();
690
675
  if (bytesRead > highWaterMarkBytes_) {
691
676
  break;
@@ -865,53 +850,57 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
865
850
  // TODO (perf): compression_opts.parallel_threads
866
851
  }
867
852
 
868
- std::optional<std::string> prefixExtractorOpt;
869
- NAPI_STATUS_RETURN(GetProperty(env, options, "prefixExtractor", prefixExtractorOpt));
870
- if (prefixExtractorOpt) {
853
+ std::string prefixExtractor;
854
+ NAPI_STATUS_RETURN(GetProperty(env, options, "prefixExtractor", prefixExtractor));
855
+ if (prefixExtractor == "") {
856
+ // Do nothing...
857
+ } else {
871
858
  ROCKS_STATUS_RETURN_NAPI(
872
- rocksdb::SliceTransform::CreateFromString(configOptions, *prefixExtractorOpt, &columnOptions.prefix_extractor));
859
+ rocksdb::SliceTransform::CreateFromString(configOptions, prefixExtractor, &columnOptions.prefix_extractor));
873
860
  }
874
861
 
875
- std::optional<std::string> comparatorOpt;
876
- NAPI_STATUS_RETURN(GetProperty(env, options, "comparator", comparatorOpt));
877
- if (comparatorOpt) {
862
+ std::string comparator;
863
+ NAPI_STATUS_RETURN(GetProperty(env, options, "comparator", comparator));
864
+ if (comparator == "") {
865
+ // Do nothing...
866
+ } else {
878
867
  ROCKS_STATUS_RETURN_NAPI(
879
- rocksdb::Comparator::CreateFromString(configOptions, *comparatorOpt, &columnOptions.comparator));
868
+ rocksdb::Comparator::CreateFromString(configOptions, comparator, &columnOptions.comparator));
880
869
  }
881
870
 
882
- std::optional<std::string> mergeOperatorOpt;
883
- NAPI_STATUS_RETURN(GetProperty(env, options, "mergeOperator", mergeOperatorOpt));
884
- if (mergeOperatorOpt) {
885
- if (*mergeOperatorOpt == "maxRev") {
886
- columnOptions.merge_operator = std::make_shared<MaxRevOperator>();
887
- } else {
888
- ROCKS_STATUS_RETURN_NAPI(
889
- rocksdb::MergeOperator::CreateFromString(configOptions, *mergeOperatorOpt, &columnOptions.merge_operator));
890
- }
871
+ std::string mergeOperator;
872
+ NAPI_STATUS_RETURN(GetProperty(env, options, "mergeOperator", mergeOperator));
873
+ if (mergeOperator == "") {
874
+ // Do nothing...
875
+ } else if (mergeOperator == "maxRev") {
876
+ columnOptions.merge_operator = std::make_shared<MaxRevOperator>();
877
+ } else {
878
+ ROCKS_STATUS_RETURN_NAPI(
879
+ rocksdb::MergeOperator::CreateFromString(configOptions, mergeOperator, &columnOptions.merge_operator));
891
880
  }
892
881
 
893
- std::optional<std::string> compactionPriority;
882
+ std::string compactionPriority;
894
883
  NAPI_STATUS_RETURN(GetProperty(env, options, "compactionPriority", compactionPriority));
895
- if (compactionPriority) {
896
- if (compactionPriority == "byCompensatedSize") {
897
- columnOptions.compaction_pri = rocksdb::kByCompensatedSize;
898
- } else if (compactionPriority == "oldestLargestSeqFirst") {
899
- columnOptions.compaction_pri = rocksdb::kOldestLargestSeqFirst;
900
- } else if (compactionPriority == "smallestSeqFirst") {
901
- columnOptions.compaction_pri = rocksdb::kOldestSmallestSeqFirst;
902
- } else if (compactionPriority == "overlappingRatio") {
903
- columnOptions.compaction_pri = rocksdb::kMinOverlappingRatio;
904
- } else if (compactionPriority == "roundRobin") {
905
- columnOptions.compaction_pri = rocksdb::kRoundRobin;
906
- } else {
907
- // Throw?
908
- }
884
+ if (compactionPriority == "") {
885
+ // Do nothing...
886
+ } else if (compactionPriority == "byCompensatedSize") {
887
+ columnOptions.compaction_pri = rocksdb::kByCompensatedSize;
888
+ } else if (compactionPriority == "oldestLargestSeqFirst") {
889
+ columnOptions.compaction_pri = rocksdb::kOldestLargestSeqFirst;
890
+ } else if (compactionPriority == "smallestSeqFirst") {
891
+ columnOptions.compaction_pri = rocksdb::kOldestSmallestSeqFirst;
892
+ } else if (compactionPriority == "overlappingRatio") {
893
+ columnOptions.compaction_pri = rocksdb::kMinOverlappingRatio;
894
+ } else if (compactionPriority == "roundRobin") {
895
+ columnOptions.compaction_pri = rocksdb::kRoundRobin;
896
+ } else {
897
+ return napi_invalid_arg;
909
898
  }
910
899
 
911
- columnOptions.optimize_filters_for_hits = false;
912
900
  NAPI_STATUS_RETURN(GetProperty(env, options, "optimizeFiltersForHits", columnOptions.optimize_filters_for_hits));
913
901
 
914
902
  rocksdb::BlockBasedTableOptions tableOptions;
903
+ tableOptions.decouple_partitioned_filters = true;
915
904
 
916
905
  {
917
906
  uint32_t cacheSize = 8 << 20;
@@ -927,7 +916,9 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
927
916
  std::string optimize = "";
928
917
  NAPI_STATUS_RETURN(GetProperty(env, options, "optimize", optimize));
929
918
 
930
- if (optimize == "point-lookup") {
919
+ if (optimize == "") {
920
+ tableOptions.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10));
921
+ } else if (optimize == "point-lookup") {
931
922
  tableOptions.data_block_index_type = rocksdb::BlockBasedTableOptions::kDataBlockBinaryAndHash;
932
923
  tableOptions.data_block_hash_table_util_ratio = 0.75;
933
924
  tableOptions.filter_policy.reset(rocksdb::NewRibbonFilterPolicy(10, 2));
@@ -937,7 +928,35 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
937
928
  } else if (optimize == "range-lookup") {
938
929
  // TODO?
939
930
  } else {
940
- tableOptions.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10));
931
+ return napi_invalid_arg;
932
+ }
933
+
934
+ std::string indexType;
935
+ NAPI_STATUS_RETURN(GetProperty(env, options, "indexType", indexType));
936
+ if (indexType == "") {
937
+ // Do nothing...
938
+ } else if (indexType == "binarySearch") {
939
+ tableOptions.index_type = rocksdb::BlockBasedTableOptions::kBinarySearch;
940
+ } else if (indexType == "hashSearch") {
941
+ tableOptions.index_type = rocksdb::BlockBasedTableOptions::kHashSearch;
942
+ } else if (indexType == "twoLevelIndexSearch") {
943
+ tableOptions.index_type = rocksdb::BlockBasedTableOptions::kTwoLevelIndexSearch;
944
+ } else if (indexType == "binarySearchWithFirstKey") {
945
+ tableOptions.index_type = rocksdb::BlockBasedTableOptions::kBinarySearchWithFirstKey;
946
+ } else {
947
+ return napi_invalid_arg;
948
+ }
949
+
950
+ std::string dataBlockIndexType;
951
+ NAPI_STATUS_RETURN(GetProperty(env, options, "dataBlockIndexType", dataBlockIndexType));
952
+ if (dataBlockIndexType == "") {
953
+ // Do nothing...
954
+ } else if (dataBlockIndexType == "dataBlockBinarySearch") {
955
+ tableOptions.data_block_index_type = rocksdb::BlockBasedTableOptions::kDataBlockBinarySearch;
956
+ } else if (dataBlockIndexType == "dataBlockBinaryAndHash") {
957
+ tableOptions.data_block_index_type = rocksdb::BlockBasedTableOptions::kDataBlockBinaryAndHash;
958
+ } else {
959
+ return napi_invalid_arg;
941
960
  }
942
961
 
943
962
  std::string filterPolicy;
@@ -947,31 +966,42 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
947
966
  rocksdb::FilterPolicy::CreateFromString(configOptions, filterPolicy, &tableOptions.filter_policy));
948
967
  }
949
968
 
950
- tableOptions.block_size = 4 * 1024;
951
- NAPI_STATUS_RETURN(GetProperty(env, options, "blockSize", tableOptions.block_size));
969
+ std::string indexShortening;
970
+ NAPI_STATUS_RETURN(GetProperty(env, options, "indexShortening", indexShortening));
971
+ if (indexShortening == "") {
972
+ // Do nothing..
973
+ } else if (indexShortening == "noShortening") {
974
+ tableOptions.index_shortening = rocksdb::BlockBasedTableOptions::IndexShorteningMode::kNoShortening;
975
+ } else if (indexShortening == "shortenSeparators") {
976
+ tableOptions.index_shortening = rocksdb::BlockBasedTableOptions::IndexShorteningMode::kShortenSeparators;
977
+ } else if (indexShortening == "shortenSeparatorsAndSuccessor") {
978
+ tableOptions.index_shortening = rocksdb::BlockBasedTableOptions::IndexShorteningMode::kShortenSeparatorsAndSuccessor;
979
+ } else {
980
+ return napi_invalid_arg;
981
+ }
952
982
 
953
- tableOptions.block_restart_interval = 16;
954
- NAPI_STATUS_RETURN(GetProperty(env, options, "blockRestartInterval", tableOptions.block_restart_interval));
983
+ std::string prepopulateBlockCache;
984
+ NAPI_STATUS_RETURN(GetProperty(env, options, "prepopulateBlockCache", prepopulateBlockCache));
985
+ if (prepopulateBlockCache == "") {
986
+ // Do nothing...
987
+ } else if (prepopulateBlockCache == "disable") {
988
+ tableOptions.prepopulate_block_cache = rocksdb::BlockBasedTableOptions::PrepopulateBlockCache::kDisable;
989
+ } else if (prepopulateBlockCache == "flushOnly") {
990
+ tableOptions.prepopulate_block_cache = rocksdb::BlockBasedTableOptions::PrepopulateBlockCache::kFlushOnly;
991
+ } else {
992
+ return napi_invalid_arg;
993
+ }
955
994
 
956
- tableOptions.block_align = false;
995
+ NAPI_STATUS_RETURN(GetProperty(env, options, "dataBlockHashTableUtilRatio", tableOptions.data_block_hash_table_util_ratio));
996
+ NAPI_STATUS_RETURN(GetProperty(env, options, "blockSize", tableOptions.block_size));
997
+ NAPI_STATUS_RETURN(GetProperty(env, options, "blockRestartInterval", tableOptions.block_restart_interval));
957
998
  NAPI_STATUS_RETURN(GetProperty(env, options, "blockAlign", tableOptions.block_align));
958
-
959
- tableOptions.cache_index_and_filter_blocks = false;
960
999
  NAPI_STATUS_RETURN(GetProperty(env, options, "cacheIndexAndFilterBlocks", tableOptions.cache_index_and_filter_blocks));
961
-
962
- tableOptions.cache_index_and_filter_blocks_with_high_priority = true;
963
1000
  NAPI_STATUS_RETURN(GetProperty(env, options, "cacheIndexAndFilterBlocksWithHighPriority", tableOptions.cache_index_and_filter_blocks_with_high_priority));
964
-
965
- tableOptions.decouple_partitioned_filters = true;
966
1001
  NAPI_STATUS_RETURN(GetProperty(env, options, "decouplePartitionedFilters", tableOptions.block_restart_interval));
967
-
968
- tableOptions.optimize_filters_for_memory = true;
969
1002
  NAPI_STATUS_RETURN(GetProperty(env, options, "optimizeFiltersForMemory", tableOptions.optimize_filters_for_memory));
970
-
971
- tableOptions.max_auto_readahead_size = 256 * 1024;
972
1003
  NAPI_STATUS_RETURN(GetProperty(env, options, "maxAutoReadaheadSize", tableOptions.max_auto_readahead_size));
973
-
974
- tableOptions.num_file_reads_for_auto_readahead = 2;
1004
+ NAPI_STATUS_RETURN(GetProperty(env, options, "initialAutoReadaheadSize", tableOptions.initial_auto_readahead_size));
975
1005
  NAPI_STATUS_RETURN(GetProperty(env, options, "numFileReadsForAutoReadahead", tableOptions.num_file_reads_for_auto_readahead));
976
1006
 
977
1007
  columnOptions.table_factory.reset(rocksdb::NewBlockBasedTableFactory(tableOptions));
package/binding.gyp CHANGED
@@ -10,7 +10,6 @@
10
10
  {
11
11
  "direct_dependent_settings": {
12
12
  "libraries": [
13
- "/usr/lib/x86_64-linux-gnu/libre2.a",
14
13
  ],
15
14
  },
16
15
  "include_dirs": [
@@ -29,12 +28,9 @@
29
28
  {
30
29
  "direct_dependent_settings": {
31
30
  "libraries": [
32
- "/opt/homebrew/Cellar/re2/20240702_1/lib/re2.a"
33
31
  ],
34
32
  },
35
33
  "include_dirs": [
36
- "/opt/homebrew/Cellar/re2/20240702_1/include",
37
- "/opt/homebrew/Cellar/abseil/20240722.0/include"
38
34
  ],
39
35
  "xcode_settings": {
40
36
  "WARNING_CFLAGS": [
@@ -93,8 +93,8 @@
93
93
  "USE_COROUTINES=1",
94
94
  "HAVE_UINT128_EXTENSION=1",
95
95
  "HAVE_ALIGNED_NEW=1",
96
- "ROCKSDB_JEMALLOC=1",
97
- "JEMALLOC_NO_DEMANGLE=1"
96
+ # "ROCKSDB_JEMALLOC=1",
97
+ # "JEMALLOC_NO_DEMANGLE=1"
98
98
  # "HAVE_FULLFSYNC=1",
99
99
  # "NUMA=1",
100
100
  ],
@@ -107,8 +107,8 @@
107
107
  "/usr/lib/x86_64-linux-gnu/libglog.a",
108
108
  "/usr/lib/x86_64-linux-gnu/libiberty.a",
109
109
  "/usr/lib/x86_64-linux-gnu/libunwind.a",
110
- "/usr/lib/x86_64-linux-gnu/libgflags.a",
111
- "/usr/lib/x86_64-linux-gnu/libjemalloc.a"
110
+ "/usr/lib/x86_64-linux-gnu/libgflags.a"
111
+ # "/usr/lib/x86_64-linux-gnu/libjemalloc.a"
112
112
  ],
113
113
  },
114
114
  "include_dirs": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "13.1.0",
3
+ "version": "13.1.2",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
package/util.h CHANGED
@@ -244,6 +244,12 @@ static napi_status GetValue(napi_env env, napi_value value, unsigned long long&
244
244
  return napi_ok;
245
245
  }
246
246
 
247
+ static napi_status GetValue(napi_env env, napi_value value, double& result) {
248
+ NAPI_STATUS_RETURN(napi_get_value_double(env, value, &result));
249
+ return napi_ok;
250
+ }
251
+
252
+
247
253
  static napi_status GetValue(napi_env env, napi_value value, std::string& result) {
248
254
  return GetString(env, value, result);
249
255
  }
package/prebuilds.zip DELETED
Binary file