@nxtedition/rocksdb 7.0.21 → 7.0.22
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 +99 -36
- package/index.js +3 -6
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
package/binding.cc
CHANGED
|
@@ -133,8 +133,7 @@ static std::optional<int64_t> Int64Property(napi_env env, napi_value obj, const
|
|
|
133
133
|
if (HasProperty(env, obj, key.data())) {
|
|
134
134
|
const auto value = GetProperty(env, obj, key.data());
|
|
135
135
|
int64_t result;
|
|
136
|
-
|
|
137
|
-
napi_get_value_bigint_int64(env, value, &result, &lossless);
|
|
136
|
+
napi_get_value_int64(env, value, &result);
|
|
138
137
|
return result;
|
|
139
138
|
}
|
|
140
139
|
|
|
@@ -538,7 +537,24 @@ struct Iterator final : public BaseIterator {
|
|
|
538
537
|
};
|
|
539
538
|
|
|
540
539
|
struct Updates {
|
|
541
|
-
Updates(Database* database,
|
|
540
|
+
Updates(Database* database,
|
|
541
|
+
int64_t seqNumber,
|
|
542
|
+
bool keys,
|
|
543
|
+
bool values,
|
|
544
|
+
bool data,
|
|
545
|
+
const std::optional<std::string>& column)
|
|
546
|
+
: database_(database), seqNumber_(seqNumber), keys_(keys), values_(values), data_(data) {
|
|
547
|
+
if (column) {
|
|
548
|
+
auto columns = database->columns_;
|
|
549
|
+
auto columnIt = std::find_if(columns.begin(), columns.end(),
|
|
550
|
+
[&](const auto& handle) { return handle->GetName() == *column; });
|
|
551
|
+
if (columnIt != columns.end()) {
|
|
552
|
+
column_family_id_ = (*columnIt)->GetID();
|
|
553
|
+
} else {
|
|
554
|
+
// TODO: Throw?
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
542
558
|
|
|
543
559
|
void Close() { iterator_.reset(); }
|
|
544
560
|
|
|
@@ -557,6 +573,10 @@ struct Updates {
|
|
|
557
573
|
Database* database_;
|
|
558
574
|
int64_t seqNumber_;
|
|
559
575
|
std::unique_ptr<rocksdb::TransactionLogIterator> iterator_;
|
|
576
|
+
bool keys_;
|
|
577
|
+
bool values_;
|
|
578
|
+
bool data_;
|
|
579
|
+
std::optional<uint32_t> column_family_id_;
|
|
560
580
|
|
|
561
581
|
private:
|
|
562
582
|
napi_ref ref_ = nullptr;
|
|
@@ -941,49 +961,33 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
|
|
|
941
961
|
|
|
942
962
|
updates_->seqNumber_ = batch.sequence;
|
|
943
963
|
|
|
964
|
+
count_ = batch.writeBatchPtr->Count();
|
|
944
965
|
cache_.reserve(batch.writeBatchPtr->Count() * 4);
|
|
945
966
|
|
|
946
967
|
return batch.writeBatchPtr->Iterate(this);
|
|
947
968
|
}
|
|
948
969
|
|
|
949
970
|
napi_status OnOk(napi_env env, napi_value callback) override {
|
|
950
|
-
napi_value argv[
|
|
971
|
+
napi_value argv[4];
|
|
972
|
+
|
|
951
973
|
NAPI_STATUS_RETURN(napi_get_null(env, &argv[0]));
|
|
952
974
|
|
|
953
975
|
if (cache_.empty()) {
|
|
954
976
|
return CallFunction(env, callback, 1, argv);
|
|
955
977
|
}
|
|
956
978
|
|
|
957
|
-
NAPI_STATUS_RETURN(napi_create_array_with_length(env, cache_.size()
|
|
979
|
+
NAPI_STATUS_RETURN(napi_create_array_with_length(env, cache_.size(), &argv[1]));
|
|
958
980
|
for (size_t idx = 0; idx < cache_.size(); idx++) {
|
|
959
|
-
napi_value op;
|
|
960
|
-
NAPI_STATUS_RETURN(Convert(env, std::get<0>(cache_[idx]), false, op));
|
|
961
|
-
NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx * 4 + 0), op));
|
|
962
|
-
|
|
963
|
-
napi_value key;
|
|
964
|
-
NAPI_STATUS_RETURN(Convert(env, std::get<1>(cache_[idx]), false, key));
|
|
965
|
-
NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx * 4 + 1), key));
|
|
966
|
-
|
|
967
981
|
napi_value val;
|
|
968
|
-
NAPI_STATUS_RETURN(Convert(env,
|
|
969
|
-
NAPI_STATUS_RETURN(napi_set_element(env, argv[1],
|
|
970
|
-
|
|
971
|
-
auto column_family_id = std::get<3>(cache_[idx]);
|
|
972
|
-
auto columns = database_->columns_;
|
|
973
|
-
auto columnIt = std::find_if(columns.begin(), columns.end(),
|
|
974
|
-
[&](const auto& handle) { return handle->GetID() == column_family_id; });
|
|
975
|
-
napi_value column;
|
|
976
|
-
if (columnIt != columns.end()) {
|
|
977
|
-
NAPI_STATUS_RETURN(napi_create_external(env, *columnIt, nullptr, nullptr, &column));
|
|
978
|
-
} else {
|
|
979
|
-
NAPI_STATUS_RETURN(napi_get_null(env, &column));
|
|
980
|
-
}
|
|
981
|
-
NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx * 4 + 3), column));
|
|
982
|
+
NAPI_STATUS_RETURN(Convert(env, cache_[idx], false, val));
|
|
983
|
+
NAPI_STATUS_RETURN(napi_set_element(env, argv[1], idx, val));
|
|
982
984
|
}
|
|
983
985
|
|
|
984
|
-
NAPI_STATUS_RETURN(
|
|
986
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, updates_->seqNumber_, &argv[2]));
|
|
985
987
|
|
|
986
|
-
|
|
988
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, count_, &argv[3]));
|
|
989
|
+
|
|
990
|
+
return CallFunction(env, callback, 4, argv);
|
|
987
991
|
}
|
|
988
992
|
|
|
989
993
|
void Destroy(napi_env env) override {
|
|
@@ -991,28 +995,83 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
|
|
|
991
995
|
Worker::Destroy(env);
|
|
992
996
|
}
|
|
993
997
|
|
|
998
|
+
std::optional<std::string> GetColumnName(uint32_t column_family_id) {
|
|
999
|
+
if (column_family_id == 0) {
|
|
1000
|
+
return "default";
|
|
1001
|
+
}
|
|
1002
|
+
auto columns = database_->columns_;
|
|
1003
|
+
auto columnIt = std::find_if(columns.begin(), columns.end(),
|
|
1004
|
+
[&](const auto& handle) { return handle->GetID() == column_family_id; });
|
|
1005
|
+
return columnIt == columns.end() ? std::nullopt : std::optional<std::string>((*columnIt)->GetName());
|
|
1006
|
+
}
|
|
1007
|
+
|
|
994
1008
|
rocksdb::Status PutCF(uint32_t column_family_id, const rocksdb::Slice& key, const rocksdb::Slice& value) override {
|
|
995
|
-
|
|
1009
|
+
if (updates_->column_family_id_ && *updates_->column_family_id_ != column_family_id) {
|
|
1010
|
+
return rocksdb::Status::OK();
|
|
1011
|
+
}
|
|
1012
|
+
cache_.emplace_back("put");
|
|
1013
|
+
if (updates_->keys_) {
|
|
1014
|
+
cache_.emplace_back(key.ToStringView());
|
|
1015
|
+
} else {
|
|
1016
|
+
cache_.emplace_back(std::nullopt);
|
|
1017
|
+
}
|
|
1018
|
+
if (updates_->values_) {
|
|
1019
|
+
cache_.emplace_back(value.ToStringView());
|
|
1020
|
+
} else {
|
|
1021
|
+
cache_.emplace_back(std::nullopt);
|
|
1022
|
+
}
|
|
1023
|
+
cache_.emplace_back(GetColumnName(column_family_id));
|
|
996
1024
|
return rocksdb::Status::OK();
|
|
997
1025
|
}
|
|
998
1026
|
|
|
999
1027
|
rocksdb::Status DeleteCF(uint32_t column_family_id, const rocksdb::Slice& key) override {
|
|
1000
|
-
|
|
1028
|
+
if (updates_->column_family_id_ && *updates_->column_family_id_ != column_family_id) {
|
|
1029
|
+
return rocksdb::Status::OK();
|
|
1030
|
+
}
|
|
1031
|
+
cache_.emplace_back("del");
|
|
1032
|
+
if (updates_->keys_) {
|
|
1033
|
+
cache_.emplace_back(key.ToStringView());
|
|
1034
|
+
} else {
|
|
1035
|
+
cache_.emplace_back(std::nullopt);
|
|
1036
|
+
}
|
|
1037
|
+
cache_.emplace_back(std::nullopt);
|
|
1038
|
+
cache_.emplace_back(GetColumnName(column_family_id));
|
|
1001
1039
|
return rocksdb::Status::OK();
|
|
1002
1040
|
}
|
|
1003
1041
|
|
|
1004
1042
|
rocksdb::Status MergeCF(uint32_t column_family_id, const rocksdb::Slice& key, const rocksdb::Slice& value) override {
|
|
1005
|
-
|
|
1043
|
+
if (updates_->column_family_id_ && *updates_->column_family_id_ != column_family_id) {
|
|
1044
|
+
return rocksdb::Status::OK();
|
|
1045
|
+
}
|
|
1046
|
+
cache_.emplace_back("put");
|
|
1047
|
+
if (updates_->keys_) {
|
|
1048
|
+
cache_.emplace_back(key.ToStringView());
|
|
1049
|
+
} else {
|
|
1050
|
+
cache_.emplace_back(std::nullopt);
|
|
1051
|
+
}
|
|
1052
|
+
if (updates_->values_) {
|
|
1053
|
+
cache_.emplace_back(value.ToStringView());
|
|
1054
|
+
} else {
|
|
1055
|
+
cache_.emplace_back(std::nullopt);
|
|
1056
|
+
}
|
|
1057
|
+
cache_.emplace_back(GetColumnName(column_family_id));
|
|
1006
1058
|
return rocksdb::Status::OK();
|
|
1007
1059
|
}
|
|
1008
1060
|
|
|
1009
|
-
void LogData(const rocksdb::Slice& data) override {
|
|
1061
|
+
void LogData(const rocksdb::Slice& data) override {
|
|
1062
|
+
if (updates_->data_) {
|
|
1063
|
+
cache_.emplace_back("data");
|
|
1064
|
+
cache_.emplace_back(std::nullopt);
|
|
1065
|
+
cache_.emplace_back(data.ToStringView());
|
|
1066
|
+
cache_.emplace_back(std::nullopt);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1010
1069
|
|
|
1011
1070
|
bool Continue() override { return true; }
|
|
1012
1071
|
|
|
1013
1072
|
private:
|
|
1014
|
-
|
|
1015
|
-
|
|
1073
|
+
size_t count_;
|
|
1074
|
+
std::vector<std::optional<std::string>> cache_;
|
|
1016
1075
|
Updates* updates_;
|
|
1017
1076
|
};
|
|
1018
1077
|
|
|
@@ -1023,8 +1082,12 @@ NAPI_METHOD(updates_init) {
|
|
|
1023
1082
|
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
|
|
1024
1083
|
|
|
1025
1084
|
const auto seqNumber = Int64Property(env, argv[1], "since").value_or(database->db_->GetLatestSequenceNumber());
|
|
1085
|
+
const auto keys = BooleanProperty(env, argv[1], "keys").value_or(true);
|
|
1086
|
+
const auto values = BooleanProperty(env, argv[1], "values").value_or(true);
|
|
1087
|
+
const auto data = BooleanProperty(env, argv[1], "data").value_or(true);
|
|
1088
|
+
const auto column = StringProperty(env, argv[1], "column");
|
|
1026
1089
|
|
|
1027
|
-
auto updates = std::make_unique<Updates>(database, seqNumber);
|
|
1090
|
+
auto updates = std::make_unique<Updates>(database, seqNumber, keys, values, data, column);
|
|
1028
1091
|
|
|
1029
1092
|
napi_value result;
|
|
1030
1093
|
NAPI_STATUS_THROWS(napi_create_external(env, updates.get(), Finalize<Updates>, updates.get(), &result));
|
package/index.js
CHANGED
|
@@ -193,10 +193,7 @@ class RocksLevel extends AbstractLevel {
|
|
|
193
193
|
|
|
194
194
|
class Updates {
|
|
195
195
|
constructor (db, options) {
|
|
196
|
-
this.context = binding.updates_init(db[kContext],
|
|
197
|
-
...options,
|
|
198
|
-
since: BigInt(options.since || 0)
|
|
199
|
-
})
|
|
196
|
+
this.context = binding.updates_init(db[kContext], options)
|
|
200
197
|
this.closed = false
|
|
201
198
|
this.promise = null
|
|
202
199
|
this.db = db
|
|
@@ -208,12 +205,12 @@ class RocksLevel extends AbstractLevel {
|
|
|
208
205
|
return {}
|
|
209
206
|
}
|
|
210
207
|
|
|
211
|
-
this.promise = new Promise(resolve => binding.updates_next(this.context, (err, rows, sequence) => {
|
|
208
|
+
this.promise = new Promise(resolve => binding.updates_next(this.context, (err, rows, sequence, count) => {
|
|
212
209
|
this.promise = null
|
|
213
210
|
if (err) {
|
|
214
211
|
resolve(Promise.reject(err))
|
|
215
212
|
} else {
|
|
216
|
-
resolve({ rows, sequence
|
|
213
|
+
resolve({ rows, sequence, count })
|
|
217
214
|
}
|
|
218
215
|
}))
|
|
219
216
|
|
package/package.json
CHANGED
|
Binary file
|