@nxtedition/rocksdb 7.0.31 → 7.0.34
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 +23 -57
- package/index.js +27 -7
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.node +0 -0
package/binding.cc
CHANGED
|
@@ -544,7 +544,13 @@ struct Updates {
|
|
|
544
544
|
bool values,
|
|
545
545
|
bool data,
|
|
546
546
|
const rocksdb::ColumnFamilyHandle* column)
|
|
547
|
-
: database_(database),
|
|
547
|
+
: database_(database),
|
|
548
|
+
sequence_(seqNumber),
|
|
549
|
+
start_(seqNumber),
|
|
550
|
+
keys_(keys),
|
|
551
|
+
values_(values),
|
|
552
|
+
data_(data),
|
|
553
|
+
column_(column) {}
|
|
548
554
|
|
|
549
555
|
void Close() { iterator_.reset(); }
|
|
550
556
|
|
|
@@ -561,7 +567,8 @@ struct Updates {
|
|
|
561
567
|
}
|
|
562
568
|
|
|
563
569
|
Database* database_;
|
|
564
|
-
int64_t
|
|
570
|
+
int64_t sequence_;
|
|
571
|
+
int64_t start_;
|
|
565
572
|
std::unique_ptr<rocksdb::TransactionLogIterator> iterator_;
|
|
566
573
|
bool keys_;
|
|
567
574
|
bool values_;
|
|
@@ -814,9 +821,8 @@ NAPI_METHOD(db_open) {
|
|
|
814
821
|
|
|
815
822
|
rocksdb::Options dbOptions;
|
|
816
823
|
|
|
817
|
-
|
|
818
|
-
.value_or(std::max<uint32_t>(1, std::thread::hardware_concurrency() / 2));
|
|
819
|
-
dbOptions.IncreaseParallelism(parallelismValue);
|
|
824
|
+
dbOptions.IncreaseParallelism(Uint32Property(env, argv[2], "parallelism")
|
|
825
|
+
.value_or(std::max<uint32_t>(1, std::thread::hardware_concurrency() / 2)));
|
|
820
826
|
|
|
821
827
|
dbOptions.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
|
|
822
828
|
dbOptions.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
|
|
@@ -824,8 +830,6 @@ NAPI_METHOD(db_open) {
|
|
|
824
830
|
dbOptions.write_dbid_to_manifest = true;
|
|
825
831
|
dbOptions.use_adaptive_mutex = true; // We don't have soo many threads in the libuv thread pool...
|
|
826
832
|
dbOptions.enable_pipelined_write = false; // We only write in the main thread...
|
|
827
|
-
dbOptions.max_background_jobs = Uint32Property(env, argv[2], "maxBackgroundJobs")
|
|
828
|
-
.value_or(std::max<uint32_t>(2, std::thread::hardware_concurrency() / 8));
|
|
829
833
|
dbOptions.WAL_ttl_seconds = Uint32Property(env, argv[2], "walTTL").value_or(0) / 1e3;
|
|
830
834
|
dbOptions.WAL_size_limit_MB = Uint32Property(env, argv[2], "walSizeLimit").value_or(0) / 1e6;
|
|
831
835
|
dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
|
|
@@ -836,46 +840,6 @@ NAPI_METHOD(db_open) {
|
|
|
836
840
|
dbOptions.fail_if_options_file_error = true;
|
|
837
841
|
dbOptions.manual_wal_flush = BooleanProperty(env, argv[2], "manualWalFlush").value_or(false);
|
|
838
842
|
|
|
839
|
-
napi_value ret;
|
|
840
|
-
NAPI_STATUS_THROWS(napi_create_object(env, &ret));
|
|
841
|
-
{
|
|
842
|
-
napi_value parallelism;
|
|
843
|
-
NAPI_STATUS_THROWS(napi_create_int64(env, parallelismValue, ¶llelism));
|
|
844
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "parallelism", parallelism));
|
|
845
|
-
|
|
846
|
-
napi_value createIfMissing;
|
|
847
|
-
NAPI_STATUS_THROWS(napi_get_boolean(env, dbOptions.create_if_missing, &createIfMissing));
|
|
848
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "createIfMissing", createIfMissing));
|
|
849
|
-
|
|
850
|
-
napi_value errorIfExists;
|
|
851
|
-
NAPI_STATUS_THROWS(napi_get_boolean(env, dbOptions.error_if_exists, &errorIfExists));
|
|
852
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "errorIfExists", errorIfExists));
|
|
853
|
-
|
|
854
|
-
napi_value maxBackgroundJobs;
|
|
855
|
-
NAPI_STATUS_THROWS(napi_create_int64(env, dbOptions.max_background_jobs, &maxBackgroundJobs));
|
|
856
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "maxBackgroundJobs", maxBackgroundJobs));
|
|
857
|
-
|
|
858
|
-
napi_value walTTL;
|
|
859
|
-
NAPI_STATUS_THROWS(napi_create_int64(env, dbOptions.WAL_ttl_seconds * 1e3, &walTTL));
|
|
860
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "walTTL", walTTL));
|
|
861
|
-
|
|
862
|
-
napi_value walSizeLimit;
|
|
863
|
-
NAPI_STATUS_THROWS(napi_create_int64(env, dbOptions.WAL_size_limit_MB * 1e6, &walSizeLimit));
|
|
864
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "walSizeLimit", walSizeLimit));
|
|
865
|
-
|
|
866
|
-
napi_value walCompression;
|
|
867
|
-
NAPI_STATUS_THROWS(napi_create_int64(env, dbOptions.wal_compression, &walCompression));
|
|
868
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "walCompression", walCompression));
|
|
869
|
-
|
|
870
|
-
napi_value unorderedWrite;
|
|
871
|
-
NAPI_STATUS_THROWS(napi_get_boolean(env, dbOptions.error_if_exists, &unorderedWrite));
|
|
872
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "unorderedWrite", unorderedWrite));
|
|
873
|
-
|
|
874
|
-
napi_value manualWalFlush;
|
|
875
|
-
NAPI_STATUS_THROWS(napi_create_int64(env, dbOptions.manual_wal_flush, &manualWalFlush));
|
|
876
|
-
NAPI_STATUS_THROWS(napi_set_named_property(env, ret, "manualWalFlush", manualWalFlush));
|
|
877
|
-
}
|
|
878
|
-
|
|
879
843
|
// TODO (feat): dbOptions.listeners
|
|
880
844
|
|
|
881
845
|
const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
|
|
@@ -939,7 +903,7 @@ NAPI_METHOD(db_open) {
|
|
|
939
903
|
auto worker = new OpenWorker(env, database, argv[3], location, dbOptions, columnsFamilies);
|
|
940
904
|
worker->Queue(env);
|
|
941
905
|
|
|
942
|
-
return
|
|
906
|
+
return 0;
|
|
943
907
|
}
|
|
944
908
|
|
|
945
909
|
struct CloseWorker final : public Worker {
|
|
@@ -983,24 +947,23 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
|
|
|
983
947
|
}
|
|
984
948
|
|
|
985
949
|
rocksdb::Status Execute(Database& database) override {
|
|
986
|
-
rocksdb::TransactionLogIterator::ReadOptions options;
|
|
987
|
-
|
|
988
950
|
if (!updates_->iterator_) {
|
|
989
|
-
|
|
951
|
+
rocksdb::TransactionLogIterator::ReadOptions options;
|
|
952
|
+
const auto status = database_->db_->GetUpdatesSince(updates_->sequence_, &updates_->iterator_, options);
|
|
990
953
|
if (!status.ok()) {
|
|
991
954
|
return status;
|
|
992
955
|
}
|
|
993
|
-
} else {
|
|
956
|
+
} else if (updates_->iterator_->Valid()) {
|
|
994
957
|
updates_->iterator_->Next();
|
|
995
958
|
}
|
|
996
959
|
|
|
997
|
-
if (!updates_->iterator_->Valid()) {
|
|
960
|
+
if (!updates_->iterator_->Valid() || !updates_->iterator_->status().ok()) {
|
|
998
961
|
return updates_->iterator_->status();
|
|
999
962
|
}
|
|
1000
963
|
|
|
1001
964
|
auto batch = updates_->iterator_->GetBatch();
|
|
1002
965
|
|
|
1003
|
-
updates_->
|
|
966
|
+
updates_->sequence_ = batch.sequence;
|
|
1004
967
|
|
|
1005
968
|
count_ = batch.writeBatchPtr->Count();
|
|
1006
969
|
cache_.reserve(batch.writeBatchPtr->Count() * 4);
|
|
@@ -1009,7 +972,7 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
|
|
|
1009
972
|
}
|
|
1010
973
|
|
|
1011
974
|
napi_status OnOk(napi_env env, napi_value callback) override {
|
|
1012
|
-
napi_value argv[
|
|
975
|
+
napi_value argv[5];
|
|
1013
976
|
|
|
1014
977
|
NAPI_STATUS_RETURN(napi_get_null(env, &argv[0]));
|
|
1015
978
|
|
|
@@ -1024,11 +987,13 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
|
|
|
1024
987
|
NAPI_STATUS_RETURN(napi_set_element(env, argv[1], idx, val));
|
|
1025
988
|
}
|
|
1026
989
|
|
|
1027
|
-
NAPI_STATUS_RETURN(napi_create_int64(env, updates_->
|
|
990
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, updates_->sequence_, &argv[2]));
|
|
1028
991
|
|
|
1029
992
|
NAPI_STATUS_RETURN(napi_create_int64(env, count_, &argv[3]));
|
|
1030
993
|
|
|
1031
|
-
|
|
994
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, updates_->start_, &argv[4]));
|
|
995
|
+
|
|
996
|
+
return CallFunction(env, callback, 5, argv);
|
|
1032
997
|
}
|
|
1033
998
|
|
|
1034
999
|
void Destroy(napi_env env) override {
|
|
@@ -1169,6 +1134,7 @@ NAPI_METHOD(updates_init) {
|
|
|
1169
1134
|
NAPI_STATUS_THROWS(napi_get_named_property(env, argv[1], "data", &dataProperty));
|
|
1170
1135
|
NAPI_STATUS_THROWS(napi_get_value_bool(env, dataProperty, &data));
|
|
1171
1136
|
|
|
1137
|
+
// TODO (fix): Needs to support { column: null }
|
|
1172
1138
|
rocksdb::ColumnFamilyHandle* column;
|
|
1173
1139
|
NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[1], &column, false));
|
|
1174
1140
|
|
package/index.js
CHANGED
|
@@ -6,11 +6,11 @@ const fs = require('fs')
|
|
|
6
6
|
const binding = require('./binding')
|
|
7
7
|
const { ChainedBatch } = require('./chained-batch')
|
|
8
8
|
const { Iterator } = require('./iterator')
|
|
9
|
+
const os = require('os')
|
|
9
10
|
|
|
10
11
|
const kContext = Symbol('context')
|
|
11
12
|
const kColumns = Symbol('columns')
|
|
12
13
|
const kLocation = Symbol('location')
|
|
13
|
-
const kOptions = Symbol('options')
|
|
14
14
|
|
|
15
15
|
class RocksLevel extends AbstractLevel {
|
|
16
16
|
constructor (location, options, _) {
|
|
@@ -25,6 +25,21 @@ class RocksLevel extends AbstractLevel {
|
|
|
25
25
|
throw new TypeError("The first argument 'location' must be a non-empty string")
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
options = {
|
|
29
|
+
...options, // TODO (fix): Other defaults...
|
|
30
|
+
parallelism: options?.parallelism ?? Math.max(1, os.cpus().length / 2),
|
|
31
|
+
createIfMissing: options?.createIfMissing ?? true,
|
|
32
|
+
errorIfExists: options?.errorIfExists ?? false,
|
|
33
|
+
walTTL: options?.walTTL ?? 0,
|
|
34
|
+
walSizeLimit: options?.walSizeLimit ?? 0,
|
|
35
|
+
walCompression: options?.walCompression ?? false,
|
|
36
|
+
unorderedWrite: options?.unorderedWrite ?? false,
|
|
37
|
+
manualWalFlush: options?.manualWalFlush ?? false,
|
|
38
|
+
infoLogLevel: options?.infoLogLevel ?? ''
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// TODO (fix): Check options.
|
|
42
|
+
|
|
28
43
|
super({
|
|
29
44
|
encodings: {
|
|
30
45
|
buffer: true,
|
|
@@ -44,10 +59,6 @@ class RocksLevel extends AbstractLevel {
|
|
|
44
59
|
this[kColumns] = {}
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
get options () {
|
|
48
|
-
return this[kOptions]
|
|
49
|
-
}
|
|
50
|
-
|
|
51
62
|
get sequence () {
|
|
52
63
|
return Number(binding.db_get_latest_sequence(this[kContext]))
|
|
53
64
|
}
|
|
@@ -72,10 +83,10 @@ class RocksLevel extends AbstractLevel {
|
|
|
72
83
|
if (options.createIfMissing) {
|
|
73
84
|
fs.mkdir(this[kLocation], { recursive: true }, (err) => {
|
|
74
85
|
if (err) return callback(err)
|
|
75
|
-
|
|
86
|
+
binding.db_open(this[kContext], this[kLocation], options, onOpen)
|
|
76
87
|
})
|
|
77
88
|
} else {
|
|
78
|
-
|
|
89
|
+
binding.db_open(this[kContext], this[kLocation], options, onOpen)
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -249,6 +260,15 @@ class RocksLevel extends AbstractLevel {
|
|
|
249
260
|
throw new TypeError("'data' must be nully or a boolean")
|
|
250
261
|
}
|
|
251
262
|
|
|
263
|
+
if (options.column !== undefined && typeof options.column !== 'object') {
|
|
264
|
+
throw new TypeError("'column' must be nully or a object")
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// HACK: We don't properly check for nully column in binding.
|
|
268
|
+
if (!options.column) {
|
|
269
|
+
delete options.column
|
|
270
|
+
}
|
|
271
|
+
|
|
252
272
|
class Updates {
|
|
253
273
|
constructor (db, options) {
|
|
254
274
|
this.context = binding.updates_init(db[kContext], options)
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|