@nxtedition/rocksdb 7.0.30 → 7.0.33

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
@@ -814,9 +814,8 @@ NAPI_METHOD(db_open) {
814
814
 
815
815
  rocksdb::Options dbOptions;
816
816
 
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);
817
+ dbOptions.IncreaseParallelism(Uint32Property(env, argv[2], "parallelism")
818
+ .value_or(std::max<uint32_t>(1, std::thread::hardware_concurrency() / 2)));
820
819
 
821
820
  dbOptions.create_if_missing = BooleanProperty(env, argv[2], "createIfMissing").value_or(true);
822
821
  dbOptions.error_if_exists = BooleanProperty(env, argv[2], "errorIfExists").value_or(false);
@@ -824,8 +823,6 @@ NAPI_METHOD(db_open) {
824
823
  dbOptions.write_dbid_to_manifest = true;
825
824
  dbOptions.use_adaptive_mutex = true; // We don't have soo many threads in the libuv thread pool...
826
825
  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
826
  dbOptions.WAL_ttl_seconds = Uint32Property(env, argv[2], "walTTL").value_or(0) / 1e3;
830
827
  dbOptions.WAL_size_limit_MB = Uint32Property(env, argv[2], "walSizeLimit").value_or(0) / 1e6;
831
828
  dbOptions.wal_compression = BooleanProperty(env, argv[2], "walCompression").value_or(false)
@@ -836,46 +833,6 @@ NAPI_METHOD(db_open) {
836
833
  dbOptions.fail_if_options_file_error = true;
837
834
  dbOptions.manual_wal_flush = BooleanProperty(env, argv[2], "manualWalFlush").value_or(false);
838
835
 
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, &parallelism));
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
-
879
836
  // TODO (feat): dbOptions.listeners
880
837
 
881
838
  const auto infoLogLevel = StringProperty(env, argv[2], "infoLogLevel").value_or("");
@@ -939,7 +896,7 @@ NAPI_METHOD(db_open) {
939
896
  auto worker = new OpenWorker(env, database, argv[3], location, dbOptions, columnsFamilies);
940
897
  worker->Queue(env);
941
898
 
942
- return ret;
899
+ return 0;
943
900
  }
944
901
 
945
902
  struct CloseWorker final : public Worker {
@@ -1149,15 +1106,30 @@ NAPI_METHOD(updates_init) {
1149
1106
  Database* database;
1150
1107
  NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1151
1108
 
1152
- const auto seqNumber = Int64Property(env, argv[1], "since").value_or(database->db_->GetLatestSequenceNumber());
1153
- const auto keys = BooleanProperty(env, argv[1], "keys").value_or(true);
1154
- const auto values = BooleanProperty(env, argv[1], "values").value_or(true);
1155
- 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));
1156
1128
 
1157
1129
  rocksdb::ColumnFamilyHandle* column;
1158
1130
  NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[1], &column, false));
1159
1131
 
1160
- 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);
1161
1133
 
1162
1134
  napi_value result;
1163
1135
  NAPI_STATUS_THROWS(napi_create_external(env, updates.get(), Finalize<Updates>, updates.get(), &result));
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
- this[kOptions] = binding.db_open(this[kContext], this[kLocation], options, onOpen)
86
+ binding.db_open(this[kContext], this[kLocation], options, onOpen)
76
87
  })
77
88
  } else {
78
- this[kOptions] = binding.db_open(this[kContext], this[kLocation], options, onOpen)
89
+ binding.db_open(this[kContext], this[kLocation], options, onOpen)
79
90
  }
80
91
  }
81
92
 
@@ -151,14 +162,32 @@ class RocksLevel extends AbstractLevel {
151
162
  }
152
163
 
153
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
+
154
171
  return binding.db_get_current_wal_file(this[kContext])
155
172
  }
156
173
 
157
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
+
158
181
  return binding.db_get_sorted_wal_files(this[kContext])
159
182
  }
160
183
 
161
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
+
162
191
  binding.db_flush_wal(this[kContext], options)
163
192
  }
164
193
 
@@ -208,6 +237,34 @@ class RocksLevel extends AbstractLevel {
208
237
  })
209
238
  }
210
239
 
240
+ options = {
241
+ since: options?.since ?? 0,
242
+ keys: options?.keys ?? true,
243
+ values: options?.values ?? true,
244
+ data: options?.data ?? true,
245
+ column: options?.column ?? null
246
+ }
247
+
248
+ if (typeof options.since !== 'number') {
249
+ throw new TypeError("'since' must be nully or a number")
250
+ }
251
+
252
+ if (typeof options.keys !== 'boolean') {
253
+ throw new TypeError("'keys' must be nully or a boolean")
254
+ }
255
+
256
+ if (typeof options.values !== 'boolean') {
257
+ throw new TypeError("'values' must be nully or a boolean")
258
+ }
259
+
260
+ if (typeof options.data !== 'boolean') {
261
+ throw new TypeError("'data' must be nully or a boolean")
262
+ }
263
+
264
+ if (typeof options.column !== 'object') {
265
+ throw new TypeError("'column' must be nully or a object")
266
+ }
267
+
211
268
  class Updates {
212
269
  constructor (db, options) {
213
270
  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.30",
3
+ "version": "7.0.33",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",