Repository navigation
Tell a peer the new length even when it can't be upgraded yet #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -548,6 +548,9 @@ class Peer { | |
| this.syncsProcessing = 0 | ||
| this.lastUpgradableLength = 0 | ||
| this.lastUpgradableFork = 0 | ||
| this.lengthSent = 0 | ||
| this.forkSent = 0 | ||
| this.remoteLengthSent = 0 | ||
|
|
||
| this._remoteContiguousLength = 0 | ||
|
|
||
|
|
@@ -693,11 +696,14 @@ class Peer { | |
| } | ||
|
|
||
| this.needsSync = false | ||
| this.lengthSent = this.core.state.length | ||
| this.forkSent = this.core.state.fork | ||
| this.remoteLengthSent = this._remoteLengthToAck() | ||
|
|
||
| this.wireSync.send({ | ||
| fork: this.core.state.fork, | ||
| length: this.core.state.length, | ||
| remoteLength: this.core.state.fork === this.remoteFork ? this.remoteLength : 0, | ||
| remoteLength: this.remoteLengthSent, | ||
| canUpgrade: this.canUpgrade, | ||
| uploading: true, | ||
| downloading: this.replicator.isDownloading(), | ||
|
|
@@ -839,7 +845,8 @@ class Peer { | |
|
|
||
| if ( | ||
| this.needsSync === true || | ||
| (this.core.state.fork === this.remoteFork && this.core.state.length > this.remoteLength) | ||
| (this.core.state.fork === this.remoteFork && this.core.state.length > this.remoteLength) || | ||
| this._lengthSent() === false | ||
| ) { | ||
| this.signalUpgrade() | ||
| } | ||
|
|
@@ -873,19 +880,31 @@ class Peer { | |
| if (remoteLength !== this.remoteLength || remoteFork !== this.remoteFork) { | ||
| return | ||
| } | ||
| if (canUpgrade === this.canUpgrade) { | ||
| if (canUpgrade !== this.canUpgrade) { | ||
| this.canUpgrade = canUpgrade | ||
| if (canUpgrade) { | ||
| this.lastUpgradableLength = this.remoteLength | ||
| this.lastUpgradableFork = this.remoteFork | ||
| } | ||
| } else if (this._syncSent()) { | ||
| return | ||
| } | ||
|
|
||
| this.canUpgrade = canUpgrade | ||
| if (canUpgrade) { | ||
| this.lastUpgradableLength = this.remoteLength | ||
| this.lastUpgradableFork = this.remoteFork | ||
| } | ||
|
|
||
| this.sendSync() | ||
| } | ||
|
|
||
| _syncSent() { | ||
| return this._lengthSent() && this.remoteLengthSent === this._remoteLengthToAck() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No test covers remoteLengthSent. It also seem to fix a second hang: on main, when two peers can’t upgrade each other, update({ wait: true }) on the shorter one waits forever for the longer one to ack its length. Could you add a test for that?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in f7c54d8: "a peer that cannot upgrade a shorter one still acks its length". It hangs on main and passes here. |
||
| } | ||
|
|
||
| _lengthSent() { | ||
| return this.lengthSent === this.core.state.length && this.forkSent === this.core.state.fork | ||
| } | ||
|
|
||
| _remoteLengthToAck() { | ||
| return this.core.state.fork === this.remoteFork ? this.remoteLength : 0 | ||
| } | ||
|
|
||
| // Safe to call in the background - never fails | ||
| async _canUpgrade(remoteLength, remoteFork) { | ||
| if (remoteFork !== this.core.state.fork) return false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to oversend
syncs in response. So far I can't figure out a way to reduce it only to the race conditions (in the second 10x try test). So it might be a matter of whether the extrasyncs are worth catching that edgecase.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysed this too. When measuring it locally, this only fires in the race, and each extra sync is correctly needed. It is about +20% syncs at zero latency (tests), 1% at 1 ms, and
no difference at at 20-40 ms. And so for the low latency scenarios we can in the future add a 20 ms debounce/delay on this signal path and I think we would get back to mains behavior.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now looked at slow tree reads. With a simulated 5–15 ms read in _canUpgrade, the race also shows up at 20–40 ms. In this scenario main drops 2–6% of length announcements and this PR adds 3–7% syncs but does the right thing, so my analysis above was partial here