hypercore 11.27.12 → 11.27.14
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/lib/replicator.js +13 -2
- package/lib/session-state.js +18 -0
- package/package.json +1 -1
package/lib/replicator.js
CHANGED
|
@@ -526,7 +526,8 @@ class Peer {
|
|
|
526
526
|
hotswaps: 0,
|
|
527
527
|
invalidData: 0,
|
|
528
528
|
invalidRequests: 0,
|
|
529
|
-
backoffs: 0
|
|
529
|
+
backoffs: 0,
|
|
530
|
+
notAvailableBackoffs: 0
|
|
530
531
|
}
|
|
531
532
|
|
|
532
533
|
this.receiverQueue = new ReceiverQueue()
|
|
@@ -1991,7 +1992,8 @@ module.exports = class Replicator {
|
|
|
1991
1992
|
hotswaps: 0,
|
|
1992
1993
|
invalidData: 0,
|
|
1993
1994
|
invalidRequests: 0,
|
|
1994
|
-
backoffs: 0
|
|
1995
|
+
backoffs: 0,
|
|
1996
|
+
notAvailableBackoffs: 0
|
|
1995
1997
|
}
|
|
1996
1998
|
|
|
1997
1999
|
this._attached = new Set()
|
|
@@ -2684,6 +2686,15 @@ module.exports = class Replicator {
|
|
|
2684
2686
|
}
|
|
2685
2687
|
|
|
2686
2688
|
_onnodata(peer, req, reason) {
|
|
2689
|
+
if (reason === NOT_AVAILABLE) {
|
|
2690
|
+
peer.stats.notAvailableBackoffs++
|
|
2691
|
+
this.stats.notAvailableBackoffs++
|
|
2692
|
+
|
|
2693
|
+
if (peer.stats.notAvailableBackoffs >= MAX_BACKOFFS) {
|
|
2694
|
+
peer.paused = true
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2687
2698
|
if (reason === INVALID_REQUEST) {
|
|
2688
2699
|
peer.stats.backoffs++
|
|
2689
2700
|
this.stats.backoffs++
|
package/lib/session-state.js
CHANGED
|
@@ -3,6 +3,7 @@ const b4a = require('b4a')
|
|
|
3
3
|
const assert = require('nanoassert')
|
|
4
4
|
const flat = require('flat-tree')
|
|
5
5
|
const quickbit = require('quickbit-universal')
|
|
6
|
+
const HypercoreStorage = require('hypercore-storage')
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
INVALID_OPERATION,
|
|
@@ -249,6 +250,13 @@ class SessionState {
|
|
|
249
250
|
return true
|
|
250
251
|
}
|
|
251
252
|
|
|
253
|
+
_precommit(state) {
|
|
254
|
+
assert(
|
|
255
|
+
state.parent === this && state.storage.core.dataPointer === this.storage.core.dataPointer,
|
|
256
|
+
'Atomic state must flush to parent'
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
|
|
252
260
|
async _commit() {
|
|
253
261
|
await this.mutex.lock()
|
|
254
262
|
|
|
@@ -957,12 +965,21 @@ class SessionState {
|
|
|
957
965
|
return { tree, flushed }
|
|
958
966
|
}
|
|
959
967
|
|
|
968
|
+
static isParent(state, parent) {
|
|
969
|
+
// atomic batches have parent set
|
|
970
|
+
if (state.parent && state.parent === parent) return true
|
|
971
|
+
|
|
972
|
+
return HypercoreStorage.isParentStorage(state.storage, parent.storage)
|
|
973
|
+
}
|
|
974
|
+
|
|
960
975
|
async commit(state, { signature, keyPair, length = state.length, treeLength = -1 } = {}) {
|
|
961
976
|
assert(
|
|
962
977
|
this.isDefault() || (this.parent && this.parent.isDefault()),
|
|
963
978
|
'Can only commit into default state'
|
|
964
979
|
)
|
|
965
980
|
|
|
981
|
+
assert(SessionState.isParent(state, this), 'Cannot commit across cores')
|
|
982
|
+
|
|
966
983
|
if (this.core._repairMode) {
|
|
967
984
|
throw ASSERTION('Cannot commit while repair mode is on')
|
|
968
985
|
}
|
|
@@ -1180,6 +1197,7 @@ class SessionState {
|
|
|
1180
1197
|
|
|
1181
1198
|
if (atom) {
|
|
1182
1199
|
this.atomized = atom
|
|
1200
|
+
atom.preflush(this._precommit.bind(this, state))
|
|
1183
1201
|
atom.onflush(state._commit.bind(state))
|
|
1184
1202
|
}
|
|
1185
1203
|
|