@nxtedition/rocksdb 7.0.6 → 7.0.9
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 +60 -10
- package/index.js +1 -1
- package/iterator.js +4 -0
- package/package.json +1 -1
- package/prebuilds/darwin-x64/node.napi.node +0 -0
package/binding.cc
CHANGED
|
@@ -6,12 +6,15 @@
|
|
|
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>
|
|
17
|
+
#include <rocksdb/filter_policy.h>
|
|
15
18
|
|
|
16
19
|
#include <array>
|
|
17
20
|
#include <memory>
|
|
@@ -40,6 +43,14 @@ struct Updates;
|
|
|
40
43
|
} \
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
#define ROCKS_STATUS_RETURN(call) \
|
|
47
|
+
{ \
|
|
48
|
+
auto _status = (call); \
|
|
49
|
+
if (!_status.ok()) { \
|
|
50
|
+
return _status; \
|
|
51
|
+
} \
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
#define ROCKS_STATUS_THROWS(call) \
|
|
44
55
|
{ \
|
|
45
56
|
auto _status = (call); \
|
|
@@ -676,7 +687,7 @@ struct OpenWorker final : public Worker {
|
|
|
676
687
|
};
|
|
677
688
|
|
|
678
689
|
template <typename T, typename U>
|
|
679
|
-
|
|
690
|
+
rocksdb::Status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
680
691
|
const auto memtable_memory_budget = Uint32Property(env, options, "memtableMemoryBudget").value_or(256 * 1024 * 1024);
|
|
681
692
|
|
|
682
693
|
const auto compaction = StringProperty(env, options, "compaction").value_or("level");
|
|
@@ -720,6 +731,20 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
720
731
|
// TODO (perf): compression_opts.parallel_threads
|
|
721
732
|
}
|
|
722
733
|
|
|
734
|
+
const auto prefixExtractorOpt = StringProperty(env, options, "prefixExtractor");
|
|
735
|
+
if (prefixExtractorOpt) {
|
|
736
|
+
rocksdb::ConfigOptions configOptions;
|
|
737
|
+
ROCKS_STATUS_RETURN(
|
|
738
|
+
rocksdb::SliceTransform::CreateFromString(configOptions, *prefixExtractorOpt, &columnOptions.prefix_extractor));
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
const auto comparatorOpt = StringProperty(env, options, "comparator");
|
|
742
|
+
if (comparatorOpt) {
|
|
743
|
+
rocksdb::ConfigOptions configOptions;
|
|
744
|
+
ROCKS_STATUS_RETURN(
|
|
745
|
+
rocksdb::Comparator::CreateFromString(configOptions, *comparatorOpt, &columnOptions.comparator));
|
|
746
|
+
}
|
|
747
|
+
|
|
723
748
|
const auto cacheSize = Uint32Property(env, options, "cacheSize").value_or(8 << 20);
|
|
724
749
|
|
|
725
750
|
rocksdb::BlockBasedTableOptions tableOptions;
|
|
@@ -748,6 +773,13 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
748
773
|
tableOptions.filter_policy.reset(rocksdb::NewRibbonFilterPolicy(10));
|
|
749
774
|
}
|
|
750
775
|
|
|
776
|
+
const auto filterPolicyOpt = StringProperty(env, options, "filterPolicy");
|
|
777
|
+
if (filterPolicyOpt) {
|
|
778
|
+
rocksdb::ConfigOptions configOptions;
|
|
779
|
+
ROCKS_STATUS_RETURN(
|
|
780
|
+
rocksdb::FilterPolicy::CreateFromString(configOptions, *filterPolicyOpt, &tableOptions.filter_policy));
|
|
781
|
+
}
|
|
782
|
+
|
|
751
783
|
tableOptions.block_size = Uint32Property(env, options, "blockSize").value_or(4096);
|
|
752
784
|
tableOptions.block_restart_interval = Uint32Property(env, options, "blockRestartInterval").value_or(16);
|
|
753
785
|
tableOptions.format_version = 5;
|
|
@@ -756,7 +788,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
756
788
|
|
|
757
789
|
columnOptions.table_factory.reset(rocksdb::NewBlockBasedTableFactory(tableOptions));
|
|
758
790
|
|
|
759
|
-
return
|
|
791
|
+
return rocksdb::Status::OK();
|
|
760
792
|
}
|
|
761
793
|
|
|
762
794
|
NAPI_METHOD(db_open) {
|
|
@@ -776,6 +808,7 @@ NAPI_METHOD(db_open) {
|
|
|
776
808
|
dbOptions.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
|
|
777
809
|
dbOptions.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
|
|
778
810
|
dbOptions.avoid_unnecessary_blocking_io = true;
|
|
811
|
+
dbOptions.write_dbid_to_manifest = true;
|
|
779
812
|
dbOptions.use_adaptive_mutex = true; // We don't have soo many threads in the libuv thread pool...
|
|
780
813
|
dbOptions.enable_pipelined_write = false; // We only write in the main thread...
|
|
781
814
|
dbOptions.max_background_jobs = Uint32Property(env, argv[2], "maxBackgroundJobs")
|
|
@@ -784,6 +817,12 @@ NAPI_METHOD(db_open) {
|
|
|
784
817
|
dbOptions.WAL_size_limit_MB = Uint32Property(env, argv[2], "walSizeLimit").value_or(0) / 1e6;
|
|
785
818
|
dbOptions.create_missing_column_families = true;
|
|
786
819
|
dbOptions.unordered_write = BooleanProperty(env, argv[2], "unorderedWrite").value_or(false);
|
|
820
|
+
dbOptions.fail_if_options_file_error = true;
|
|
821
|
+
dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
|
|
822
|
+
? rocksdb::CompressionType::kZSTD
|
|
823
|
+
: rocksdb::CompressionType::kNoCompression;
|
|
824
|
+
|
|
825
|
+
// TODO (feat): dbOptions.listeners
|
|
787
826
|
|
|
788
827
|
const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
|
|
789
828
|
if (infoLogLevel.size() > 0) {
|
|
@@ -812,7 +851,7 @@ NAPI_METHOD(db_open) {
|
|
|
812
851
|
dbOptions.info_log.reset(new NullLogger());
|
|
813
852
|
}
|
|
814
853
|
|
|
815
|
-
|
|
854
|
+
ROCKS_STATUS_THROWS(InitOptions(env, dbOptions, argv[2]));
|
|
816
855
|
|
|
817
856
|
std::vector<rocksdb::ColumnFamilyDescriptor> columnsFamilies;
|
|
818
857
|
|
|
@@ -837,7 +876,7 @@ NAPI_METHOD(db_open) {
|
|
|
837
876
|
napi_value column;
|
|
838
877
|
NAPI_STATUS_THROWS(napi_get_property(env, columns, key, &column));
|
|
839
878
|
|
|
840
|
-
|
|
879
|
+
ROCKS_STATUS_THROWS(InitOptions(env, columnsFamilies[n].options, column));
|
|
841
880
|
|
|
842
881
|
NAPI_STATUS_THROWS(ToString(env, key, columnsFamilies[n].name));
|
|
843
882
|
}
|
|
@@ -1112,22 +1151,30 @@ struct GetManyWorker final : public Worker {
|
|
|
1112
1151
|
std::vector<std::string> keys,
|
|
1113
1152
|
napi_value callback,
|
|
1114
1153
|
const bool valueAsBuffer,
|
|
1115
|
-
const bool fillCache
|
|
1154
|
+
const bool fillCache,
|
|
1155
|
+
const bool ignoreRangeDeletions)
|
|
1116
1156
|
: Worker(env, database, callback, "leveldown.get.many"),
|
|
1117
1157
|
column_(column),
|
|
1118
1158
|
keys_(std::move(keys)),
|
|
1119
1159
|
valueAsBuffer_(valueAsBuffer),
|
|
1120
1160
|
fillCache_(fillCache),
|
|
1121
|
-
|
|
1161
|
+
ignoreRangeDeletions_(ignoreRangeDeletions),
|
|
1162
|
+
snapshot_(database_->db_->GetSnapshot()) {
|
|
1122
1163
|
database_->IncrementPriorityWork(env);
|
|
1123
1164
|
}
|
|
1124
1165
|
|
|
1166
|
+
~GetManyWorker() {
|
|
1167
|
+
if (snapshot_) {
|
|
1168
|
+
database_->db_->ReleaseSnapshot(snapshot_);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1125
1172
|
rocksdb::Status Execute(Database& database) override {
|
|
1126
1173
|
rocksdb::ReadOptions readOptions;
|
|
1127
1174
|
readOptions.fill_cache = fillCache_;
|
|
1128
|
-
readOptions.snapshot = snapshot_
|
|
1175
|
+
readOptions.snapshot = snapshot_;
|
|
1129
1176
|
readOptions.async_io = true;
|
|
1130
|
-
readOptions.
|
|
1177
|
+
readOptions.ignore_range_deletions = ignoreRangeDeletions_;
|
|
1131
1178
|
|
|
1132
1179
|
std::vector<rocksdb::Slice> keys;
|
|
1133
1180
|
keys.reserve(keys_.size());
|
|
@@ -1182,7 +1229,8 @@ struct GetManyWorker final : public Worker {
|
|
|
1182
1229
|
std::vector<rocksdb::Status> statuses_;
|
|
1183
1230
|
const bool valueAsBuffer_;
|
|
1184
1231
|
const bool fillCache_;
|
|
1185
|
-
|
|
1232
|
+
const bool ignoreRangeDeletions_;
|
|
1233
|
+
const rocksdb::Snapshot* snapshot_;
|
|
1186
1234
|
};
|
|
1187
1235
|
|
|
1188
1236
|
NAPI_METHOD(db_get_many) {
|
|
@@ -1206,11 +1254,13 @@ NAPI_METHOD(db_get_many) {
|
|
|
1206
1254
|
|
|
1207
1255
|
const bool asBuffer = EncodingIsBuffer(env, argv[2], "valueEncoding");
|
|
1208
1256
|
const bool fillCache = BooleanProperty(env, argv[2], "fillCache").value_or(true);
|
|
1257
|
+
const bool ignoreRangeDeletions = BooleanProperty(env, argv[2], "ignoreRangeDeletions").value_or(false);
|
|
1209
1258
|
|
|
1210
1259
|
rocksdb::ColumnFamilyHandle* column;
|
|
1211
1260
|
NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[2], &column));
|
|
1212
1261
|
|
|
1213
|
-
auto worker =
|
|
1262
|
+
auto worker =
|
|
1263
|
+
new GetManyWorker(env, database, column, std::move(keys), argv[3], asBuffer, fillCache, ignoreRangeDeletions);
|
|
1214
1264
|
worker->Queue(env);
|
|
1215
1265
|
|
|
1216
1266
|
return 0;
|
package/index.js
CHANGED
|
@@ -160,7 +160,7 @@ class RocksLevel extends AbstractLevel {
|
|
|
160
160
|
this.attachResource(resource)
|
|
161
161
|
|
|
162
162
|
const limit = options.limit ?? 1000
|
|
163
|
-
await new Promise((resolve, reject) => binding.iterator_nextv(context, limit, (err, rows, finished) => {
|
|
163
|
+
return await new Promise((resolve, reject) => binding.iterator_nextv(context, limit, (err, rows, finished) => {
|
|
164
164
|
if (err) {
|
|
165
165
|
reject(err)
|
|
166
166
|
} else {
|
package/iterator.js
CHANGED
|
@@ -29,6 +29,10 @@ class Iterator extends AbstractIterator {
|
|
|
29
29
|
this[kPosition] = 0
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
get sequence () {
|
|
33
|
+
return binding.iterator_get_sequence(this[kContext])
|
|
34
|
+
}
|
|
35
|
+
|
|
32
36
|
_seek (target) {
|
|
33
37
|
if (target.length === 0) {
|
|
34
38
|
throw new Error('cannot seek() to an empty target')
|
package/package.json
CHANGED
|
Binary file
|