@nxtedition/rocksdb 7.0.29 → 7.0.30
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 +111 -6
- package/index.js +15 -2
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/node.napi.node +0 -0
package/binding.cc
CHANGED
|
@@ -814,8 +814,9 @@ NAPI_METHOD(db_open) {
|
|
|
814
814
|
|
|
815
815
|
rocksdb::Options dbOptions;
|
|
816
816
|
|
|
817
|
-
|
|
818
|
-
.value_or(std::max<uint32_t>(1, std::thread::hardware_concurrency() / 2))
|
|
817
|
+
const auto parallelismValue = Uint32Property(env, argv[2], "parallelism")
|
|
818
|
+
.value_or(std::max<uint32_t>(1, std::thread::hardware_concurrency() / 2));
|
|
819
|
+
dbOptions.IncreaseParallelism(parallelismValue);
|
|
819
820
|
|
|
820
821
|
dbOptions.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
|
|
821
822
|
dbOptions.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
|
|
@@ -827,14 +828,54 @@ NAPI_METHOD(db_open) {
|
|
|
827
828
|
.value_or(std::max<uint32_t>(2, std::thread::hardware_concurrency() / 8));
|
|
828
829
|
dbOptions.WAL_ttl_seconds = Uint32Property(env, argv[2], "walTTL").value_or(0) / 1e3;
|
|
829
830
|
dbOptions.WAL_size_limit_MB = Uint32Property(env, argv[2], "walSizeLimit").value_or(0) / 1e6;
|
|
830
|
-
dbOptions.create_missing_column_families = true;
|
|
831
|
-
dbOptions.unordered_write = BooleanProperty(env, argv[2], "unorderedWrite").value_or(false);
|
|
832
|
-
dbOptions.fail_if_options_file_error = true;
|
|
833
831
|
dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
|
|
834
832
|
? rocksdb::CompressionType::kZSTD
|
|
835
833
|
: rocksdb::CompressionType::kNoCompression;
|
|
834
|
+
dbOptions.create_missing_column_families = true;
|
|
835
|
+
dbOptions.unordered_write = BooleanProperty(env, argv[2], "unorderedWrite").value_or(false);
|
|
836
|
+
dbOptions.fail_if_options_file_error = true;
|
|
836
837
|
dbOptions.manual_wal_flush = BooleanProperty(env, argv[2], "manualWalFlush").value_or(false);
|
|
837
838
|
|
|
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, &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, &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
|
+
|
|
838
879
|
// TODO (feat): dbOptions.listeners
|
|
839
880
|
|
|
840
881
|
const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
|
|
@@ -898,7 +939,7 @@ NAPI_METHOD(db_open) {
|
|
|
898
939
|
auto worker = new OpenWorker(env, database, argv[3], location, dbOptions, columnsFamilies);
|
|
899
940
|
worker->Queue(env);
|
|
900
941
|
|
|
901
|
-
return
|
|
942
|
+
return ret;
|
|
902
943
|
}
|
|
903
944
|
|
|
904
945
|
struct CloseWorker final : public Worker {
|
|
@@ -1891,6 +1932,68 @@ NAPI_METHOD(db_flush_wal) {
|
|
|
1891
1932
|
return 0;
|
|
1892
1933
|
}
|
|
1893
1934
|
|
|
1935
|
+
napi_status FromLogFile(napi_env env, const auto& file, napi_value* obj) {
|
|
1936
|
+
NAPI_STATUS_RETURN(napi_create_object(env, obj));
|
|
1937
|
+
|
|
1938
|
+
napi_value pathName;
|
|
1939
|
+
NAPI_STATUS_RETURN(napi_create_string_utf8(env, file->PathName().c_str(), NAPI_AUTO_LENGTH, &pathName));
|
|
1940
|
+
NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "pathName", pathName));
|
|
1941
|
+
|
|
1942
|
+
napi_value logNumber;
|
|
1943
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, file->LogNumber(), &logNumber));
|
|
1944
|
+
NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "logNumber", logNumber));
|
|
1945
|
+
|
|
1946
|
+
napi_value type;
|
|
1947
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, file->Type(), &type));
|
|
1948
|
+
NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "type", type));
|
|
1949
|
+
|
|
1950
|
+
napi_value startSequence;
|
|
1951
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, file->StartSequence(), &startSequence));
|
|
1952
|
+
NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "startSequence", startSequence));
|
|
1953
|
+
|
|
1954
|
+
napi_value sizeFileBytes;
|
|
1955
|
+
NAPI_STATUS_RETURN(napi_create_int64(env, file->SizeFileBytes(), &sizeFileBytes));
|
|
1956
|
+
NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "sizeFileBytes", sizeFileBytes));
|
|
1957
|
+
|
|
1958
|
+
return napi_ok;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
NAPI_METHOD(db_get_sorted_wal_files) {
|
|
1962
|
+
NAPI_ARGV(1);
|
|
1963
|
+
|
|
1964
|
+
Database* database;
|
|
1965
|
+
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
|
|
1966
|
+
|
|
1967
|
+
rocksdb::VectorLogPtr files;
|
|
1968
|
+
ROCKS_STATUS_THROWS(database->db_->GetSortedWalFiles(files));
|
|
1969
|
+
|
|
1970
|
+
napi_value ret;
|
|
1971
|
+
NAPI_STATUS_THROWS(napi_create_array_with_length(env, files.size(), &ret));
|
|
1972
|
+
|
|
1973
|
+
for (size_t n = 0; n < files.size(); ++n) {
|
|
1974
|
+
napi_value obj;
|
|
1975
|
+
NAPI_STATUS_THROWS(FromLogFile(env, files[n], &obj));
|
|
1976
|
+
NAPI_STATUS_THROWS(napi_set_element(env, ret, n, obj));
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
return ret;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
NAPI_METHOD(db_get_current_wal_file) {
|
|
1983
|
+
NAPI_ARGV(1);
|
|
1984
|
+
|
|
1985
|
+
Database* database;
|
|
1986
|
+
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
|
|
1987
|
+
|
|
1988
|
+
std::unique_ptr<rocksdb::LogFile> file;
|
|
1989
|
+
ROCKS_STATUS_THROWS(database->db_->GetCurrentWalFile(&file));
|
|
1990
|
+
|
|
1991
|
+
napi_value ret;
|
|
1992
|
+
NAPI_STATUS_THROWS(FromLogFile(env, file, &ret));
|
|
1993
|
+
|
|
1994
|
+
return ret;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1894
1997
|
NAPI_INIT() {
|
|
1895
1998
|
NAPI_EXPORT_FUNCTION(db_init);
|
|
1896
1999
|
NAPI_EXPORT_FUNCTION(db_open);
|
|
@@ -1914,6 +2017,8 @@ NAPI_INIT() {
|
|
|
1914
2017
|
NAPI_EXPORT_FUNCTION(updates_next);
|
|
1915
2018
|
|
|
1916
2019
|
NAPI_EXPORT_FUNCTION(db_flush_wal);
|
|
2020
|
+
NAPI_EXPORT_FUNCTION(db_get_sorted_wal_files);
|
|
2021
|
+
NAPI_EXPORT_FUNCTION(db_get_current_wal_file);
|
|
1917
2022
|
|
|
1918
2023
|
NAPI_EXPORT_FUNCTION(batch_do);
|
|
1919
2024
|
NAPI_EXPORT_FUNCTION(batch_init);
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const { Iterator } = require('./iterator')
|
|
|
10
10
|
const kContext = Symbol('context')
|
|
11
11
|
const kColumns = Symbol('columns')
|
|
12
12
|
const kLocation = Symbol('location')
|
|
13
|
+
const kOptions = Symbol('options')
|
|
13
14
|
|
|
14
15
|
class RocksLevel extends AbstractLevel {
|
|
15
16
|
constructor (location, options, _) {
|
|
@@ -43,6 +44,10 @@ class RocksLevel extends AbstractLevel {
|
|
|
43
44
|
this[kColumns] = {}
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
get options () {
|
|
48
|
+
return this[kOptions]
|
|
49
|
+
}
|
|
50
|
+
|
|
46
51
|
get sequence () {
|
|
47
52
|
return Number(binding.db_get_latest_sequence(this[kContext]))
|
|
48
53
|
}
|
|
@@ -67,10 +72,10 @@ class RocksLevel extends AbstractLevel {
|
|
|
67
72
|
if (options.createIfMissing) {
|
|
68
73
|
fs.mkdir(this[kLocation], { recursive: true }, (err) => {
|
|
69
74
|
if (err) return callback(err)
|
|
70
|
-
binding.db_open(this[kContext], this[kLocation], options, onOpen)
|
|
75
|
+
this[kOptions] = binding.db_open(this[kContext], this[kLocation], options, onOpen)
|
|
71
76
|
})
|
|
72
77
|
} else {
|
|
73
|
-
binding.db_open(this[kContext], this[kLocation], options, onOpen)
|
|
78
|
+
this[kOptions] = binding.db_open(this[kContext], this[kLocation], options, onOpen)
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -145,6 +150,14 @@ class RocksLevel extends AbstractLevel {
|
|
|
145
150
|
return binding.db_get_property(this[kContext], property)
|
|
146
151
|
}
|
|
147
152
|
|
|
153
|
+
async getCurrentWALFile () {
|
|
154
|
+
return binding.db_get_current_wal_file(this[kContext])
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async getSortedWALFiles () {
|
|
158
|
+
return binding.db_get_sorted_wal_files(this[kContext])
|
|
159
|
+
}
|
|
160
|
+
|
|
148
161
|
async flushWAL (options) {
|
|
149
162
|
binding.db_flush_wal(this[kContext], options)
|
|
150
163
|
}
|
package/package.json
CHANGED
|
Binary file
|