rocksdb-native 3.9.2 → 3.10.0

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/CMakeLists.txt CHANGED
@@ -9,7 +9,7 @@ project(rocksdb_native C CXX)
9
9
 
10
10
  bare_target(target)
11
11
 
12
- fetch_package("github:holepunchto/librocksdb#3aaa9dc")
12
+ fetch_package("github:holepunchto/librocksdb#1fa9c8c")
13
13
  fetch_package("github:holepunchto/libjstl#098664c")
14
14
 
15
15
  add_bare_module(rocksdb_native_bare)
package/binding.cc CHANGED
@@ -155,6 +155,21 @@ rocksdb_native__on_free(js_env_t *env, char *data) {
155
155
  free(data);
156
156
  }
157
157
 
158
+ static int
159
+ rocksdb_native__try_create_external_arraybuffer(js_env_t *env, char *data, size_t len, js_arraybuffer_t &result) {
160
+ int err;
161
+
162
+ err = js_create_external_arraybuffer<rocksdb_native__on_free>(env, data, len, result);
163
+ if (err == 0) return 0;
164
+
165
+ err = js_create_arraybuffer(env, data, len, result);
166
+ assert(err == 0);
167
+
168
+ free(data);
169
+
170
+ return 0;
171
+ }
172
+
158
173
  static void
159
174
  rocksdb_native__on_column_family_teardown(void *data);
160
175
 
@@ -207,7 +222,7 @@ rocksdb_native__on_open(rocksdb_open_t *handle, int status) {
207
222
 
208
223
  rocksdb_column_family_t **handles = handle->handles;
209
224
 
210
- if (req->handle.error == NULL) {
225
+ if (req->handle.error == nullptr) {
211
226
  std::vector<js_arraybuffer_t> elements;
212
227
  err = js_get_array_elements(env, column_families, elements);
213
228
  assert(err == 0);
@@ -710,8 +725,8 @@ rocksdb_native_column_family_init(
710
725
  assert(err == 0);
711
726
 
712
727
  column_family->env = env;
713
- column_family->db = NULL;
714
- column_family->handle = NULL;
728
+ column_family->db = nullptr;
729
+ column_family->handle = nullptr;
715
730
 
716
731
  column_family->descriptor = (rocksdb_column_family_descriptor_t) {
717
732
  name,
@@ -747,7 +762,7 @@ rocksdb_native_column_family_destroy(
747
762
  ) {
748
763
  int err;
749
764
 
750
- if (column_family->handle == NULL) return;
765
+ if (column_family->handle == nullptr) return;
751
766
 
752
767
  err = rocksdb_column_family_destroy(column_family->db, column_family->handle);
753
768
  assert(err == 0);
@@ -757,7 +772,7 @@ rocksdb_native_column_family_destroy(
757
772
 
758
773
  column_family->ctx.reset();
759
774
 
760
- column_family->handle = NULL;
775
+ column_family->handle = nullptr;
761
776
  }
762
777
 
763
778
  static js_arraybuffer_t
@@ -1001,16 +1016,6 @@ rocksdb_native_iterator_close(js_env_t *env, js_arraybuffer_span_of_t<rocksdb_na
1001
1016
  req->active = true;
1002
1017
  }
1003
1018
 
1004
- static int
1005
- rocksdb_native_try_create_external_arraybuffer(js_env_t *env, char *data, size_t len, js_arraybuffer_t &result) {
1006
- int err;
1007
-
1008
- err = js_create_external_arraybuffer<rocksdb_native__on_free>(env, data, len, result);
1009
- if (err == 0) return 0;
1010
-
1011
- return js_create_arraybuffer(env, data, len, result);
1012
- }
1013
-
1014
1019
  static void
1015
1020
  rocksdb_native__on_iterator_read(rocksdb_iterator_t *handle, int status) {
1016
1021
  int err;
@@ -1026,7 +1031,7 @@ rocksdb_native__on_iterator_read(rocksdb_iterator_t *handle, int status) {
1026
1031
  size_t len = req->handle.len;
1027
1032
 
1028
1033
  if (db->exiting) {
1029
- if (status == 0 && req->handle.error == NULL) {
1034
+ if (status == 0 && req->handle.error == nullptr) {
1030
1035
  for (size_t i = 0; i < len; i++) {
1031
1036
  js_value_t *result;
1032
1037
 
@@ -1070,14 +1075,14 @@ rocksdb_native__on_iterator_read(rocksdb_iterator_t *handle, int status) {
1070
1075
 
1071
1076
  rocksdb_slice_t *key = &req->keys[i];
1072
1077
 
1073
- err = rocksdb_native_try_create_external_arraybuffer(env, const_cast<char *>(key->data), key->len, result);
1078
+ err = rocksdb_native__try_create_external_arraybuffer(env, const_cast<char *>(key->data), key->len, result);
1074
1079
  assert(err == 0);
1075
1080
 
1076
1081
  keys.push_back(result);
1077
1082
 
1078
1083
  rocksdb_slice_t *value = &req->values[i];
1079
1084
 
1080
- err = rocksdb_native_try_create_external_arraybuffer(env, const_cast<char *>(value->data), value->len, result);
1085
+ err = rocksdb_native__try_create_external_arraybuffer(env, const_cast<char *>(value->data), value->len, result);
1081
1086
  assert(err == 0);
1082
1087
 
1083
1088
  values.push_back(result);
@@ -1203,11 +1208,11 @@ rocksdb_native__on_read(rocksdb_read_batch_t *handle, int status) {
1203
1208
 
1204
1209
  rocksdb_slice_t *slice = &req->reads[i].value;
1205
1210
 
1206
- if (slice->data == NULL && slice->len == (size_t) -1) {
1207
- err = js_get_null(env, (js_value_t **) result);
1211
+ if (slice->data == nullptr && slice->len == size_t(-1)) {
1212
+ err = js_get_null(env, static_cast<js_value_t **>(result));
1208
1213
  assert(err == 0);
1209
1214
  } else {
1210
- err = rocksdb_native_try_create_external_arraybuffer(env, const_cast<char *>(slice->data), slice->len, result);
1215
+ err = rocksdb_native__try_create_external_arraybuffer(env, const_cast<char *>(slice->data), slice->len, result);
1211
1216
  assert(err == 0);
1212
1217
  }
1213
1218
 
@@ -1487,7 +1492,7 @@ rocksdb_native_write(
1487
1492
  }
1488
1493
  }
1489
1494
 
1490
- err = rocksdb_write(&db->handle, &req->handle, req->writes, len, NULL, rocksdb_native__on_write);
1495
+ err = rocksdb_write(&db->handle, &req->handle, req->writes, len, nullptr, rocksdb_native__on_write);
1491
1496
 
1492
1497
  if (err < 0) {
1493
1498
  err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
@@ -1567,7 +1572,7 @@ rocksdb_native_flush(
1567
1572
  req->env = env;
1568
1573
  req->handle.data = req;
1569
1574
 
1570
- err = rocksdb_flush(&db->handle, &req->handle, column_family->handle, NULL, rocksdb_native__on_flush);
1575
+ err = rocksdb_flush(&db->handle, &req->handle, column_family->handle, nullptr, rocksdb_native__on_flush);
1571
1576
 
1572
1577
  if (err < 0) {
1573
1578
  err = js_throw_error(env, uv_err_name(err), uv_strerror(err));
package/lib/batch.js CHANGED
@@ -214,18 +214,14 @@ exports.ReadBatch = class RocksDBReadBatch extends RocksDBBatch {
214
214
  let applied = true
215
215
 
216
216
  for (let i = 0, n = this._promises.length; i < n; i++) {
217
- const promise = this._promises[i]
218
- if (promise === null) continue
219
-
220
217
  const err = errs[i]
218
+ if (err) applied = false
221
219
 
222
- if (err) {
223
- applied = false
220
+ const promise = this._promises[i]
221
+ if (promise === null) continue
224
222
 
225
- promise.reject(new Error(err))
226
- } else {
227
- promise.resolve(values[i] ? this._decodeValue(Buffer.from(values[i])) : null)
228
- }
223
+ if (err) promise.reject(new Error(err))
224
+ else promise.resolve(values[i] ? this._decodeValue(Buffer.from(values[i])) : null)
229
225
  }
230
226
 
231
227
  this._onfinished(applied ? null : new Error('Batch was not applied'))
@@ -274,19 +270,14 @@ exports.WriteBatch = class RocksDBWriteBatch extends RocksDBBatch {
274
270
  }
275
271
 
276
272
  _onwrite(err) {
277
- let applied = true
273
+ const applied = !err
278
274
 
279
275
  for (let i = 0, n = this._promises.length; i < n; i++) {
280
276
  const promise = this._promises[i]
281
277
  if (promise === null) continue
282
278
 
283
- if (err) {
284
- applied = false
285
-
286
- promise.reject(new Error(err))
287
- } else {
288
- promise.resolve()
289
- }
279
+ if (err) promise.reject(new Error(err))
280
+ else promise.resolve()
290
281
  }
291
282
 
292
283
  this._onfinished(applied ? null : new Error('Batch was not applied'))
package/lib/iterator.js CHANGED
@@ -137,7 +137,8 @@ module.exports = class RocksDBIterator extends Readable {
137
137
  )
138
138
  } catch (err) {
139
139
  this._db._state.io.dec()
140
- throw err
140
+
141
+ cb(err)
141
142
  }
142
143
  }
143
144
 
@@ -160,7 +161,8 @@ module.exports = class RocksDBIterator extends Readable {
160
161
  binding.iteratorRead(this._handle, Math.min(this._capacity, this._limit))
161
162
  } catch (err) {
162
163
  this._db._state.io.dec()
163
- throw err
164
+
165
+ cb(err)
164
166
  }
165
167
  }
166
168
 
@@ -169,19 +171,22 @@ module.exports = class RocksDBIterator extends Readable {
169
171
 
170
172
  this._db._state.io.inc()
171
173
 
172
- this._pendingDestroy = cb
173
-
174
174
  if (this._opened === false) {
175
175
  this._db._state.io.dec()
176
+ this._db._unref()
176
177
 
177
- return this._onclose(null)
178
+ return cb(null)
178
179
  }
179
180
 
181
+ this._pendingDestroy = cb
182
+
180
183
  try {
181
184
  binding.iteratorClose(this._handle)
182
185
  } catch (err) {
183
186
  this._db._state.io.dec()
184
- throw err
187
+ this._db._unref()
188
+
189
+ cb(err)
185
190
  }
186
191
  }
187
192
 
package/lib/state.js CHANGED
@@ -27,7 +27,8 @@ module.exports = class RocksDBState extends ReadyResource {
27
27
  avoidUnnecessaryBlockingIO = false,
28
28
  skipStatsUpdateOnOpen = false,
29
29
  useDirectIOForFlushAndCompaction = false,
30
- maxFileOpeningThreads = 16
30
+ maxFileOpeningThreads = 16,
31
+ preopen = null
31
32
  } = opts
32
33
 
33
34
  this.path = path
@@ -44,6 +45,7 @@ module.exports = class RocksDBState extends ReadyResource {
44
45
  this._updating = false
45
46
  this._updatingSignal = new SignalPromise()
46
47
  this._columnsFlushed = false
48
+ this._preopen = preopen
47
49
  this._readBatches = []
48
50
  this._writeBatches = []
49
51
 
@@ -83,6 +85,7 @@ module.exports = class RocksDBState extends ReadyResource {
83
85
  }
84
86
 
85
87
  freeBatch(batch, writable) {
88
+ if (batch._capacity > 16) return
86
89
  const queue = writable ? this._writeBatches : this._readBatches
87
90
  if (queue.length >= MAX_BATCH_REUSE) return
88
91
  queue.push(batch)
@@ -135,6 +138,8 @@ module.exports = class RocksDBState extends ReadyResource {
135
138
  async _open() {
136
139
  await Promise.resolve() // allow column families to populate if ondemand
137
140
 
141
+ if (this._preopen) await this._preopen
142
+
138
143
  const req = { resolve: null, reject: null, handle: null }
139
144
 
140
145
  const promise = new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.9.2",
3
+ "version": "3.10.0",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",