-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Increase file size limit from 25GB to 50.1GB #396
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3a34e36
feat: Increase file size limit from 25GB to 50.1GB
sbassam 3f2c68e
feat: Increase file size limit to 50.1GB - tests passing
sbassam c1b27a5
fix: Optimize memory and timeout handling for 50GB+ files
sbassam 774c20e
fixed test
sbassam f953eed
removed unnecessary comments
sbassam f6d6ca0
refactor: Address code review comments
sbassam d104aa1
address pr feedback
sbassam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,10 @@ | |
| import stat | ||
| import tempfile | ||
| import uuid | ||
| from concurrent.futures import ThreadPoolExecutor, as_completed | ||
| from concurrent.futures import Future, ThreadPoolExecutor, as_completed | ||
| from functools import partial | ||
| from pathlib import Path | ||
| from typing import Any, Dict, List, Tuple | ||
| from typing import Any, BinaryIO, Dict, List, Tuple | ||
|
|
||
| import requests | ||
| from filelock import FileLock | ||
|
|
@@ -212,6 +212,7 @@ def download( | |
| ), | ||
| remaining_retries=MAX_RETRIES, | ||
| stream=True, | ||
| request_timeout=3600, | ||
| ) | ||
|
|
||
| try: | ||
|
|
@@ -512,6 +513,18 @@ def _initiate_upload( | |
|
|
||
| return response.data | ||
|
|
||
| def _submit_part( | ||
| self, | ||
| executor: ThreadPoolExecutor, | ||
| f: BinaryIO, | ||
| part_info: Dict[str, Any], | ||
| part_size: int, | ||
| ) -> Future[str]: | ||
| """Submit a single part for upload and return the future""" | ||
| f.seek((part_info["PartNumber"] - 1) * part_size) | ||
| part_data = f.read(part_size) | ||
| return executor.submit(self._upload_single_part, part_info, part_data) | ||
|
|
||
| def _upload_parts_concurrent( | ||
| self, file: Path, upload_info: Dict[str, Any], part_size: int | ||
| ) -> List[Dict[str, Any]]: | ||
|
|
@@ -522,29 +535,39 @@ def _upload_parts_concurrent( | |
|
|
||
| with ThreadPoolExecutor(max_workers=self.max_concurrent_parts) as executor: | ||
| with tqdm(total=len(parts), desc="Uploading parts", unit="part") as pbar: | ||
| future_to_part = {} | ||
|
|
||
| with open(file, "rb") as f: | ||
| for part_info in parts: | ||
| f.seek((part_info["PartNumber"] - 1) * part_size) | ||
| part_data = f.read(part_size) | ||
| future_to_part = {} | ||
| part_index = 0 | ||
|
|
||
| future = executor.submit( | ||
| self._upload_single_part, part_info, part_data | ||
| ) | ||
| # Submit initial batch limited by max_concurrent_parts | ||
| for _ in range(min(self.max_concurrent_parts, len(parts))): | ||
| part_info = parts[part_index] | ||
| future = self._submit_part(executor, f, part_info, part_size) | ||
| future_to_part[future] = part_info["PartNumber"] | ||
|
|
||
| # Collect results | ||
| for future in as_completed(future_to_part): | ||
| part_number = future_to_part[future] | ||
| try: | ||
| etag = future.result() | ||
| completed_parts.append( | ||
| {"part_number": part_number, "etag": etag} | ||
| ) | ||
| pbar.update(1) | ||
| except Exception as e: | ||
| raise Exception(f"Failed to upload part {part_number}: {e}") | ||
| part_index += 1 | ||
|
|
||
| # Process completions and submit new parts (sliding window) | ||
| while future_to_part: | ||
| done_future = next(as_completed(future_to_part)) | ||
| part_number = future_to_part.pop(done_future) | ||
|
|
||
| try: | ||
| etag = done_future.result() | ||
| completed_parts.append( | ||
| {"part_number": part_number, "etag": etag} | ||
| ) | ||
| pbar.update(1) | ||
| except Exception as e: | ||
| raise Exception(f"Failed to upload part {part_number}: {e}") | ||
|
|
||
| # Submit next part if available | ||
| if part_index < len(parts): | ||
| part_info = parts[part_index] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be great to rewrite it to deduplicate this code piece with the one above. I think you can either make a for loop to submit tasks and wait on result if we have enough already, or use executor.map with buffersize to limit concurrent tasks. |
||
| future = self._submit_part( | ||
| executor, f, part_info, part_size | ||
| ) | ||
| future_to_part[future] = part_info["PartNumber"] | ||
| part_index += 1 | ||
|
|
||
| completed_parts.sort(key=lambda x: x["part_number"]) | ||
| return completed_parts | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.