refactor: 🔒 Reduce file storage locks critical zone #629
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.
Problem
File storage locks were being held for longer than necessary:
file_download_manager.rs: Write lock acquired before
try_download_chunk_batchand held during network I/O, retries, and 500ms delays between attempts.msp_upload_file.rs: Write lock acquired early in
handle_new_storage_request_eventand held across file existence checks, even when only a read lock was needed.Solution
file_download_manager.rs:
process_proven_chunkmsp_upload_file.rs:
file_in_file_storagecheck to use a scoped read lock instead of holding the write lockis_file_completecheck also uses a scoped read lockTBD: It can be argued that taking and releasing the write lock for every chunk would be a lot of overhead:
Anyway, open to discussion :)