@nxtedition/rocksdb 7.0.29 → 7.0.32

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
@@ -823,16 +823,14 @@ NAPI_METHOD(db_open) {
823
823
  dbOptions.write_dbid_to_manifest = true;
824
824
  dbOptions.use_adaptive_mutex = true; // We don't have soo many threads in the libuv thread pool...
825
825
  dbOptions.enable_pipelined_write = false; // We only write in the main thread...
826
- dbOptions.max_background_jobs = Uint32Property(env, argv[2], "maxBackgroundJobs")
827
- .value_or(std::max<uint32_t>(2, std::thread::hardware_concurrency() / 8));
828
826
  dbOptions.WAL_ttl_seconds = Uint32Property(env, argv[2], "walTTL").value_or(0) / 1e3;
829
827
  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
828
  dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
834
829
  ? rocksdb::CompressionType::kZSTD
835
830
  : rocksdb::CompressionType::kNoCompression;
831
+ dbOptions.create_missing_column_families = true;
832
+ dbOptions.unordered_write = BooleanProperty(env, argv[2], "unorderedWrite").value_or(false);
833
+ dbOptions.fail_if_options_file_error = true;
836
834
  dbOptions.manual_wal_flush = BooleanProperty(env, argv[2], "manualWalFlush").value_or(false);
837
835
 
838
836
  // TODO (feat): dbOptions.listeners
@@ -1108,15 +1106,30 @@ NAPI_METHOD(updates_init) {
1108
1106
  Database* database;
1109
1107
  NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1110
1108
 
1111
- const auto seqNumber = Int64Property(env, argv[1], "since").value_or(database->db_->GetLatestSequenceNumber());
1112
- const auto keys = BooleanProperty(env, argv[1], "keys").value_or(true);
1113
- const auto values = BooleanProperty(env, argv[1], "values").value_or(true);
1114
- const auto data = BooleanProperty(env, argv[1], "data").value_or(true);
1109
+ napi_value sinceProperty;
1110
+ int64_t since;
1111
+ NAPI_STATUS_THROWS(napi_get_named_property(env, argv[1], "since", &sinceProperty));
1112
+ NAPI_STATUS_THROWS(napi_get_value_int64(env, sinceProperty, &since));
1113
+
1114
+ napi_value keysProperty;
1115
+ bool keys;
1116
+ NAPI_STATUS_THROWS(napi_get_named_property(env, argv[1], "keys", &keysProperty));
1117
+ NAPI_STATUS_THROWS(napi_get_value_bool(env, keysProperty, &keys));
1118
+
1119
+ napi_value valuesProperty;
1120
+ bool values;
1121
+ NAPI_STATUS_THROWS(napi_get_named_property(env, argv[1], "values", &valuesProperty));
1122
+ NAPI_STATUS_THROWS(napi_get_value_bool(env, valuesProperty, &values));
1123
+
1124
+ napi_value dataProperty;
1125
+ bool data;
1126
+ NAPI_STATUS_THROWS(napi_get_named_property(env, argv[1], "data", &dataProperty));
1127
+ NAPI_STATUS_THROWS(napi_get_value_bool(env, dataProperty, &data));
1115
1128
 
1116
1129
  rocksdb::ColumnFamilyHandle* column;
1117
1130
  NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[1], &column, false));
1118
1131
 
1119
- auto updates = std::make_unique<Updates>(database, seqNumber, keys, values, data, column);
1132
+ auto updates = std::make_unique<Updates>(database, since, keys, values, data, column);
1120
1133
 
1121
1134
  napi_value result;
1122
1135
  NAPI_STATUS_THROWS(napi_create_external(env, updates.get(), Finalize<Updates>, updates.get(), &result));
@@ -1891,6 +1904,68 @@ NAPI_METHOD(db_flush_wal) {
1891
1904
  return 0;
1892
1905
  }
1893
1906
 
1907
+ napi_status FromLogFile(napi_env env, const auto& file, napi_value* obj) {
1908
+ NAPI_STATUS_RETURN(napi_create_object(env, obj));
1909
+
1910
+ napi_value pathName;
1911
+ NAPI_STATUS_RETURN(napi_create_string_utf8(env, file->PathName().c_str(), NAPI_AUTO_LENGTH, &pathName));
1912
+ NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "pathName", pathName));
1913
+
1914
+ napi_value logNumber;
1915
+ NAPI_STATUS_RETURN(napi_create_int64(env, file->LogNumber(), &logNumber));
1916
+ NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "logNumber", logNumber));
1917
+
1918
+ napi_value type;
1919
+ NAPI_STATUS_RETURN(napi_create_int64(env, file->Type(), &type));
1920
+ NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "type", type));
1921
+
1922
+ napi_value startSequence;
1923
+ NAPI_STATUS_RETURN(napi_create_int64(env, file->StartSequence(), &startSequence));
1924
+ NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "startSequence", startSequence));
1925
+
1926
+ napi_value sizeFileBytes;
1927
+ NAPI_STATUS_RETURN(napi_create_int64(env, file->SizeFileBytes(), &sizeFileBytes));
1928
+ NAPI_STATUS_RETURN(napi_set_named_property(env, *obj, "sizeFileBytes", sizeFileBytes));
1929
+
1930
+ return napi_ok;
1931
+ }
1932
+
1933
+ NAPI_METHOD(db_get_sorted_wal_files) {
1934
+ NAPI_ARGV(1);
1935
+
1936
+ Database* database;
1937
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1938
+
1939
+ rocksdb::VectorLogPtr files;
1940
+ ROCKS_STATUS_THROWS(database->db_->GetSortedWalFiles(files));
1941
+
1942
+ napi_value ret;
1943
+ NAPI_STATUS_THROWS(napi_create_array_with_length(env, files.size(), &ret));
1944
+
1945
+ for (size_t n = 0; n < files.size(); ++n) {
1946
+ napi_value obj;
1947
+ NAPI_STATUS_THROWS(FromLogFile(env, files[n], &obj));
1948
+ NAPI_STATUS_THROWS(napi_set_element(env, ret, n, obj));
1949
+ }
1950
+
1951
+ return ret;
1952
+ }
1953
+
1954
+ NAPI_METHOD(db_get_current_wal_file) {
1955
+ NAPI_ARGV(1);
1956
+
1957
+ Database* database;
1958
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1959
+
1960
+ std::unique_ptr<rocksdb::LogFile> file;
1961
+ ROCKS_STATUS_THROWS(database->db_->GetCurrentWalFile(&file));
1962
+
1963
+ napi_value ret;
1964
+ NAPI_STATUS_THROWS(FromLogFile(env, file, &ret));
1965
+
1966
+ return ret;
1967
+ }
1968
+
1894
1969
  NAPI_INIT() {
1895
1970
  NAPI_EXPORT_FUNCTION(db_init);
1896
1971
  NAPI_EXPORT_FUNCTION(db_open);
@@ -1914,6 +1989,8 @@ NAPI_INIT() {
1914
1989
  NAPI_EXPORT_FUNCTION(updates_next);
1915
1990
 
1916
1991
  NAPI_EXPORT_FUNCTION(db_flush_wal);
1992
+ NAPI_EXPORT_FUNCTION(db_get_sorted_wal_files);
1993
+ NAPI_EXPORT_FUNCTION(db_get_current_wal_file);
1917
1994
 
1918
1995
  NAPI_EXPORT_FUNCTION(batch_do);
1919
1996
  NAPI_EXPORT_FUNCTION(batch_init);
package/index.js CHANGED
@@ -6,6 +6,7 @@ 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')
@@ -24,6 +25,21 @@ class RocksLevel extends AbstractLevel {
24
25
  throw new TypeError("The first argument 'location' must be a non-empty string")
25
26
  }
26
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
+
27
43
  super({
28
44
  encodings: {
29
45
  buffer: true,
@@ -145,7 +161,33 @@ class RocksLevel extends AbstractLevel {
145
161
  return binding.db_get_property(this[kContext], property)
146
162
  }
147
163
 
164
+ async getCurrentWALFile () {
165
+ if (this.status !== 'open') {
166
+ throw new ModuleError('Database is not open', {
167
+ code: 'LEVEL_DATABASE_NOT_OPEN'
168
+ })
169
+ }
170
+
171
+ return binding.db_get_current_wal_file(this[kContext])
172
+ }
173
+
174
+ async getSortedWALFiles () {
175
+ if (this.status !== 'open') {
176
+ throw new ModuleError('Database is not open', {
177
+ code: 'LEVEL_DATABASE_NOT_OPEN'
178
+ })
179
+ }
180
+
181
+ return binding.db_get_sorted_wal_files(this[kContext])
182
+ }
183
+
148
184
  async flushWAL (options) {
185
+ if (this.status !== 'open') {
186
+ throw new ModuleError('Database is not open', {
187
+ code: 'LEVEL_DATABASE_NOT_OPEN'
188
+ })
189
+ }
190
+
149
191
  binding.db_flush_wal(this[kContext], options)
150
192
  }
151
193
 
@@ -195,6 +237,29 @@ class RocksLevel extends AbstractLevel {
195
237
  })
196
238
  }
197
239
 
240
+ options = {
241
+ since: options?.since ?? 0,
242
+ keys: options?.keys ?? true,
243
+ values: options?.values ?? true,
244
+ data: options?.data ?? true
245
+ }
246
+
247
+ if (typeof options.since !== 'number') {
248
+ throw new TypeError("'since' must be nully or a number")
249
+ }
250
+
251
+ if (typeof options.keys !== 'boolean') {
252
+ throw new TypeError("'keys' must be nully or a boolean")
253
+ }
254
+
255
+ if (typeof options.values !== 'boolean') {
256
+ throw new TypeError("'values' must be nully or a boolean")
257
+ }
258
+
259
+ if (typeof options.data !== 'boolean') {
260
+ throw new TypeError("'data' must be nully or a boolean")
261
+ }
262
+
198
263
  class Updates {
199
264
  constructor (db, options) {
200
265
  this.context = binding.updates_init(db[kContext], options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "7.0.29",
3
+ "version": "7.0.32",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",