Skip to content

Resumable downloads.#84

Merged
Narsil merged 5 commits into
mainfrom
resumable_downloads
Dec 30, 2024
Merged

Resumable downloads.#84
Narsil merged 5 commits into
mainfrom
resumable_downloads

Conversation

@Narsil

@Narsil Narsil commented Dec 27, 2024

Copy link
Copy Markdown
Contributor

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).

@McPatate McPatate left a comment

Copy link
Copy Markdown
Member

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

Comment thread src/api/sync.rs
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
Copy Markdown
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
Copy Markdown
Contributor 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.

Comment thread src/api/sync.rs
let mut file = std::fs::File::create(&filepath)?;

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
Copy Markdown
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) {

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

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment thread src/api/tokio.rs
0
}
}
Err(_err) => {

Copy link
Copy Markdown
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(_) => {

@McPatate McPatate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, understood!

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