@nxtedition/rocksdb 10.0.19 → 10.0.20
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
|
@@ -666,7 +666,6 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
666
666
|
|
|
667
667
|
if (cacheSize) {
|
|
668
668
|
tableOptions.block_cache = rocksdb::HyperClockCacheOptions(cacheSize, 0).MakeSharedCache();
|
|
669
|
-
tableOptions.cache_index_and_filter_blocks = true;
|
|
670
669
|
NAPI_STATUS_RETURN(
|
|
671
670
|
GetProperty(env, options, "cacheIndexAndFilterBlocks", tableOptions.cache_index_and_filter_blocks));
|
|
672
671
|
} else {
|
|
@@ -828,7 +827,6 @@ NAPI_METHOD(db_open) {
|
|
|
828
827
|
|
|
829
828
|
dbOptions.avoid_unnecessary_blocking_io = true;
|
|
830
829
|
dbOptions.write_dbid_to_manifest = true;
|
|
831
|
-
dbOptions.enable_pipelined_write = true; // We only write in the main thread...
|
|
832
830
|
dbOptions.create_missing_column_families = true;
|
|
833
831
|
dbOptions.fail_if_options_file_error = true;
|
|
834
832
|
|
|
@@ -960,26 +958,76 @@ NAPI_METHOD(db_close) {
|
|
|
960
958
|
return 0;
|
|
961
959
|
}
|
|
962
960
|
|
|
963
|
-
NAPI_METHOD(
|
|
961
|
+
NAPI_METHOD(db_get_many_sync) {
|
|
964
962
|
NAPI_ARGV(4);
|
|
965
963
|
|
|
966
964
|
Database* database;
|
|
967
965
|
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
|
|
968
966
|
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
967
|
+
uint32_t size;
|
|
968
|
+
NAPI_STATUS_THROWS(napi_get_array_length(env, argv[1], &size));
|
|
969
|
+
|
|
970
|
+
const auto options = argv[2];
|
|
971
|
+
|
|
972
|
+
bool fillCache = true;
|
|
973
|
+
NAPI_STATUS_THROWS(GetProperty(env, options, "fillCache", fillCache));
|
|
974
|
+
|
|
975
|
+
bool ignoreRangeDeletions = false;
|
|
976
|
+
NAPI_STATUS_THROWS(GetProperty(env, options, "ignoreRangeDeletions", ignoreRangeDeletions));
|
|
977
|
+
|
|
978
|
+
rocksdb::ColumnFamilyHandle* column = database->db->DefaultColumnFamily();
|
|
979
|
+
NAPI_STATUS_THROWS(GetProperty(env, options, "column", column));
|
|
980
|
+
|
|
981
|
+
auto callback = argv[3];
|
|
982
|
+
|
|
983
|
+
std::vector<rocksdb::Slice> keys{size};
|
|
984
|
+
std::vector<rocksdb::Status> statuses{size};
|
|
985
|
+
std::vector<rocksdb::PinnableSlice> values{size};
|
|
986
|
+
|
|
987
|
+
for (uint32_t n = 0; n < size; n++) {
|
|
988
|
+
napi_value element;
|
|
989
|
+
char* buf;
|
|
990
|
+
size_t length;
|
|
991
|
+
NAPI_STATUS_THROWS(napi_get_element(env, argv[1], n, &element));
|
|
992
|
+
NAPI_STATUS_THROWS(napi_get_buffer_info(env, element, reinterpret_cast<void**>(&buf), &length));
|
|
993
|
+
keys[n] = rocksdb::Slice{ buf, length };
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
rocksdb::ReadOptions readOptions;
|
|
997
|
+
readOptions.fill_cache = fillCache;
|
|
998
|
+
readOptions.ignore_range_deletions = ignoreRangeDeletions;
|
|
999
|
+
|
|
1000
|
+
database->db->MultiGet(readOptions, column, size, keys.data(), values.data(), statuses.data());
|
|
1001
|
+
|
|
1002
|
+
napi_value ret;
|
|
1003
|
+
NAPI_STATUS_THROWS(napi_create_array_with_length(env, values.size(), &ret));
|
|
1004
|
+
|
|
1005
|
+
for (size_t idx = 0; idx < values.size(); idx++) {
|
|
1006
|
+
const auto& status = statuses[idx];
|
|
1007
|
+
const auto& value = values[idx];
|
|
1008
|
+
|
|
1009
|
+
napi_value element;
|
|
1010
|
+
if (status.IsNotFound()) {
|
|
1011
|
+
NAPI_STATUS_THROWS(napi_get_undefined(env, &element));
|
|
1012
|
+
} else {
|
|
1013
|
+
ROCKS_STATUS_THROWS_NAPI(status);
|
|
1014
|
+
NAPI_STATUS_THROWS(napi_create_buffer_copy(env, value.size(), value.data(), nullptr, &element));
|
|
980
1015
|
}
|
|
1016
|
+
NAPI_STATUS_THROWS(napi_set_element(env, argv[1], static_cast<uint32_t>(idx), element));
|
|
981
1017
|
}
|
|
982
1018
|
|
|
1019
|
+
return ret;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
NAPI_METHOD(db_get_many) {
|
|
1023
|
+
NAPI_ARGV(4);
|
|
1024
|
+
|
|
1025
|
+
Database* database;
|
|
1026
|
+
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
|
|
1027
|
+
|
|
1028
|
+
uint32_t size;
|
|
1029
|
+
NAPI_STATUS_THROWS(napi_get_array_length(env, argv[1], &size));
|
|
1030
|
+
|
|
983
1031
|
const auto options = argv[2];
|
|
984
1032
|
|
|
985
1033
|
bool fillCache = true;
|
|
@@ -996,9 +1044,26 @@ NAPI_METHOD(db_get_many) {
|
|
|
996
1044
|
auto snapshot = std::shared_ptr<const rocksdb::Snapshot>(
|
|
997
1045
|
database->db->GetSnapshot(), [database](auto ptr) { database->db->ReleaseSnapshot(ptr); });
|
|
998
1046
|
|
|
999
|
-
|
|
1047
|
+
// TODO (fix): Ensure lifetime of buffer?
|
|
1048
|
+
std::vector<rocksdb::Slice> keys { size };
|
|
1049
|
+
|
|
1050
|
+
for (uint32_t n = 0; n < size; n++) {
|
|
1051
|
+
napi_value element;
|
|
1052
|
+
char* buf;
|
|
1053
|
+
size_t length;
|
|
1054
|
+
NAPI_STATUS_THROWS(napi_get_element(env, argv[1], n, &element));
|
|
1055
|
+
NAPI_STATUS_THROWS(napi_get_buffer_info(env, element, reinterpret_cast<void**>(&buf), &length));
|
|
1056
|
+
keys[n] = rocksdb::Slice{ buf, length };
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
struct State {
|
|
1060
|
+
std::vector<rocksdb::Status> statuses;
|
|
1061
|
+
std::vector<rocksdb::PinnableSlice> values;
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
runAsync<State>(
|
|
1000
1065
|
"leveldown.get.many", env, callback,
|
|
1001
|
-
[=, keys = std::move(keys), snapshot = std::move(snapshot)](auto&
|
|
1066
|
+
[=, keys = std::move(keys), snapshot = std::move(snapshot)](auto& state) {
|
|
1002
1067
|
rocksdb::ReadOptions readOptions;
|
|
1003
1068
|
readOptions.fill_cache = fillCache;
|
|
1004
1069
|
readOptions.snapshot = snapshot.get();
|
|
@@ -1006,37 +1071,28 @@ NAPI_METHOD(db_get_many) {
|
|
|
1006
1071
|
readOptions.ignore_range_deletions = ignoreRangeDeletions;
|
|
1007
1072
|
readOptions.optimize_multiget_for_io = true;
|
|
1008
1073
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
std::vector<rocksdb::Status> statuses;
|
|
1012
|
-
|
|
1013
|
-
statuses.resize(size);
|
|
1014
|
-
values.resize(size);
|
|
1015
|
-
|
|
1016
|
-
database->db->MultiGet(readOptions, column, size, keys.data(), values.data(), statuses.data());
|
|
1074
|
+
state.statuses.resize(size);
|
|
1075
|
+
state.values.resize(size);
|
|
1017
1076
|
|
|
1018
|
-
|
|
1019
|
-
if (statuses[idx].IsNotFound()) {
|
|
1020
|
-
values[idx] = rocksdb::PinnableSlice(nullptr);
|
|
1021
|
-
} else if (!statuses[idx].ok()) {
|
|
1022
|
-
return statuses[idx];
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1077
|
+
database->db->MultiGet(readOptions, column, size, keys.data(), state.values.data(), state.statuses.data());
|
|
1025
1078
|
|
|
1026
1079
|
return rocksdb::Status::OK();
|
|
1027
1080
|
},
|
|
1028
|
-
[=](auto&
|
|
1081
|
+
[=](auto& state, auto env, auto& argv) {
|
|
1029
1082
|
argv.resize(2);
|
|
1030
1083
|
|
|
1031
|
-
NAPI_STATUS_RETURN(napi_create_array_with_length(env, values.size(), &argv[1]));
|
|
1084
|
+
NAPI_STATUS_RETURN(napi_create_array_with_length(env, state.values.size(), &argv[1]));
|
|
1085
|
+
|
|
1086
|
+
for (size_t idx = 0; idx < state.values.size(); idx++) {
|
|
1087
|
+
const auto& status = state.statuses[idx];
|
|
1088
|
+
const auto& value = state.values[idx];
|
|
1032
1089
|
|
|
1033
|
-
for (size_t idx = 0; idx < values.size(); idx++) {
|
|
1034
1090
|
napi_value element;
|
|
1035
|
-
if (
|
|
1036
|
-
auto ptr = new rocksdb::PinnableSlice(std::move(values[idx]));
|
|
1037
|
-
NAPI_STATUS_RETURN(napi_create_external_buffer(env, ptr->size(), const_cast<char*>(ptr->data()), Finalize<rocksdb::PinnableSlice>, ptr, &element));
|
|
1038
|
-
} else {
|
|
1091
|
+
if (status.IsNotFound()) {
|
|
1039
1092
|
NAPI_STATUS_RETURN(napi_get_undefined(env, &element));
|
|
1093
|
+
} else {
|
|
1094
|
+
ROCKS_STATUS_RETURN_NAPI(status);
|
|
1095
|
+
NAPI_STATUS_RETURN(napi_create_buffer_copy(env, value.size(), value.data(), nullptr, &element));
|
|
1040
1096
|
}
|
|
1041
1097
|
NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<uint32_t>(idx), element));
|
|
1042
1098
|
}
|
|
@@ -1650,6 +1706,7 @@ NAPI_INIT() {
|
|
|
1650
1706
|
NAPI_EXPORT_FUNCTION(db_get_location);
|
|
1651
1707
|
NAPI_EXPORT_FUNCTION(db_close);
|
|
1652
1708
|
NAPI_EXPORT_FUNCTION(db_get_many);
|
|
1709
|
+
NAPI_EXPORT_FUNCTION(db_get_many_sync);
|
|
1653
1710
|
NAPI_EXPORT_FUNCTION(db_clear);
|
|
1654
1711
|
NAPI_EXPORT_FUNCTION(db_get_property);
|
|
1655
1712
|
NAPI_EXPORT_FUNCTION(db_get_latest_sequence);
|
package/index.js
CHANGED
|
@@ -171,6 +171,10 @@ class RocksLevel extends AbstractLevel {
|
|
|
171
171
|
return callback[kPromise]
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
_getManySync (keys, options) {
|
|
175
|
+
return binding.db_get_many_sync(this[kContext], keys, options ?? EMPTY)
|
|
176
|
+
}
|
|
177
|
+
|
|
174
178
|
_getMergeOperands (key, options, callback) {
|
|
175
179
|
callback = fromCallback(callback, kPromise)
|
|
176
180
|
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|