rocksdb-native 3.5.2 → 3.5.3
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/index.js +4 -16
- package/lib/batch.js +42 -25
- package/lib/iterator.js +15 -9
- package/lib/snapshot.js +1 -1
- package/lib/state.js +48 -21
- package/package.json +2 -3
package/index.js
CHANGED
|
@@ -101,11 +101,11 @@ class RocksDB {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
isIdle() {
|
|
104
|
-
return this._state.
|
|
104
|
+
return this._state.handles.isIdle()
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
idle() {
|
|
108
|
-
return this._state.
|
|
108
|
+
return this._state.handles.idle()
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
iterator(range, opts) {
|
|
@@ -165,26 +165,14 @@ class RocksDB {
|
|
|
165
165
|
await batch.flush()
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
// used by iterators/batches to ensure no gc/close when active
|
|
169
|
-
|
|
170
168
|
_ref() {
|
|
171
169
|
if (this._snapshot) this._snapshot.ref()
|
|
172
|
-
this._state.
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
_refBatch() {
|
|
176
|
-
this._ref()
|
|
177
|
-
this._state.activeBatches.inc()
|
|
170
|
+
this._state.handles.inc()
|
|
178
171
|
}
|
|
179
172
|
|
|
180
173
|
_unref() {
|
|
181
174
|
if (this._snapshot) this._snapshot.unref()
|
|
182
|
-
this._state.
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
_unrefBatch() {
|
|
186
|
-
this._unref()
|
|
187
|
-
this._state.activeBatches.dec()
|
|
175
|
+
this._state.handles.dec()
|
|
188
176
|
}
|
|
189
177
|
}
|
|
190
178
|
|
package/lib/batch.js
CHANGED
|
@@ -8,7 +8,7 @@ class RocksDBBatch {
|
|
|
8
8
|
constructor(db, opts = {}) {
|
|
9
9
|
const { capacity = 8, autoDestroy = false } = opts
|
|
10
10
|
|
|
11
|
-
db.
|
|
11
|
+
db._ref()
|
|
12
12
|
|
|
13
13
|
this._db = db
|
|
14
14
|
this._destroyed = false
|
|
@@ -32,7 +32,7 @@ class RocksDBBatch {
|
|
|
32
32
|
_reuse(db, opts = {}) {
|
|
33
33
|
const { autoDestroy = false } = opts
|
|
34
34
|
|
|
35
|
-
db.
|
|
35
|
+
db._ref()
|
|
36
36
|
|
|
37
37
|
this._db = db
|
|
38
38
|
this._destroyed = false
|
|
@@ -48,6 +48,7 @@ class RocksDBBatch {
|
|
|
48
48
|
this._request = null
|
|
49
49
|
this._resolve = null
|
|
50
50
|
this._reject = null
|
|
51
|
+
this._db._state.io.dec()
|
|
51
52
|
|
|
52
53
|
if (this._autoDestroy === true) this.destroy()
|
|
53
54
|
|
|
@@ -81,7 +82,7 @@ class RocksDBBatch {
|
|
|
81
82
|
|
|
82
83
|
if (this._promises.length) this._abort()
|
|
83
84
|
|
|
84
|
-
this._db.
|
|
85
|
+
this._db._unref()
|
|
85
86
|
this._onfree()
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -121,15 +122,19 @@ class RocksDBBatch {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
async _flush() {
|
|
124
|
-
const state = this._db._state
|
|
125
|
-
|
|
126
125
|
if (this._handle === null) await this.ready()
|
|
127
|
-
if (state.resumed !== null) await state.resumed.promise
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this._db.
|
|
127
|
+
this._db._state.io.inc()
|
|
128
|
+
|
|
129
|
+
if (this._db._state.resumed !== null) {
|
|
130
|
+
const resumed = await this._db._state.resumed.promise
|
|
131
|
+
|
|
132
|
+
if (!resumed && !this._destroyed) {
|
|
133
|
+
this._destroyed = true
|
|
134
|
+
this._abort()
|
|
135
|
+
this._db._state.io.dec()
|
|
136
|
+
this._db._unref()
|
|
137
|
+
}
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
|
|
@@ -170,16 +175,22 @@ exports.ReadBatch = class RocksDBReadBatch extends RocksDBBatch {
|
|
|
170
175
|
|
|
171
176
|
async _flush() {
|
|
172
177
|
await super._flush()
|
|
178
|
+
|
|
173
179
|
if (this._destroyed) return
|
|
174
180
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
try {
|
|
182
|
+
binding.read(
|
|
183
|
+
this._db._state._handle,
|
|
184
|
+
this._handle,
|
|
185
|
+
this._operations,
|
|
186
|
+
this._db._snapshot ? this._db._snapshot._handle : null,
|
|
187
|
+
this,
|
|
188
|
+
this._onread
|
|
189
|
+
)
|
|
190
|
+
} catch (err) {
|
|
191
|
+
this._db._state.io.dec()
|
|
192
|
+
throw err
|
|
193
|
+
}
|
|
183
194
|
}
|
|
184
195
|
|
|
185
196
|
_onread(errs, values) {
|
|
@@ -238,15 +249,21 @@ exports.WriteBatch = class RocksDBWriteBatch extends RocksDBBatch {
|
|
|
238
249
|
|
|
239
250
|
async _flush() {
|
|
240
251
|
await super._flush()
|
|
252
|
+
|
|
241
253
|
if (this._destroyed) return
|
|
242
254
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
255
|
+
try {
|
|
256
|
+
binding.write(
|
|
257
|
+
this._db._state._handle,
|
|
258
|
+
this._handle,
|
|
259
|
+
this._operations,
|
|
260
|
+
this,
|
|
261
|
+
this._onwrite
|
|
262
|
+
)
|
|
263
|
+
} catch (err) {
|
|
264
|
+
this._db._state.io.dec()
|
|
265
|
+
throw err
|
|
266
|
+
}
|
|
250
267
|
}
|
|
251
268
|
|
|
252
269
|
_onwrite(err) {
|
package/lib/iterator.js
CHANGED
|
@@ -30,6 +30,7 @@ module.exports = class RocksDBIterator extends Readable {
|
|
|
30
30
|
this._reverse = reverse
|
|
31
31
|
this._limit = limit < 0 ? Infinity : limit
|
|
32
32
|
this._capacity = capacity
|
|
33
|
+
this._opened = false
|
|
33
34
|
|
|
34
35
|
this._pendingOpen = null
|
|
35
36
|
this._pendingRead = null
|
|
@@ -44,12 +45,15 @@ module.exports = class RocksDBIterator extends Readable {
|
|
|
44
45
|
_onopen(err) {
|
|
45
46
|
const cb = this._pendingOpen
|
|
46
47
|
this._pendingOpen = null
|
|
48
|
+
this._opened = true
|
|
49
|
+
this._db._state.io.dec()
|
|
47
50
|
cb(err)
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
_onread(err, keys, values) {
|
|
51
54
|
const cb = this._pendingRead
|
|
52
55
|
this._pendingRead = null
|
|
56
|
+
this._db._state.io.dec()
|
|
53
57
|
if (err) return cb(err)
|
|
54
58
|
|
|
55
59
|
const n = keys.length
|
|
@@ -97,10 +101,8 @@ module.exports = class RocksDBIterator extends Readable {
|
|
|
97
101
|
async _open(cb) {
|
|
98
102
|
await this.ready()
|
|
99
103
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (state._suspending || state._suspended) {
|
|
103
|
-
return cb(new Error('Database is suspended'))
|
|
104
|
+
if (this._db._state.resumed !== null) {
|
|
105
|
+
await this._db._state.resumed.promise
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
this._pendingOpen = cb
|
|
@@ -120,18 +122,20 @@ module.exports = class RocksDBIterator extends Readable {
|
|
|
120
122
|
this._onclose,
|
|
121
123
|
this._onread
|
|
122
124
|
)
|
|
123
|
-
}
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
this._db._state.io.inc()
|
|
127
|
+
}
|
|
127
128
|
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
async _read(cb) {
|
|
130
|
+
if (this._db._state.resumed !== null) {
|
|
131
|
+
await this._db._state.resumed.promise
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
this._pendingRead = cb
|
|
133
135
|
|
|
134
136
|
binding.iteratorRead(this._handle, Math.min(this._capacity, this._limit))
|
|
137
|
+
|
|
138
|
+
this._db._state.io.inc()
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
async _destroy(cb) {
|
|
@@ -139,6 +143,8 @@ module.exports = class RocksDBIterator extends Readable {
|
|
|
139
143
|
|
|
140
144
|
this._pendingDestroy = cb
|
|
141
145
|
|
|
146
|
+
if (this._opened === false) return this._onclose(null)
|
|
147
|
+
|
|
142
148
|
binding.iteratorClose(this._handle)
|
|
143
149
|
}
|
|
144
150
|
|
package/lib/snapshot.js
CHANGED
package/lib/state.js
CHANGED
|
@@ -25,8 +25,8 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
25
25
|
|
|
26
26
|
this.path = path
|
|
27
27
|
this.db = db
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
28
|
+
this.handles = new RefCounter()
|
|
29
|
+
this.io = new RefCounter()
|
|
30
30
|
this.sessions = []
|
|
31
31
|
this.columnFamilies = [columnFamily]
|
|
32
32
|
this.deferSnapshotInit = true
|
|
@@ -146,6 +146,7 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
146
146
|
await promise
|
|
147
147
|
|
|
148
148
|
this.deferSnapshotInit = false
|
|
149
|
+
|
|
149
150
|
for (const session of this.sessions) {
|
|
150
151
|
if (session._snapshot) session._snapshot._init()
|
|
151
152
|
}
|
|
@@ -157,11 +158,17 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
157
158
|
}
|
|
158
159
|
|
|
159
160
|
async _close() {
|
|
160
|
-
if (this.resumed)
|
|
161
|
-
|
|
161
|
+
if (this.resumed) {
|
|
162
|
+
const resumed = this.resumed
|
|
163
|
+
this.resumed = null
|
|
164
|
+
resumed.resolve(false)
|
|
165
|
+
}
|
|
162
166
|
|
|
163
|
-
while (this.
|
|
167
|
+
while (!this.handles.isIdle()) await this.handles.idle()
|
|
168
|
+
|
|
169
|
+
while (this.sessions.length > 0) {
|
|
164
170
|
await this.sessions[this.sessions.length - 1].close()
|
|
171
|
+
}
|
|
165
172
|
|
|
166
173
|
for (const columnFamily of this.columnFamilies) columnFamily.destroy()
|
|
167
174
|
|
|
@@ -185,6 +192,20 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
185
192
|
async flush(db, opts) {
|
|
186
193
|
if (this.opened === false) await this.ready()
|
|
187
194
|
|
|
195
|
+
this.handles.inc()
|
|
196
|
+
this.io.inc()
|
|
197
|
+
|
|
198
|
+
if (this.resumed !== null) {
|
|
199
|
+
const resumed = await this.resumed.promise
|
|
200
|
+
|
|
201
|
+
if (!resumed) {
|
|
202
|
+
this.handles.dec()
|
|
203
|
+
this.io.dec()
|
|
204
|
+
|
|
205
|
+
throw new Error('RocksDB session is closed')
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
188
209
|
const req = { resolve: null, reject: null, handle: null }
|
|
189
210
|
|
|
190
211
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -192,14 +213,19 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
192
213
|
req.reject = reject
|
|
193
214
|
})
|
|
194
215
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
216
|
+
try {
|
|
217
|
+
req.handle = binding.flush(
|
|
218
|
+
this._handle,
|
|
219
|
+
db._columnFamily._handle,
|
|
220
|
+
req,
|
|
221
|
+
onflush
|
|
222
|
+
)
|
|
201
223
|
|
|
202
|
-
|
|
224
|
+
await promise
|
|
225
|
+
} finally {
|
|
226
|
+
this.handles.dec()
|
|
227
|
+
this.io.dec()
|
|
228
|
+
}
|
|
203
229
|
|
|
204
230
|
function onflush(err) {
|
|
205
231
|
if (err) req.reject(new Error(err))
|
|
@@ -208,16 +234,17 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
208
234
|
}
|
|
209
235
|
|
|
210
236
|
async suspend() {
|
|
211
|
-
if (this._suspended === true) return
|
|
212
237
|
if (this._suspending === null) this._suspending = this._suspend()
|
|
213
238
|
return this._suspending
|
|
214
239
|
}
|
|
215
240
|
|
|
216
241
|
async _suspend() {
|
|
217
|
-
if (this._resuming !== null) await this._resuming
|
|
218
242
|
if (this.opened === false) await this.ready()
|
|
243
|
+
if (this._resuming !== null) await this._resuming
|
|
244
|
+
if (this._suspended === true) return
|
|
245
|
+
|
|
246
|
+
while (!this.io.isIdle()) await this.io.idle()
|
|
219
247
|
|
|
220
|
-
while (!this.activeBatches.isIdle()) await this.activeBatches.idle()
|
|
221
248
|
this.resumed = rrp()
|
|
222
249
|
|
|
223
250
|
const req = { resolve: null, reject: null, handle: null }
|
|
@@ -227,9 +254,9 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
227
254
|
req.reject = reject
|
|
228
255
|
})
|
|
229
256
|
|
|
230
|
-
req.handle = binding.suspend(this._handle, req, onsuspend)
|
|
231
|
-
|
|
232
257
|
try {
|
|
258
|
+
req.handle = binding.suspend(this._handle, req, onsuspend)
|
|
259
|
+
|
|
233
260
|
await promise
|
|
234
261
|
|
|
235
262
|
this._suspended = true
|
|
@@ -244,14 +271,14 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
244
271
|
}
|
|
245
272
|
|
|
246
273
|
resume() {
|
|
247
|
-
if (this._suspended === false) return
|
|
248
274
|
if (this._resuming === null) this._resuming = this._resume()
|
|
249
275
|
return this._resuming
|
|
250
276
|
}
|
|
251
277
|
|
|
252
278
|
async _resume() {
|
|
253
|
-
if (this._suspending !== null) await this._suspending
|
|
254
279
|
if (this.opened === false) await this.ready()
|
|
280
|
+
if (this._suspending !== null) await this._suspending
|
|
281
|
+
if (this._suspended === false) return
|
|
255
282
|
|
|
256
283
|
const req = { resolve: null, reject: null, handle: null }
|
|
257
284
|
|
|
@@ -260,9 +287,9 @@ module.exports = class RocksDBState extends ReadyResource {
|
|
|
260
287
|
req.reject = reject
|
|
261
288
|
})
|
|
262
289
|
|
|
263
|
-
req.handle = binding.resume(this._handle, req, onresume)
|
|
264
|
-
|
|
265
290
|
try {
|
|
291
|
+
req.handle = binding.resume(this._handle, req, onresume)
|
|
292
|
+
|
|
266
293
|
await promise
|
|
267
294
|
|
|
268
295
|
this._suspended = false
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rocksdb-native",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "librocksdb bindings for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -50,7 +50,6 @@
|
|
|
50
50
|
"cmake-fetch": "^1.0.1",
|
|
51
51
|
"cmake-napi": "^1.0.6",
|
|
52
52
|
"prettier": "^3.4.1",
|
|
53
|
-
"prettier-config-standard": "^7.0.0"
|
|
54
|
-
"test-tmp": "^1.2.0"
|
|
53
|
+
"prettier-config-standard": "^7.0.0"
|
|
55
54
|
}
|
|
56
55
|
}
|