autobee 2.0.0-rc.25 → 2.0.0-rc.26
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 +43 -10
- package/lib/writers.js +6 -1
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const asserts = require('./lib/asserts.js')
|
|
|
14
14
|
const boot = require('./lib/boot.js')
|
|
15
15
|
const { resolveWeight, currentWeight } = require('./lib/witness.js')
|
|
16
16
|
const encoding = require('./lib/encoding.js')
|
|
17
|
+
const { LEGACY_OPLOG_VERSION } = require('./lib/constants.js')
|
|
17
18
|
const FastForward = require('./lib/fast-forward.js')
|
|
18
19
|
const System = require('./lib/system.js')
|
|
19
20
|
const ApplyCalls = require('./lib/apply-calls.js')
|
|
@@ -527,12 +528,12 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
527
528
|
this.stats.drains++
|
|
528
529
|
|
|
529
530
|
if (this.bootFrom) {
|
|
530
|
-
const { head = null, legacy = null, bootCondition = null } = this.bootFrom
|
|
531
|
+
const { head = null, legacy = null, bootCondition = null, wait = false } = this.bootFrom
|
|
531
532
|
|
|
532
533
|
this.bootFrom = null
|
|
533
534
|
|
|
534
535
|
if (legacy) await this._bootFromSystem(legacy)
|
|
535
|
-
else if (head) await this._bootFromHead(head, bootCondition)
|
|
536
|
+
else if (head) await this._bootFromHead(head, bootCondition, wait)
|
|
536
537
|
}
|
|
537
538
|
|
|
538
539
|
this._ackRequired = false
|
|
@@ -1195,9 +1196,9 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
1195
1196
|
|
|
1196
1197
|
// the boot head seeds the view every trust decision here is made against,
|
|
1197
1198
|
// since our own view is still empty
|
|
1198
|
-
async _bootFromHead(head, bootCondition) {
|
|
1199
|
+
async _bootFromHead(head, bootCondition, wait = false) {
|
|
1199
1200
|
// just a head: one attempt, we do not wait around if it cannot be read
|
|
1200
|
-
if (bootCondition === null) {
|
|
1201
|
+
if (bootCondition === null && !wait) {
|
|
1201
1202
|
try {
|
|
1202
1203
|
const ff = await FastForward.fromHead(this, head, null, {
|
|
1203
1204
|
force: true,
|
|
@@ -1211,8 +1212,8 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
1211
1212
|
}
|
|
1212
1213
|
}
|
|
1213
1214
|
|
|
1214
|
-
//
|
|
1215
|
-
//
|
|
1215
|
+
// park until the head can be read and, if a condition is set, something
|
|
1216
|
+
// acceptable turns up
|
|
1216
1217
|
let opened = null
|
|
1217
1218
|
|
|
1218
1219
|
try {
|
|
@@ -1220,10 +1221,28 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
1220
1221
|
this._bootWait = rrp()
|
|
1221
1222
|
|
|
1222
1223
|
try {
|
|
1223
|
-
if (
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1224
|
+
if (bootCondition === null) {
|
|
1225
|
+
const ff = await FastForward.fromHead(this, head, null, {
|
|
1226
|
+
force: true,
|
|
1227
|
+
timeout: FastForward.DEFAULT_TIMEOUT
|
|
1228
|
+
})
|
|
1229
|
+
|
|
1230
|
+
if (ff !== null && (await this._runFastForward(ff))) return true
|
|
1231
|
+
} else {
|
|
1232
|
+
if (opened === null) opened = await this._bootReference(head)
|
|
1233
|
+
|
|
1234
|
+
if (opened !== null) {
|
|
1235
|
+
if (await this._bootAttempt(head, bootCondition, opened.view)) {
|
|
1236
|
+
return true
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// the reference may be stale - resolve it afresh next attempt
|
|
1240
|
+
await opened.close()
|
|
1241
|
+
opened = null
|
|
1242
|
+
} else if (await this._bootLegacyHead(head)) {
|
|
1243
|
+
// boot legacy head through the migration pathway
|
|
1244
|
+
return true
|
|
1245
|
+
}
|
|
1227
1246
|
}
|
|
1228
1247
|
} catch (err) {
|
|
1229
1248
|
safetyCatch(err)
|
|
@@ -1258,6 +1277,20 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
1258
1277
|
return ff !== null && (await this._runFastForward(ff))
|
|
1259
1278
|
}
|
|
1260
1279
|
|
|
1280
|
+
async _bootLegacyHead(head) {
|
|
1281
|
+
const oplog = await FastForward.flushHead(this, head, {
|
|
1282
|
+
timeout: FastForward.DEFAULT_TIMEOUT
|
|
1283
|
+
})
|
|
1284
|
+
if (oplog === null || oplog.op.version > LEGACY_OPLOG_VERSION) return false
|
|
1285
|
+
|
|
1286
|
+
const ff = await FastForward.fromHead(this, head, null, {
|
|
1287
|
+
force: true,
|
|
1288
|
+
timeout: FastForward.DEFAULT_TIMEOUT
|
|
1289
|
+
})
|
|
1290
|
+
|
|
1291
|
+
return ff !== null && (await this._runFastForward(ff))
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1261
1294
|
async _bootReference(head) {
|
|
1262
1295
|
const oplog = await FastForward.flushHead(this, head, {
|
|
1263
1296
|
timeout: FastForward.DEFAULT_TIMEOUT
|
package/lib/writers.js
CHANGED
|
@@ -59,21 +59,26 @@ class ActiveWriters {
|
|
|
59
59
|
let w = this.active.get(id)
|
|
60
60
|
|
|
61
61
|
if (w === this.localWriter) return
|
|
62
|
+
|
|
63
|
+
let added = false
|
|
62
64
|
if (!w) {
|
|
63
65
|
// anchors are local-only and never replicated - nothing to fetch
|
|
64
66
|
const info = await this.auto.system.get(key, { unflushed: true })
|
|
65
67
|
if (info && info.isAnchor) return
|
|
66
68
|
w = await this.add(key)
|
|
67
69
|
if (!w) return
|
|
70
|
+
added = true
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
const advanced = length > w.hintedLength
|
|
74
|
+
|
|
70
75
|
// remember the announced length so gc doesn't drop a writer we haven't caught up on
|
|
71
76
|
w.hint(length)
|
|
72
77
|
|
|
73
78
|
// prefetch the oplog head for the fast-forward that runs right after us
|
|
74
79
|
if (w && length > 0) w.core.get(length - 1).catch(noop)
|
|
75
80
|
|
|
76
|
-
this.bump()
|
|
81
|
+
if (added || advanced) this.bump()
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
getLatestLocalOplog() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autobee",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.26",
|
|
4
4
|
"description": "Bee based autobase",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Holepunch Inc.",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"lunte": "^1.6.0",
|
|
44
44
|
"prettier": "^3.8.1",
|
|
45
45
|
"prettier-config-holepunch": "^2.0.0",
|
|
46
|
-
"protomux-wakeup": "^2.9.0"
|
|
46
|
+
"protomux-wakeup": "^2.9.0",
|
|
47
|
+
"replication-simulator": "^3.0.0"
|
|
47
48
|
}
|
|
48
49
|
}
|