-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Pre-download bundle uploads before lock to reduce contention #678
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
base: main
Are you sure you want to change the base?
Changes from all commits
9a7b802
7dfb50f
6a93d56
359a1aa
0bb0049
6a3cb0a
19dc6c0
9c402cd
453ef5e
dc341fa
8ba64f0
2cb4b58
fbd2c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,4 +131,7 @@ dmypy.json | |
| *.pem | ||
| junit.xml | ||
|
|
||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| # Cursor (user/IDE rules - do not commit) | ||
| .cursor/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,11 +224,22 @@ def _attempt_init_from_previous_report( | |
|
|
||
| @sentry_sdk.trace | ||
| def process_upload( | ||
| self, commit: Commit, upload: Upload, compare_sha: str | None = None | ||
| self, | ||
| commit: Commit, | ||
| upload: Upload, | ||
| compare_sha: str | None = None, | ||
| pre_downloaded_path: str | None = None, | ||
|
Contributor
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. I think we can force this to be always available and set to just |
||
| ) -> ProcessingResult: | ||
| """ | ||
| Download and parse the data associated with the given upload and | ||
| merge the results into a bundle report. | ||
|
|
||
| Args: | ||
| commit: The commit being processed | ||
| upload: The upload record | ||
| compare_sha: Optional SHA for comparison | ||
| pre_downloaded_path: Optional path to pre-downloaded upload file. | ||
| If provided, skips the GCS download (optimization for reducing lock time). | ||
| """ | ||
| commit_report: CommitReport = upload.report | ||
| bundle_loader = BundleAnalysisReportLoader(commit_report.commit.repository) | ||
|
|
@@ -241,20 +252,32 @@ def process_upload( | |
| commit, bundle_loader | ||
| ) | ||
|
|
||
| # download raw upload data to local tempfile | ||
| _, local_path = tempfile.mkstemp() | ||
| if pre_downloaded_path and os.path.exists(pre_downloaded_path): | ||
|
Contributor
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. so yeah, forcing the path to exist as a string will simplify this logic. We probably still want the |
||
| local_path = pre_downloaded_path | ||
|
Contributor
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. and subsequently, don't need to create this temp var |
||
| should_cleanup_local = False | ||
| log.info( | ||
| "Using pre-downloaded upload file", | ||
| extra={ | ||
| "repoid": commit.repoid, | ||
| "commit": commit.commitid, | ||
| "local_path": local_path, | ||
| }, | ||
| ) | ||
| else: | ||
| _, local_path = tempfile.mkstemp() | ||
| should_cleanup_local = True | ||
|
|
||
| try: | ||
| session_id, prev_bar, bundle_name = None, None, None | ||
| if upload.storage_path != "": | ||
| with open(local_path, "wb") as f: | ||
| storage_service.read_file( | ||
| get_bucket_name(), upload.storage_path, file_obj=f | ||
| ) | ||
| if should_cleanup_local: | ||
|
Contributor
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. you can actually probably just do the |
||
| with open(local_path, "wb") as f: | ||
| storage_service.read_file( | ||
| get_bucket_name(), upload.storage_path, file_obj=f | ||
| ) | ||
|
|
||
| # load the downloaded data into the bundle report | ||
| session_id, bundle_name = bundle_report.ingest(local_path, compare_sha) | ||
|
|
||
| # Retrieve previous commit's BAR and associate past Assets | ||
| prev_bar = self._previous_bundle_analysis_report( | ||
| bundle_loader, commit, head_bundle_report=bundle_report | ||
| ) | ||
|
|
@@ -332,7 +355,8 @@ def process_upload( | |
| ), | ||
| ) | ||
| finally: | ||
| os.remove(local_path) | ||
| if should_cleanup_local and os.path.exists(local_path): | ||
|
Contributor
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. and yeah, don't need the |
||
| os.remove(local_path) | ||
|
|
||
| return ProcessingResult( | ||
| upload=upload, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please pull in latest