-
Notifications
You must be signed in to change notification settings - Fork 51
fix: improve peer reconciliation #1901
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
packages/cojson/src/sync.ts
Outdated
const prevPeer = this.peers[peer.id]; | ||
const peerState = new PeerState(peer, prevPeer?.knownStates); | ||
this.peers[peer.id] = peerState; | ||
|
||
if (prevPeer && !prevPeer.closed) { | ||
prevPeer.gracefulShutdown(); | ||
await prevPeer.processMessages?.catch((e) => {}); |
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.
We need to wait for the previous peer to process all the incoming messages before starting to process the new peer messages.
This is probably why, on frequent reconnections, the sync server starts to have troubles.
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.
Quick fix, doesn't handle more than one peers in line to be added.
Will improve in the final version of the PR
value: coValue.knownState(), | ||
}); | ||
} | ||
} | ||
|
||
addPeer(peer: Peer) { | ||
async startPeerReconciliation(peer: PeerState) { |
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.
Before we were sending the content without waiting for the known
state from the server.
Done some changes so we just send a load
request for each available coValue to the server.
Added some logic to make the server request the content if they notice that they miss some content from the client.
The downside is that we now wait for the server response before sending the content, but we should send less messages around (in theory)
{ | ||
from: "client", | ||
msg: map.core.newContentSince(undefined)?.[0], | ||
}, |
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.
We send the same content twice 🤔
action: "content", | ||
...map.core.newContentSince(knownStateBefore)?.[0], | ||
}, | ||
}, |
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.
We send the same content twice 🤔
|
||
await account.waitForAllCoValuesSync(); | ||
|
||
return account; |
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.
Needed this change because the content reconciliation now requires more than one roundtrip.
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.
thanks for catching it
Jazz pre-releasePackages:{
"cojson": "https://pkg.pr.new/garden-co/jazz/cojson@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"cojson-storage": "https://pkg.pr.new/garden-co/jazz/cojson-storage@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"cojson-storage-sqlite": "https://pkg.pr.new/garden-co/jazz/cojson-storage-sqlite@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"create-jazz-app": "https://pkg.pr.new/garden-co/jazz/create-jazz-app@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"cojson-transport-ws": "https://pkg.pr.new/garden-co/jazz/cojson-transport-ws@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"cursor-docs": "https://pkg.pr.new/garden-co/jazz/cursor-docs@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"cojson-storage-indexeddb": "https://pkg.pr.new/garden-co/jazz/cojson-storage-indexeddb@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"hash-slash": "https://pkg.pr.new/garden-co/jazz/hash-slash@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-auth-clerk": "https://pkg.pr.new/garden-co/jazz/jazz-auth-clerk@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-browser": "https://pkg.pr.new/garden-co/jazz/jazz-browser@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-browser-media-images": "https://pkg.pr.new/garden-co/jazz/jazz-browser-media-images@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-expo": "https://pkg.pr.new/garden-co/jazz/jazz-expo@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-inspector": "https://pkg.pr.new/garden-co/jazz/jazz-inspector@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-nodejs": "https://pkg.pr.new/garden-co/jazz/jazz-nodejs@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-react": "https://pkg.pr.new/garden-co/jazz/jazz-react@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-react-auth-clerk": "https://pkg.pr.new/garden-co/jazz/jazz-react-auth-clerk@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-react-core": "https://pkg.pr.new/garden-co/jazz/jazz-react-core@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-react-native": "https://pkg.pr.new/garden-co/jazz/jazz-react-native@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-react-native-core": "https://pkg.pr.new/garden-co/jazz/jazz-react-native-core@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-react-native-media-images": "https://pkg.pr.new/garden-co/jazz/jazz-react-native-media-images@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-run": "https://pkg.pr.new/garden-co/jazz/jazz-run@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-svelte": "https://pkg.pr.new/garden-co/jazz/jazz-svelte@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-tools": "https://pkg.pr.new/garden-co/jazz/jazz-tools@fa1f15d3afac9a6573699d252cbd8e416094cfbc",
"jazz-vue": "https://pkg.pr.new/garden-co/jazz/jazz-vue@fa1f15d3afac9a6573699d252cbd8e416094cfbc"
} |
fixes #1871