@nxtedition/rocksdb 7.0.7 → 7.0.8

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
@@ -6,10 +6,12 @@
6
6
 
7
7
  #include <rocksdb/cache.h>
8
8
  #include <rocksdb/comparator.h>
9
+ #include <rocksdb/convenience.h>
9
10
  #include <rocksdb/db.h>
10
11
  #include <rocksdb/env.h>
11
12
  #include <rocksdb/filter_policy.h>
12
13
  #include <rocksdb/options.h>
14
+ #include <rocksdb/slice_transform.h>
13
15
  #include <rocksdb/table.h>
14
16
  #include <rocksdb/write_batch.h>
15
17
 
@@ -40,6 +42,14 @@ struct Updates;
40
42
  } \
41
43
  }
42
44
 
45
+ #define ROCKS_STATUS_RETURN(call) \
46
+ { \
47
+ auto _status = (call); \
48
+ if (!_status.ok()) { \
49
+ return _status; \
50
+ } \
51
+ }
52
+
43
53
  #define ROCKS_STATUS_THROWS(call) \
44
54
  { \
45
55
  auto _status = (call); \
@@ -676,7 +686,7 @@ struct OpenWorker final : public Worker {
676
686
  };
677
687
 
678
688
  template <typename T, typename U>
679
- napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
689
+ rocksdb::Status InitOptions(napi_env env, T& columnOptions, const U& options) {
680
690
  const auto memtable_memory_budget = Uint32Property(env, options, "memtableMemoryBudget").value_or(256 * 1024 * 1024);
681
691
 
682
692
  const auto compaction = StringProperty(env, options, "compaction").value_or("level");
@@ -720,6 +730,20 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
720
730
  // TODO (perf): compression_opts.parallel_threads
721
731
  }
722
732
 
733
+ const auto prefixExtractorOpt = StringProperty(env, options, "prefixExtractor");
734
+ if (prefixExtractorOpt) {
735
+ rocksdb::ConfigOptions configOptions;
736
+ ROCKS_STATUS_RETURN(
737
+ rocksdb::SliceTransform::CreateFromString(configOptions, *prefixExtractorOpt, &columnOptions.prefix_extractor));
738
+ }
739
+
740
+ const auto comparatorOpt = StringProperty(env, options, "comparator");
741
+ if (comparatorOpt) {
742
+ rocksdb::ConfigOptions configOptions;
743
+ ROCKS_STATUS_RETURN(
744
+ rocksdb::Comparator::CreateFromString(configOptions, *comparatorOpt, &columnOptions.comparator));
745
+ }
746
+
723
747
  const auto cacheSize = Uint32Property(env, options, "cacheSize").value_or(8 << 20);
724
748
 
725
749
  rocksdb::BlockBasedTableOptions tableOptions;
@@ -756,7 +780,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
756
780
 
757
781
  columnOptions.table_factory.reset(rocksdb::NewBlockBasedTableFactory(tableOptions));
758
782
 
759
- return napi_ok;
783
+ return rocksdb::Status::OK();
760
784
  }
761
785
 
762
786
  NAPI_METHOD(db_open) {
@@ -776,6 +800,7 @@ NAPI_METHOD(db_open) {
776
800
  dbOptions.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
777
801
  dbOptions.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
778
802
  dbOptions.avoid_unnecessary_blocking_io = true;
803
+ dbOptions.write_dbid_to_manifest = true;
779
804
  dbOptions.use_adaptive_mutex = true; // We don't have soo many threads in the libuv thread pool...
780
805
  dbOptions.enable_pipelined_write = false; // We only write in the main thread...
781
806
  dbOptions.max_background_jobs = Uint32Property(env, argv[2], "maxBackgroundJobs")
@@ -784,6 +809,12 @@ NAPI_METHOD(db_open) {
784
809
  dbOptions.WAL_size_limit_MB = Uint32Property(env, argv[2], "walSizeLimit").value_or(0) / 1e6;
785
810
  dbOptions.create_missing_column_families = true;
786
811
  dbOptions.unordered_write = BooleanProperty(env, argv[2], "unorderedWrite").value_or(false);
812
+ dbOptions.fail_if_options_file_error = true;
813
+ dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
814
+ ? rocksdb::CompressionType::kZSTD
815
+ : rocksdb::CompressionType::kNoCompression;
816
+
817
+ // TODO (feat): dbOptions.listeners
787
818
 
788
819
  const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
789
820
  if (infoLogLevel.size() > 0) {
@@ -812,7 +843,7 @@ NAPI_METHOD(db_open) {
812
843
  dbOptions.info_log.reset(new NullLogger());
813
844
  }
814
845
 
815
- NAPI_STATUS_THROWS(InitOptions(env, dbOptions, argv[2]));
846
+ ROCKS_STATUS_THROWS(InitOptions(env, dbOptions, argv[2]));
816
847
 
817
848
  std::vector<rocksdb::ColumnFamilyDescriptor> columnsFamilies;
818
849
 
@@ -837,7 +868,7 @@ NAPI_METHOD(db_open) {
837
868
  napi_value column;
838
869
  NAPI_STATUS_THROWS(napi_get_property(env, columns, key, &column));
839
870
 
840
- NAPI_STATUS_THROWS(InitOptions(env, columnsFamilies[n].options, column));
871
+ ROCKS_STATUS_THROWS(InitOptions(env, columnsFamilies[n].options, column));
841
872
 
842
873
  NAPI_STATUS_THROWS(ToString(env, key, columnsFamilies[n].name));
843
874
  }
@@ -1112,22 +1143,26 @@ struct GetManyWorker final : public Worker {
1112
1143
  std::vector<std::string> keys,
1113
1144
  napi_value callback,
1114
1145
  const bool valueAsBuffer,
1115
- const bool fillCache)
1146
+ const bool fillCache,
1147
+ const bool ignoreRangeDeletions)
1116
1148
  : Worker(env, database, callback, "leveldown.get.many"),
1117
1149
  column_(column),
1118
1150
  keys_(std::move(keys)),
1119
1151
  valueAsBuffer_(valueAsBuffer),
1120
1152
  fillCache_(fillCache),
1121
- snapshot_(database_->db_->GetSnapshot(), [=](const auto ptr) { database_->db_->ReleaseSnapshot(ptr); }) {
1153
+ ignoreRangeDeletions_(ignoreRangeDeletions),
1154
+ snapshot_(database_->db_->GetSnapshot()) {
1122
1155
  database_->IncrementPriorityWork(env);
1123
1156
  }
1124
1157
 
1158
+ ~GetManyWorker() { database_->db_->ReleaseSnapshot(snapshot_); }
1159
+
1125
1160
  rocksdb::Status Execute(Database& database) override {
1126
1161
  rocksdb::ReadOptions readOptions;
1127
1162
  readOptions.fill_cache = fillCache_;
1128
- readOptions.snapshot = snapshot_.get();
1163
+ readOptions.snapshot = snapshot_;
1129
1164
  readOptions.async_io = true;
1130
- readOptions.adaptive_readahead = true;
1165
+ readOptions.ignore_range_deletions = ignoreRangeDeletions_;
1131
1166
 
1132
1167
  std::vector<rocksdb::Slice> keys;
1133
1168
  keys.reserve(keys_.size());
@@ -1182,7 +1217,8 @@ struct GetManyWorker final : public Worker {
1182
1217
  std::vector<rocksdb::Status> statuses_;
1183
1218
  const bool valueAsBuffer_;
1184
1219
  const bool fillCache_;
1185
- std::shared_ptr<const rocksdb::Snapshot> snapshot_;
1220
+ const bool ignoreRangeDeletions_;
1221
+ const rocksdb::Snapshot* snapshot_;
1186
1222
  };
1187
1223
 
1188
1224
  NAPI_METHOD(db_get_many) {
@@ -1206,11 +1242,13 @@ NAPI_METHOD(db_get_many) {
1206
1242
 
1207
1243
  const bool asBuffer = EncodingIsBuffer(env, argv[2], "valueEncoding");
1208
1244
  const bool fillCache = BooleanProperty(env, argv[2], "fillCache").value_or(true);
1245
+ const bool ignoreRangeDeletions = BooleanProperty(env, argv[2], "ignoreRangeDeletions").value_or(false);
1209
1246
 
1210
1247
  rocksdb::ColumnFamilyHandle* column;
1211
1248
  NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[2], &column));
1212
1249
 
1213
- auto worker = new GetManyWorker(env, database, column, std::move(keys), argv[3], asBuffer, fillCache);
1250
+ auto worker =
1251
+ new GetManyWorker(env, database, column, std::move(keys), argv[3], asBuffer, fillCache, ignoreRangeDeletions);
1214
1252
  worker->Queue(env);
1215
1253
 
1216
1254
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "7.0.7",
3
+ "version": "7.0.8",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
Binary file