Skip to content

Fix/br 1151 error opening files read callback#278

Open
AlexisMora wants to merge 10 commits intomainfrom
fix/br-1151-error-opening-files_read_callback
Open

Fix/br 1151 error opening files read callback#278
AlexisMora wants to merge 10 commits intomainfrom
fix/br-1151-error-opening-files_read_callback

Conversation

@AlexisMora
Copy link

What is Changed / Added

Instead of downloading the entire file into memory before serving bytes, the new implementation writes the download stream directly to disk and serves requested byte ranges as soon as they land. A waiter queue tracks which byte ranges have been written, allowing FUSE read callbacks to resolve as soon as their requested bytes are available. This way there is no need to wait for the full download.

A global registry tracks in-flight downloads per file with contentsId. If multiple read requests arrive for the same file, they all share the same download instead of starting new ones. Once the download completes, the file is registered in the database so future reads are served directly from disk.

When the virtual drive cache is cleared, all in-flight downloads are cancelled and partial files are cleaned up.

The shouldDownload check was blocking legitimate file opens from applications like VLC. Flag 34816 (O_RDONLY | O_LARGEFILE) was not recognized as a valid user open. The logic now only blocks the known system flag (294912)

If the user closes a file mid-download, the download continues in the background until it completes (to me this makes sense so that if accessed again, the load is faster.)


Why

The previous implementation buffered the entire file into an in-memory Map<string, Buffer> before any bytes could be served to the calling application. For large files (videos, PDFs), this caused high memory usage and slow file opens.

The new approach streams bytes to disk progressively and serves them as soon as they arrive, keeping memory usage constant regardless of file size.

@AlexisMora AlexisMora self-assigned this Mar 18, 2026
@AlexisMora AlexisMora requested a review from egalvis27 March 18, 2026 17:23
…download, instant resolve of promises if requested bytes are already available
@sonarqubecloud
Copy link

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