Repository navigation
client: download in batches, resume after an interruption - #57
Merged
Merged
Conversation
A first sync asked for every chunk of every file in one request and wrote the files only after the last chunk had arrived. A library that did not fit the 60 s request timeout never finished: each attempt was cut off, kept nothing and started again from the beginning, and the app showed "Unexpected sync error" over an empty list (cooklang/cookcli#849). - The listing is applied lowest id first, in batches of at most 2,000 chunks or about 16 MB. Each batch is fetched, written to disk and recorded before the next one starts, so files appear as they arrive and a retry asks the server only for what is still missing. - The multipart parser searched its whole buffer again, and copied it, on every network read. It now looks at each byte once: a 60 MB test library downloads from a local server in about 2 s instead of 26 s. - A chunk download has a time limit of its own (300 s) instead of the general 60 s, and a chunk used several times is requested once. - A batch in flight stops when sync is cancelled, and a stopped download no longer reports idle. - Downloads and uploads take turns, and the first turn is a download. A commit records an id above everything on the server, and the next download resumes after the highest id recorded locally: a commit landing between two batches would have moved that point past files not fetched yet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the "Unexpected sync error" over an empty recipe list reported in cooklang/cookcli#849. Related: #4.
What went wrong
A first sync asked for every chunk of every file in one request, under the general 60 s request timeout, and wrote the files only after the last chunk had arrived. A library that did not fit in 60 s never finished: each attempt was cut off, kept nothing, and started again from the beginning. reqwest reports a body cut by the timeout as "error decoding response body", which the apps show as "Unexpected sync error".
Two things made 60 s too short:
What changes
MultipartParserlooks at each byte once. The same 60 MB library now downloads in about 2 s.No change to the server, the wire format, the local database or the FFI surface.
How it was checked
cargo test --workspace: 180 pass. New tests cover batch splitting, ordering, keeping finished batches when a later one fails, duplicate chunks, the parser at read sizes from one byte up, stopping mid-download, and download-before-upload.download_batch_outlives_the_general_request_timeoutis#[ignore]d because it waits 65 s; it passes, and fails without the timeout change.cargo build -p cooklang-sync-client --features fficompiles.Not checked: nothing has run on a phone, and I have not watched files appear in the apps.
Left for later