Comparing version 6.0.18 to 6.0.19
101
index.js
@@ -30,3 +30,3 @@ const b4a = require('b4a') | ||
const FF_THRESHOLD = 16 | ||
const DEFAULT_FF_TIMEOUT = 60_000 | ||
const DEFAULT_FF_TIMEOUT = 10_000 | ||
@@ -358,3 +358,3 @@ const REMOTE_ADD_BATCH = 64 | ||
this.fastForwardTo = null // will get reset once ready | ||
this.initialFastForward(key, timeout || DEFAULT_FF_TIMEOUT) | ||
this.initialFastForward(key, timeout || DEFAULT_FF_TIMEOUT * 2) | ||
} | ||
@@ -387,3 +387,3 @@ | ||
if (key === null || !base.reindexing || base._isFastForwarding()) return | ||
base.initialFastForward(key, DEFAULT_FF_TIMEOUT) | ||
base.initialFastForward(key, DEFAULT_FF_TIMEOUT * 2) | ||
} | ||
@@ -820,3 +820,3 @@ | ||
w.resume() | ||
this._resumeWriter(w) | ||
return w | ||
@@ -876,2 +876,6 @@ } finally { | ||
_resumeWriter (w) { | ||
if (!this._isFastForwarding()) w.resume() | ||
} | ||
async _bootstrapLinearizer () { | ||
@@ -885,3 +889,3 @@ const bootstrap = this._makeWriter(this.bootstrap, 0, true) | ||
await bootstrap.ready() | ||
bootstrap.resume() | ||
this._resumeWriter(bootstrap) | ||
@@ -1240,2 +1244,8 @@ this._updateLinearizer([bootstrap], []) | ||
doneFastForwarding () { | ||
if (--this.fastForwarding === 0 && !this._isFastForwarding()) { | ||
for (const w of this.activeWriters) w.resume() | ||
} | ||
} | ||
async initialFastForward (key, timeout) { | ||
@@ -1268,3 +1278,3 @@ this.fastForwarding++ | ||
await core.close() | ||
this.fastForwarding-- | ||
this.doneFastForwarding() | ||
this.queueFastForward() | ||
@@ -1277,10 +1287,10 @@ return | ||
this.fastForwarding-- | ||
// initial fast-forward failed | ||
if (target === null) return | ||
if (target === null) { | ||
this.doneFastForwarding() | ||
return | ||
} | ||
for (const w of this.activeWriters) w.pause() | ||
this.fastForwardTo = target | ||
this.doneFastForwarding() | ||
@@ -1299,16 +1309,21 @@ this._bumpAckTimer() | ||
if (this.fastForwardTo !== null && core.session.length <= this.fastForwardTo.length + FF_THRESHOLD) return | ||
if (!core.session.length) return | ||
this.fastForwarding++ | ||
const target = await this._preFastForward(core.session, core.session.length, null) | ||
this.fastForwarding-- | ||
const target = await this._preFastForward(core.session, core.session.length, DEFAULT_FF_TIMEOUT) | ||
// fast-forward failed | ||
if (target === null) return | ||
if (target === null) { | ||
this.doneFastForwarding() | ||
return | ||
} | ||
// if it migrated underneath us, ignore for now | ||
if (core !== this.system.core.getBackingCore()) return | ||
if (core !== this.system.core.getBackingCore()) { | ||
this.doneFastForwarding() | ||
return | ||
} | ||
for (const w of this.activeWriters) w.pause() | ||
this.fastForwardTo = target | ||
this.doneFastForwarding() | ||
@@ -1325,2 +1340,5 @@ this._bumpAckTimer() | ||
// pause writers | ||
for (const w of this.activeWriters) w.pause() | ||
try { | ||
@@ -1393,3 +1411,3 @@ // sys runs open with wait false, so get head block first for low complexity | ||
const core = this.store.get(info.key) | ||
await core.get(length - 1) | ||
await core.get(length - 1, { timeout }) | ||
@@ -1414,6 +1432,8 @@ closing.push(core.close()) | ||
_clearFastForward () { | ||
for (const w of this.activeWriters) w.resume() | ||
_clearFastForward (queue) { | ||
if (this.fastForwarding === 0) { | ||
for (const w of this.activeWriters) w.resume() | ||
} | ||
this.fastForwardTo = null | ||
this.queueFastForward() // queue in case we lost an ff while applying this one | ||
if (queue) this.queueFastForward() // queue in case we lost an ff while applying this one | ||
} | ||
@@ -1437,3 +1457,3 @@ | ||
if (from >= length || core.length < length) { | ||
this._clearFastForward() | ||
this._clearFastForward(true) | ||
return | ||
@@ -1490,3 +1510,3 @@ } | ||
await closeAll(opened) | ||
this._clearFastForward() // something wrong somewhere, likely a bug, just safety | ||
this._clearFastForward(false) // something wrong somewhere, likely a bug, just safety | ||
return | ||
@@ -1502,3 +1522,3 @@ } | ||
await closeAll(opened) | ||
this._clearFastForward() | ||
this._clearFastForward(true) | ||
return | ||
@@ -1530,3 +1550,3 @@ } | ||
if (b4a.equals(this.fastForwardTo.key, key) && this.fastForwardTo.length === length) { | ||
this.fastForwardTo = null | ||
this._clearFastForward(false) | ||
} | ||
@@ -1589,2 +1609,8 @@ | ||
if (!this.activeWriters.has(key)) { | ||
this.activeWriters.add(writer) | ||
this._checkWriters.push(writer) | ||
this._resumeWriter(writer) | ||
} | ||
// If we are getting added as indexer, already start adding checkpoints while we get confirmed... | ||
@@ -1923,12 +1949,25 @@ if (writer === this.localWriter && isIndexer) this._addCheckpoints = true | ||
const p = [] | ||
for (const { key } of info.indexers) { | ||
p.push(await this._getWriterByKey(key, -1, 0, false, null)) | ||
let same = info.indexers.length === this.linearizer.indexers.length | ||
if (same) { | ||
for (let i = 0; i < info.indexers.length; i++) { | ||
if (!b4a.equals(info.indexers[i].key, this.linearizer.indexers[i].core.key)) { | ||
same = false | ||
break | ||
} | ||
} | ||
} | ||
const indexers = await p | ||
let key = this.system.core.key | ||
const sys = this._viewStore.getSystemCore() | ||
const key = await sys.deriveKey(indexers, pending) | ||
if (!same) { | ||
const p = [] | ||
for (const { key } of info.indexers) { | ||
p.push(await this._getWriterByKey(key, -1, 0, false, null)) | ||
} | ||
const indexers = await p | ||
const sys = this._viewStore.getSystemCore() | ||
key = await sys.deriveKey(indexers, pending) | ||
} | ||
if (this._localDigest.key && b4a.equals(key, this._localDigest.key)) return | ||
@@ -1935,0 +1974,0 @@ |
@@ -50,3 +50,2 @@ const Linearizer = require('./linearizer') | ||
if (this.range) return | ||
this.pause() | ||
this.range = this.core.download({ start: this.nodes.length, end: -1, linear: true }) | ||
@@ -53,0 +52,0 @@ } |
{ | ||
"name": "autobase", | ||
"version": "6.0.18", | ||
"version": "6.0.19", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
172078
4617