autobee 2.5.5 → 2.6.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/README.md +9 -0
- package/index.js +6 -1
- package/lib/fast-forward.js +31 -0
- package/lib/writers.js +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,6 +81,7 @@ Options:
|
|
|
81
81
|
optimistic: true, // allow optimistic writes from unknown writers
|
|
82
82
|
isTrusted (key, reference) {}, // do we trust this writer, see Fast-forward
|
|
83
83
|
mostRecentTrusted (target, reference) {}, // the head we vouch for, see Fast-forward
|
|
84
|
+
warmup (view) {}, // prepare a candidate view, see Fast-forward
|
|
84
85
|
ackThreshold: 32, // flushes we may fall behind before acking, see Acking
|
|
85
86
|
fastForward: {} // see Fast-forward
|
|
86
87
|
}
|
|
@@ -255,6 +256,14 @@ Return the oplog head you most recently vouched for, given the `target` view bei
|
|
|
255
256
|
|
|
256
257
|
Called at flush time to stamp your own oplog (with your view as `target` and a `null` reference), and again per candidate during discovery.
|
|
257
258
|
|
|
259
|
+
#### `warmup(view)`
|
|
260
|
+
|
|
261
|
+
Prepare a candidate `view` before the fast-forward onto it is applied.
|
|
262
|
+
|
|
263
|
+
Called as soon as the candidate's view head is known, and runs alongside the block downloads the fast-forward is already doing rather than after them. Throw or reject to reject the candidate: the fast-forward is abandoned and the usual apply path catches up instead.
|
|
264
|
+
|
|
265
|
+
`view` is opened and closed through the `open` and `close` handlers, so don't build or close a db of your own.
|
|
266
|
+
|
|
258
267
|
#### `fastForward.boot`
|
|
259
268
|
|
|
260
269
|
```js
|
package/index.js
CHANGED
|
@@ -134,6 +134,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
134
134
|
this._now = handlers.now || Date.now // overridable for clock-drift tests
|
|
135
135
|
this._preapply = handlers.preapply || null
|
|
136
136
|
this._preApplied = false
|
|
137
|
+
this._warmup = handlers.warmup || null
|
|
137
138
|
this._hasApply = !!handlers.apply
|
|
138
139
|
this._hasUpdate = !!handlers.update
|
|
139
140
|
this._needsUpdate = false
|
|
@@ -440,7 +441,11 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
440
441
|
const v = oplog.op.views.view
|
|
441
442
|
if (!v) return null
|
|
442
443
|
|
|
443
|
-
return
|
|
444
|
+
return this.openView({ key: v.key, length: v.start + v.length })
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
openView(head) {
|
|
448
|
+
return new ApplyView(this.bee.checkout({ key: head.key, length: head.length }), this)
|
|
444
449
|
}
|
|
445
450
|
|
|
446
451
|
openCore(key) {
|
package/lib/fast-forward.js
CHANGED
|
@@ -30,6 +30,8 @@ class FastForward {
|
|
|
30
30
|
this.running = null
|
|
31
31
|
this.failed = false
|
|
32
32
|
this.cores = []
|
|
33
|
+
this.warmup = null
|
|
34
|
+
this.warmupView = null
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
static DEFAULT_TIMEOUT = DEFAULT_OP_TIMEOUT
|
|
@@ -170,6 +172,8 @@ class FastForward {
|
|
|
170
172
|
|
|
171
173
|
const promises = []
|
|
172
174
|
|
|
175
|
+
if (this._startWarmup()) promises.push(this.warmup)
|
|
176
|
+
|
|
173
177
|
// ensure local key is locally available always
|
|
174
178
|
promises.push(this.system.get(this.auto.local.key, { timeout: this.timeout }))
|
|
175
179
|
|
|
@@ -199,6 +203,17 @@ class FastForward {
|
|
|
199
203
|
}
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
_startWarmup() {
|
|
207
|
+
if (!this.auto._warmup || !this.system.view.length) return false
|
|
208
|
+
|
|
209
|
+
this.warmupView = this.auto.openView(this.system.view)
|
|
210
|
+
|
|
211
|
+
// ensure thenable
|
|
212
|
+
this.warmup = Promise.resolve(this.auto._warmup(this.warmupView.view))
|
|
213
|
+
|
|
214
|
+
return true
|
|
215
|
+
}
|
|
216
|
+
|
|
202
217
|
async _resolveLength() {
|
|
203
218
|
const core = this.auto.store.get({ key: this.head.key })
|
|
204
219
|
this.cores.push(core)
|
|
@@ -278,6 +293,22 @@ class FastForward {
|
|
|
278
293
|
async close() {
|
|
279
294
|
this.destroyed = true
|
|
280
295
|
this.clearRequests()
|
|
296
|
+
|
|
297
|
+
// close view to cancel inflight reads
|
|
298
|
+
if (this.warmupView) {
|
|
299
|
+
const view = this.warmupView
|
|
300
|
+
this.warmupView = null
|
|
301
|
+
await view.close()
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (this.warmup) {
|
|
305
|
+
try {
|
|
306
|
+
await this.warmup
|
|
307
|
+
} catch (err) {
|
|
308
|
+
safetyCatch(err)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
281
312
|
if (this.system) await this.system.close()
|
|
282
313
|
for (const core of this.cores) await core.close()
|
|
283
314
|
}
|
package/lib/writers.js
CHANGED
|
@@ -134,10 +134,20 @@ class ActiveWriters {
|
|
|
134
134
|
// peeked batches were read against the pre-reboot system, drop them
|
|
135
135
|
this._pendingBuffer.clear()
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
const local = this.localWriter && !this.localWriter.isClosed ? this.localWriter : null
|
|
138
|
+
|
|
139
|
+
const info = []
|
|
140
|
+
for (const w of this.active.values()) {
|
|
141
|
+
if (w.isFrozen && w !== this.localWriter) continue
|
|
142
|
+
info.push(w.system.get(w.core.key))
|
|
139
143
|
}
|
|
140
144
|
|
|
145
|
+
if (local) info.push(local.system.get(local.core.key))
|
|
146
|
+
|
|
147
|
+
await Promise.all(info)
|
|
148
|
+
|
|
149
|
+
if (local) await this.updateLocalState()
|
|
150
|
+
|
|
141
151
|
for (const writer of this.active.values()) {
|
|
142
152
|
if (writer.isFrozen && writer !== this.localWriter) await writer.detachAndClose()
|
|
143
153
|
else await writer.reset()
|