Resume FSA file downloads #173
No reviewers
Labels
No labels
backend
bug
CI
dependencies
design
documentation
duplicate
enhancement
frontend
github_actions
good first issue
help wanted
invalid
javascript
question
refactoring
security
tooling
UX
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
NBIS/sda-download-ui!173
Loading…
Reference in a new issue
No description provided.
Delete branch "149-resume-FSA-file-downloads"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Related issue(s) and PR(s)
This PR closes #149 .
It improves the File System Access (FSA) batch downloads by adding persistent download metadata, partial-file resume support, periodical streamed file commits (saves byte chunks to disk), and user-visible download progress. It enables interrupted or canceled FSA downloads to be resumed by selecting the same destination folder again, while preserving local files and avoiding unsafe metadata updates.
It also adds a non-dismissible in-page progress modal for current page-local FSA downloads, including rough byte-based progress based on selected file sizes. The modal was needed because navigating away from the dataset's page stops the download. A later improvement could be to make the download persistent in the background but this is out of scope for now.
Type of change
List of changes made
FSA metadata persistence
.download-metadatafile in the selected download directory.Saving to a local file instead of e.g. the browser's indexDB has the benefit that if the session is cleared when logging out, the local file is not.
Resume and partial download handling
Content-RangeDurable checkpoint commits
This was needed because FSA's partial files are not durable on disk, i.e. there is no mechanism in FSA that persists a partial file by default. Without this, whenever a download was cancelled or interrupted the file size on disk remained 0.
Download result and progress reporting
resumed,skipped,restartedfiles.Progress modal
Testing
Instructions on how to test
should do the trick.
Start a download of selected files and hit CANCEL or close the tab before it finishes, confirm that:
.download-metadatafile is created in the selected folder.Repeat the same download to the same folder, observe the status in the modal. Make sure that:
Repeat the same download and make sure that nothing happens since all files are already downloaded, i.e. completed files are skipped.
Missing metadata. Delete the
.download-metadatafile and try to repeat the download. Confirm that the download fails with an error message.Definition of Done checklist
I started to test this and most of it works as described but the things that are not fully working for me is:
.download-metadatafile is added to the folder I've selected for the download (the files are downloaded though). EDIT: Okay, I now see it! :)I'm starting a review now...
I've tested this and works as expected! Great job! Also, thank you for adding many explaining comments, a detailed PR description and most of all detailed testing instructions 💯
Most of the UI looks good as well but I think that the error messages need a little more attention, see my comments. I also saw that you need to rebase on develop as there were some layout changes to the files page that are not part of your code yet.
The comment I made on the ModalDialog is optional, feel free to dismiss it if you think it's too little benefit.
I also noticed that two of the smaller files I tested with didn't have exactly the same size as shown in the UI. On my computer, they had 1,176 bytes while the UI said 1.02 kB. I don't know if that is expected? It's a small difference but still a difference.
The error messages here are pushing the button around in the UI in a way that is hard to predict and can result in weird layouts, e.g on small screens or with bigger text in the browser.
I would suggest showing a dismissable modal with the error message instead.
The code comment mentions a "changed c4gh key" while the error message to the user states that "download metadata is missing". Is the error message misleading?
I'm even wondering if we should mention the download metadata for the user at all. They don't necessarily are aware of that hidden file and the term could be confusing. I think it would be enough to say "Existing local file ... has been partially downloaded but cannot be safely resumed. Delete or move the local file before retrying."
@ -0,0 +14,4 @@onCancel: () => void;};export function FileSystemDownloadProgressModal({It kind of bothers me that we are not reusing the existing ModalDialog component here but I suppose the reason is that the modal in this case must not be dismiss-able. Was that your reasoning as well?
I wonder if it would reduce code if we instead add a boolean prop
dismissableto the ModalDialog component so that you can reuse it here without showing the "Close"-button. But I'll leave that up to you.That's a great catch!
Actually, I forgot to use this in the logic below. I now pushed the fix in commit 1473bbc.
Background: The problem here is that the file size reported by the sda-download backend service is not the same with the file size written on disk. The actual download size will be slightly larger due to the recipient-specific Crypt4GH header.
So, the
estimateFilesizevariable is used as a way to get a more precise progress estimate. Imo precise accuracy for the progress estimate is not needed but this is a cheap way to improve things.@ -0,0 +14,4 @@onCancel: () => void;};export function FileSystemDownloadProgressModal({Yes, the reasoning is that the modal needs to be non-dismissible.I agree that it would be better practice to reuse existing components if the boolean mod is small. I opened #191 for this, please feel free to edit.
Yes, that is expected, because the sda-download backend API reports file sizes without including the header size as FileInfo, see here. This is the simplest estimate we can do without doing elaborate work trying to calculate the header size and summing both sizes. Even if we do, this will probably mean doing extra head requests to the backend API for every file with little gain.
We could raise the issue at a sprint review and maybe add clarifying text as a hover over maybe.
Great comment, thanks for pointing out. I have now made these appear as modals as you suggested.
This was a leftover comment. Great catch. I have fixed the error message and comment to be more user friendly and reflect the actual behavior.
Thanks @AnnikaSonnek and @HenrikeW for the nice feedback! Please take a look again since approvals have been dismissed by recent pushes and comments have been addressed.
@ -123,3 +220,1 @@</button>{isDownloading && (<>Since resuming depends on the user picking the same folder again, would it be worth passing an
idtoshowDirectoryPicker, for exampleshowDirectoryPicker({ mode: "readwrite", id: "sda-batch-download" })? Chrome then remembers the last folder used for that id and opens the picker there, which makes the "select the same folder" step from the modal text a bit easier to get right.Sorry for one more comment on a PR I am not reviewing, feel free to ignore it. I might have missed something, but I could not find any new test files in the diff, while the DoD checklist has the unit test item ticked. Is that a leftover from the template?
@ -0,0 +14,4 @@onCancel: () => void;};export function FileSystemDownloadProgressModal({That's awesome! Good idea to turn it into a refactoring issue.
This now looks much better than before, great! I would still vote for a small change to the modal shown when the download is cancelled manually. I made a comment for the modal title.
I also would suggest turning the error message into a proper sentence, like "The download process was cancelled." That way I think the modal will look a bit more complete and there's a better balance between length of the heading and length of the body, like this:
Otherwise this PR looks great now.
Thanks also for the explanation regarding the file sizes. I think it's fine if it differs a little but it probably makes sense to raise the issue during a sprint review or refinement.
This modal is shown when the user manually interrupts the download, either by clicking "Cancel download" or just closing the file explorer window. So I think the term "error" is too strong here, I would suggest using "Information" or something equally neutral.
Small thing: If you start the sentence with "The file .....", the text will start with a capital letter instead of a file name and (I think) will look a bit more tidy and complete.
Good point, changed it to "Notice".
Yes, this reads better. Now changed.
Yes.
@ -123,3 +220,1 @@</button>{isDownloading && (<>/na
I also added a commit to somewhat progressively reduce the times a file is closed by FSA as mentioned in #193 since this creates the bottlenecks in the download progress. It will improve slightly the UX until there is a better mechanism in place for the resuming mechanism.
I've tested this and it seems to work as it should and looks nice. Good work!
This looks great now! Thank you for your patience, good work! 💯