Skip to content
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

Resumable downloads. #84

Merged
merged 5 commits into from
Dec 30, 2024
Merged

Resumable downloads. #84

merged 5 commits into from
Dec 30, 2024

Conversation

Narsil
Copy link
Collaborator

@Narsil Narsil commented Dec 27, 2024

Notes on the strategy here.

Sync:

  • Relatively straigforward, we're not multiplexing, we write in order, therefore we can simply pick up whereever we left off.

Tokio:
Since we're multiplexing, writes are not happening in order. We could:

  • Store every written interval and skip those, but that involves creating somewhat complex datastructures.
  • Instead, since writes are mostly ordered, we simply commit whatever was fully written as a single u64 at the very end of the partial file. When resuming, we read that single int, and resume from there. Anything fishy and we drop the resumability.

This feels simpler that the more complex version, seems to work quite well in practice (only tested on stable networks right now).
The probability for storing invalid files seems low (since commit happens at a single location both in code and in file).

Copy link
Member

@McPatate McPatate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st part of my review, trying to figure out how things work in tokio

let new_size = (size as f32 * truncate) as u64;
file.set_len(new_size).unwrap();
let mut blob_part = blob.clone();
blob_part.set_extension(".part");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use EXTENTION here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done on purpose to have it hardcoded in the test. I don't want my test to change when library code changes.


let mut res = self.download_from(url, 0u64, size, &mut file, filename, &mut progress);
let mut file = match std::fs::OpenOptions::new().append(true).open(&filepath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut file = match std::fs::OpenOptions::new().append(true).open(&filepath) {
let mut part_file = match std::fs::OpenOptions::new().append(true).open(&filepath) {

src/api/tokio.rs Outdated
.await
{
Ok(mut f) => {
let len = f.metadata().await.unwrap().len();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap expected here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

0
}
}
Err(_err) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(_err) => {
Err(_) => {

Copy link
Member

@McPatate McPatate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, understood!

@Narsil Narsil merged commit 41d49d6 into main Dec 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants