rocksdb-native 3.5.3 → 3.5.5

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
@@ -13,7 +13,7 @@ if(target MATCHES "win32")
13
13
  add_compile_options(/MT$<$<CONFIG:Debug>:d>)
14
14
  endif()
15
15
 
16
- fetch_package("github:holepunchto/librocksdb#d2b6760")
16
+ fetch_package("github:holepunchto/librocksdb#dbebf66")
17
17
 
18
18
  add_bare_module(rocksdb_native_bare)
19
19
 
package/binding.c CHANGED
@@ -192,10 +192,8 @@ rocksdb_native__on_open(rocksdb_open_t *handle, int status) {
192
192
 
193
193
  js_value_t **elements = malloc(len * sizeof(js_value_t *));
194
194
 
195
- uint32_t fetched;
196
- err = js_get_array_elements(env, column_families, elements, len, 0, &fetched);
195
+ err = js_get_array_elements(env, column_families, elements, len, 0, NULL);
197
196
  assert(err == 0);
198
- assert(fetched == len);
199
197
 
200
198
  for (uint32_t i = 0; i < len; i++) {
201
199
  js_value_t *handle = elements[i];
@@ -397,10 +395,8 @@ rocksdb_native_open(js_env_t *env, js_callback_info_t *info) {
397
395
 
398
396
  js_value_t **elements = malloc(len * sizeof(js_value_t *));
399
397
 
400
- uint32_t fetched;
401
- err = js_get_array_elements(env, argv[3], elements, len, 0, &fetched);
398
+ err = js_get_array_elements(env, argv[3], elements, len, 0, NULL);
402
399
  assert(err == 0);
403
- assert(fetched == len);
404
400
 
405
401
  for (uint32_t i = 0; i < len; i++) {
406
402
  js_value_t *handle = elements[i];
@@ -1410,10 +1406,8 @@ rocksdb_native_read(js_env_t *env, js_callback_info_t *info) {
1410
1406
 
1411
1407
  js_value_t **elements = malloc(len * sizeof(js_value_t *));
1412
1408
 
1413
- uint32_t fetched;
1414
- err = js_get_array_elements(env, argv[2], elements, len, 0, &fetched);
1409
+ err = js_get_array_elements(env, argv[2], elements, len, 0, NULL);
1415
1410
  assert(err == 0);
1416
- assert(fetched == len);
1417
1411
 
1418
1412
  for (uint32_t i = 0; i < len; i++) {
1419
1413
  js_value_t *read = elements[i];
@@ -1614,10 +1608,8 @@ rocksdb_native_write(js_env_t *env, js_callback_info_t *info) {
1614
1608
 
1615
1609
  js_value_t **elements = malloc(len * sizeof(js_value_t *));
1616
1610
 
1617
- uint32_t fetched;
1618
- err = js_get_array_elements(env, argv[2], elements, len, 0, &fetched);
1611
+ err = js_get_array_elements(env, argv[2], elements, len, 0, NULL);
1619
1612
  assert(err == 0);
1620
- assert(fetched == len);
1621
1613
 
1622
1614
  for (uint32_t i = 0; i < len; i++) {
1623
1615
  js_value_t *write = elements[i];
package/index.js CHANGED
@@ -81,8 +81,9 @@ class RocksDB {
81
81
  if (this._index !== -1) this._state.removeSession(this)
82
82
 
83
83
  if (force) {
84
- while (this._state.sessions.length > 0)
84
+ while (this._state.sessions.length > 0) {
85
85
  await this._state.sessions[this._state.sessions.length - 1].close()
86
+ }
86
87
  }
87
88
 
88
89
  return this.isRoot() ? this._state.close() : Promise.resolve()
package/lib/batch.js CHANGED
@@ -96,6 +96,8 @@ class RocksDBBatch {
96
96
  const promise = this._promises[i]
97
97
  if (promise !== null) promise.reject(new Error('Batch is destroyed'))
98
98
  }
99
+
100
+ this._onfinished(new Error('Batch is destroyed'))
99
101
  }
100
102
 
101
103
  async flush() {
@@ -129,11 +131,14 @@ class RocksDBBatch {
129
131
  if (this._db._state.resumed !== null) {
130
132
  const resumed = await this._db._state.resumed.promise
131
133
 
132
- if (!resumed && !this._destroyed) {
133
- this._destroyed = true
134
- this._abort()
135
- this._db._state.io.dec()
136
- this._db._unref()
134
+ if (!resumed) {
135
+ if (this._destroyed) {
136
+ this._db._state.io.dec()
137
+ } else {
138
+ this._destroyed = true
139
+ this._abort()
140
+ this._db._unref()
141
+ }
137
142
  }
138
143
  }
139
144
  }
package/lib/iterator.js CHANGED
@@ -75,6 +75,7 @@ module.exports = class RocksDBIterator extends Readable {
75
75
  _onclose(err) {
76
76
  const cb = this._pendingDestroy
77
77
  this._pendingDestroy = null
78
+ this._db._state.io.dec()
78
79
  this._db._unref()
79
80
  cb(err)
80
81
  }
@@ -101,51 +102,84 @@ module.exports = class RocksDBIterator extends Readable {
101
102
  async _open(cb) {
102
103
  await this.ready()
103
104
 
105
+ this._db._state.io.inc()
106
+
104
107
  if (this._db._state.resumed !== null) {
105
- await this._db._state.resumed.promise
108
+ const resumed = await this._db._state.resumed.promise
109
+
110
+ if (!resumed) {
111
+ this._db._state.io.dec()
112
+
113
+ return cb(new Error('RocksDB session is closed'))
114
+ }
106
115
  }
107
116
 
108
117
  this._pendingOpen = cb
109
118
 
110
- binding.iteratorOpen(
111
- this._db._state._handle,
112
- this._handle,
113
- this._db._columnFamily._handle,
114
- this._gt,
115
- this._gte,
116
- this._lt,
117
- this._lte,
118
- this._reverse,
119
- this._db._snapshot ? this._db._snapshot._handle : null,
120
- this,
121
- this._onopen,
122
- this._onclose,
123
- this._onread
124
- )
125
-
126
- this._db._state.io.inc()
119
+ try {
120
+ binding.iteratorOpen(
121
+ this._db._state._handle,
122
+ this._handle,
123
+ this._db._columnFamily._handle,
124
+ this._gt,
125
+ this._gte,
126
+ this._lt,
127
+ this._lte,
128
+ this._reverse,
129
+ this._db._snapshot ? this._db._snapshot._handle : null,
130
+ this,
131
+ this._onopen,
132
+ this._onclose,
133
+ this._onread
134
+ )
135
+ } catch (err) {
136
+ this._db._state.io.dec()
137
+ throw err
138
+ }
127
139
  }
128
140
 
129
141
  async _read(cb) {
142
+ this._db._state.io.inc()
143
+
130
144
  if (this._db._state.resumed !== null) {
131
- await this._db._state.resumed.promise
145
+ const resumed = await this._db._state.resumed.promise
146
+
147
+ if (!resumed) {
148
+ this._db._state.io.dec()
149
+
150
+ return cb(new Error('RocksDB session is closed'))
151
+ }
132
152
  }
133
153
 
134
154
  this._pendingRead = cb
135
155
 
136
- binding.iteratorRead(this._handle, Math.min(this._capacity, this._limit))
137
-
138
- this._db._state.io.inc()
156
+ try {
157
+ binding.iteratorRead(this._handle, Math.min(this._capacity, this._limit))
158
+ } catch (err) {
159
+ this._db._state.io.dec()
160
+ throw err
161
+ }
139
162
  }
140
163
 
141
164
  async _destroy(cb) {
142
165
  await this.ready()
143
166
 
167
+ this._db._state.io.inc()
168
+
144
169
  this._pendingDestroy = cb
145
170
 
146
- if (this._opened === false) return this._onclose(null)
171
+ if (this._opened === false) {
172
+ this._db._state.io.dec()
147
173
 
148
- binding.iteratorClose(this._handle)
174
+ return this._onclose(null)
175
+ }
176
+
177
+ try {
178
+ binding.iteratorClose(this._handle)
179
+ } catch (err) {
180
+ this._db._state.io.dec()
181
+ throw err
182
+ }
149
183
  }
150
184
 
151
185
  _encodeKey(k) {
package/lib/state.js CHANGED
@@ -158,12 +158,9 @@ module.exports = class RocksDBState extends ReadyResource {
158
158
  }
159
159
 
160
160
  async _close() {
161
- if (this.resumed) {
162
- const resumed = this.resumed
163
- this.resumed = null
164
- resumed.resolve(false)
165
- }
161
+ if (this.resumed) this.resumed.resolve(false)
166
162
 
163
+ while (!this.io.isIdle()) await this.io.idle()
167
164
  while (!this.handles.isIdle()) await this.handles.idle()
168
165
 
169
166
  while (this.sessions.length > 0) {
@@ -192,14 +189,12 @@ module.exports = class RocksDBState extends ReadyResource {
192
189
  async flush(db, opts) {
193
190
  if (this.opened === false) await this.ready()
194
191
 
195
- this.handles.inc()
196
192
  this.io.inc()
197
193
 
198
194
  if (this.resumed !== null) {
199
195
  const resumed = await this.resumed.promise
200
196
 
201
197
  if (!resumed) {
202
- this.handles.dec()
203
198
  this.io.dec()
204
199
 
205
200
  throw new Error('RocksDB session is closed')
@@ -223,7 +218,6 @@ module.exports = class RocksDBState extends ReadyResource {
223
218
 
224
219
  await promise
225
220
  } finally {
226
- this.handles.dec()
227
221
  this.io.dec()
228
222
  }
229
223
 
@@ -245,6 +239,7 @@ module.exports = class RocksDBState extends ReadyResource {
245
239
 
246
240
  while (!this.io.isIdle()) await this.io.idle()
247
241
 
242
+ this.io.inc()
248
243
  this.resumed = rrp()
249
244
 
250
245
  const req = { resolve: null, reject: null, handle: null }
@@ -261,6 +256,8 @@ module.exports = class RocksDBState extends ReadyResource {
261
256
 
262
257
  this._suspended = true
263
258
  } finally {
259
+ this.io.dec()
260
+
264
261
  this._suspending = null
265
262
  }
266
263
 
@@ -280,6 +277,8 @@ module.exports = class RocksDBState extends ReadyResource {
280
277
  if (this._suspending !== null) await this._suspending
281
278
  if (this._suspended === false) return
282
279
 
280
+ this.io.inc()
281
+
283
282
  const req = { resolve: null, reject: null, handle: null }
284
283
 
285
284
  const promise = new Promise((resolve, reject) => {
@@ -294,6 +293,8 @@ module.exports = class RocksDBState extends ReadyResource {
294
293
 
295
294
  this._suspended = false
296
295
  } finally {
296
+ this.io.dec()
297
+
297
298
  this._resuming = null
298
299
  }
299
300
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.5.3",
3
+ "version": "3.5.5",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",