@nxtedition/rocksdb 7.0.7 → 7.0.10
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,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); \
|
|
@@ -187,6 +198,8 @@ static napi_value ToError(napi_env env, const rocksdb::Status& status) {
|
|
|
187
198
|
return CreateError(env, "LEVEL_NOT_FOUND", msg);
|
|
188
199
|
} else if (status.IsCorruption()) {
|
|
189
200
|
return CreateError(env, "LEVEL_CORRUPTION", msg);
|
|
201
|
+
} else if (status.IsTryAgain()) {
|
|
202
|
+
return CreateError(env, "LEVEL_TRYAGAIN", msg);
|
|
190
203
|
} else if (status.IsIOError()) {
|
|
191
204
|
if (msg.find("IO error: lock ") != std::string::npos) { // env_posix.cc
|
|
192
205
|
return CreateError(env, "LEVEL_LOCKED", msg);
|
|
@@ -676,7 +689,7 @@ struct OpenWorker final : public Worker {
|
|
|
676
689
|
};
|
|
677
690
|
|
|
678
691
|
template <typename T, typename U>
|
|
679
|
-
|
|
692
|
+
rocksdb::Status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
680
693
|
const auto memtable_memory_budget = Uint32Property(env, options, "memtableMemoryBudget").value_or(256 * 1024 * 1024);
|
|
681
694
|
|
|
682
695
|
const auto compaction = StringProperty(env, options, "compaction").value_or("level");
|
|
@@ -720,6 +733,20 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
720
733
|
// TODO (perf): compression_opts.parallel_threads
|
|
721
734
|
}
|
|
722
735
|
|
|
736
|
+
const auto prefixExtractorOpt = StringProperty(env, options, "prefixExtractor");
|
|
737
|
+
if (prefixExtractorOpt) {
|
|
738
|
+
rocksdb::ConfigOptions configOptions;
|
|
739
|
+
ROCKS_STATUS_RETURN(
|
|
740
|
+
rocksdb::SliceTransform::CreateFromString(configOptions, *prefixExtractorOpt, &columnOptions.prefix_extractor));
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
const auto comparatorOpt = StringProperty(env, options, "comparator");
|
|
744
|
+
if (comparatorOpt) {
|
|
745
|
+
rocksdb::ConfigOptions configOptions;
|
|
746
|
+
ROCKS_STATUS_RETURN(
|
|
747
|
+
rocksdb::Comparator::CreateFromString(configOptions, *comparatorOpt, &columnOptions.comparator));
|
|
748
|
+
}
|
|
749
|
+
|
|
723
750
|
const auto cacheSize = Uint32Property(env, options, "cacheSize").value_or(8 << 20);
|
|
724
751
|
|
|
725
752
|
rocksdb::BlockBasedTableOptions tableOptions;
|
|
@@ -748,6 +775,13 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
748
775
|
tableOptions.filter_policy.reset(rocksdb::NewRibbonFilterPolicy(10));
|
|
749
776
|
}
|
|
750
777
|
|
|
778
|
+
const auto filterPolicyOpt = StringProperty(env, options, "filterPolicy");
|
|
779
|
+
if (filterPolicyOpt) {
|
|
780
|
+
rocksdb::ConfigOptions configOptions;
|
|
781
|
+
ROCKS_STATUS_RETURN(
|
|
782
|
+
rocksdb::FilterPolicy::CreateFromString(configOptions, *filterPolicyOpt, &tableOptions.filter_policy));
|
|
783
|
+
}
|
|
784
|
+
|
|
751
785
|
tableOptions.block_size = Uint32Property(env, options, "blockSize").value_or(4096);
|
|
752
786
|
tableOptions.block_restart_interval = Uint32Property(env, options, "blockRestartInterval").value_or(16);
|
|
753
787
|
tableOptions.format_version = 5;
|
|
@@ -756,7 +790,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
756
790
|
|
|
757
791
|
columnOptions.table_factory.reset(rocksdb::NewBlockBasedTableFactory(tableOptions));
|
|
758
792
|
|
|
759
|
-
return
|
|
793
|
+
return rocksdb::Status::OK();
|
|
760
794
|
}
|
|
761
795
|
|
|
762
796
|
NAPI_METHOD(db_open) {
|
|
@@ -776,6 +810,7 @@ NAPI_METHOD(db_open) {
|
|
|
776
810
|
dbOptions.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
|
|
777
811
|
dbOptions.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
|
|
778
812
|
dbOptions.avoid_unnecessary_blocking_io = true;
|
|
813
|
+
dbOptions.write_dbid_to_manifest = true;
|
|
779
814
|
dbOptions.use_adaptive_mutex = true; // We don't have soo many threads in the libuv thread pool...
|
|
780
815
|
dbOptions.enable_pipelined_write = false; // We only write in the main thread...
|
|
781
816
|
dbOptions.max_background_jobs = Uint32Property(env, argv[2], "maxBackgroundJobs")
|
|
@@ -784,6 +819,12 @@ NAPI_METHOD(db_open) {
|
|
|
784
819
|
dbOptions.WAL_size_limit_MB = Uint32Property(env, argv[2], "walSizeLimit").value_or(0) / 1e6;
|
|
785
820
|
dbOptions.create_missing_column_families = true;
|
|
786
821
|
dbOptions.unordered_write = BooleanProperty(env, argv[2], "unorderedWrite").value_or(false);
|
|
822
|
+
dbOptions.fail_if_options_file_error = true;
|
|
823
|
+
dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
|
|
824
|
+
? rocksdb::CompressionType::kZSTD
|
|
825
|
+
: rocksdb::CompressionType::kNoCompression;
|
|
826
|
+
|
|
827
|
+
// TODO (feat): dbOptions.listeners
|
|
787
828
|
|
|
788
829
|
const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
|
|
789
830
|
if (infoLogLevel.size() > 0) {
|
|
@@ -812,7 +853,7 @@ NAPI_METHOD(db_open) {
|
|
|
812
853
|
dbOptions.info_log.reset(new NullLogger());
|
|
813
854
|
}
|
|
814
855
|
|
|
815
|
-
|
|
856
|
+
ROCKS_STATUS_THROWS(InitOptions(env, dbOptions, argv[2]));
|
|
816
857
|
|
|
817
858
|
std::vector<rocksdb::ColumnFamilyDescriptor> columnsFamilies;
|
|
818
859
|
|
|
@@ -837,7 +878,7 @@ NAPI_METHOD(db_open) {
|
|
|
837
878
|
napi_value column;
|
|
838
879
|
NAPI_STATUS_THROWS(napi_get_property(env, columns, key, &column));
|
|
839
880
|
|
|
840
|
-
|
|
881
|
+
ROCKS_STATUS_THROWS(InitOptions(env, columnsFamilies[n].options, column));
|
|
841
882
|
|
|
842
883
|
NAPI_STATUS_THROWS(ToString(env, key, columnsFamilies[n].name));
|
|
843
884
|
}
|
|
@@ -1112,22 +1153,30 @@ struct GetManyWorker final : public Worker {
|
|
|
1112
1153
|
std::vector<std::string> keys,
|
|
1113
1154
|
napi_value callback,
|
|
1114
1155
|
const bool valueAsBuffer,
|
|
1115
|
-
const bool fillCache
|
|
1156
|
+
const bool fillCache,
|
|
1157
|
+
const bool ignoreRangeDeletions)
|
|
1116
1158
|
: Worker(env, database, callback, "leveldown.get.many"),
|
|
1117
1159
|
column_(column),
|
|
1118
1160
|
keys_(std::move(keys)),
|
|
1119
1161
|
valueAsBuffer_(valueAsBuffer),
|
|
1120
1162
|
fillCache_(fillCache),
|
|
1121
|
-
|
|
1163
|
+
ignoreRangeDeletions_(ignoreRangeDeletions),
|
|
1164
|
+
snapshot_(database_->db_->GetSnapshot()) {
|
|
1122
1165
|
database_->IncrementPriorityWork(env);
|
|
1123
1166
|
}
|
|
1124
1167
|
|
|
1168
|
+
~GetManyWorker() {
|
|
1169
|
+
if (snapshot_) {
|
|
1170
|
+
database_->db_->ReleaseSnapshot(snapshot_);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1125
1174
|
rocksdb::Status Execute(Database& database) override {
|
|
1126
1175
|
rocksdb::ReadOptions readOptions;
|
|
1127
1176
|
readOptions.fill_cache = fillCache_;
|
|
1128
|
-
readOptions.snapshot = snapshot_
|
|
1177
|
+
readOptions.snapshot = snapshot_;
|
|
1129
1178
|
readOptions.async_io = true;
|
|
1130
|
-
readOptions.
|
|
1179
|
+
readOptions.ignore_range_deletions = ignoreRangeDeletions_;
|
|
1131
1180
|
|
|
1132
1181
|
std::vector<rocksdb::Slice> keys;
|
|
1133
1182
|
keys.reserve(keys_.size());
|
|
@@ -1182,7 +1231,8 @@ struct GetManyWorker final : public Worker {
|
|
|
1182
1231
|
std::vector<rocksdb::Status> statuses_;
|
|
1183
1232
|
const bool valueAsBuffer_;
|
|
1184
1233
|
const bool fillCache_;
|
|
1185
|
-
|
|
1234
|
+
const bool ignoreRangeDeletions_;
|
|
1235
|
+
const rocksdb::Snapshot* snapshot_;
|
|
1186
1236
|
};
|
|
1187
1237
|
|
|
1188
1238
|
NAPI_METHOD(db_get_many) {
|
|
@@ -1206,11 +1256,13 @@ NAPI_METHOD(db_get_many) {
|
|
|
1206
1256
|
|
|
1207
1257
|
const bool asBuffer = EncodingIsBuffer(env, argv[2], "valueEncoding");
|
|
1208
1258
|
const bool fillCache = BooleanProperty(env, argv[2], "fillCache").value_or(true);
|
|
1259
|
+
const bool ignoreRangeDeletions = BooleanProperty(env, argv[2], "ignoreRangeDeletions").value_or(false);
|
|
1209
1260
|
|
|
1210
1261
|
rocksdb::ColumnFamilyHandle* column;
|
|
1211
1262
|
NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[2], &column));
|
|
1212
1263
|
|
|
1213
|
-
auto worker =
|
|
1264
|
+
auto worker =
|
|
1265
|
+
new GetManyWorker(env, database, column, std::move(keys), argv[3], asBuffer, fillCache, ignoreRangeDeletions);
|
|
1214
1266
|
worker->Queue(env);
|
|
1215
1267
|
|
|
1216
1268
|
return 0;
|
|
@@ -1421,7 +1473,7 @@ NAPI_METHOD(iterator_get_sequence) {
|
|
|
1421
1473
|
napi_value result;
|
|
1422
1474
|
NAPI_STATUS_THROWS(napi_create_bigint_int64(env, seq, &result));
|
|
1423
1475
|
|
|
1424
|
-
return
|
|
1476
|
+
return result;
|
|
1425
1477
|
}
|
|
1426
1478
|
|
|
1427
1479
|
struct NextWorker final : public Worker {
|
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
|
|
Binary file
|