Skip to content
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

gcsio: reduce number of get requests in function calls #30205

Merged
merged 3 commits into from
Feb 7, 2024

Conversation

shunping
Copy link
Contributor

@shunping shunping commented Feb 3, 2024

We replace client.get_bucket() with client.bucket(), and bucket.get_blob() with bucket.blob() in a few places where a lightweight instance of bucket/blob is sufficient for the function calls.

The fix reduces unnecessary get requests (from get_bucket and get_blob) in the following gcsio apis:

  • open
  • delete
  • delete_batch
  • copy
  • copy_batch
  • list_files

addresses #28398


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@shunping shunping changed the title Reduce the number of get requests in gcsio. Reduce the number of get requests in gcsio Feb 3, 2024
Copy link
Contributor

github-actions bot commented Feb 3, 2024

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

Copy link
Contributor

github-actions bot commented Feb 3, 2024

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @AnandInguva for label python.
R: @johnjcasey for label io.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Copy link

@lgeiger lgeiger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should .get_bucket in self._gcs_object also be replaced with .bucket?

It seems like bucket.get_blob already makes a HTTP request to check whether the blob exists, or am I missing something?

@lgeiger
Copy link

lgeiger commented Feb 5, 2024

Looking at the codebase again, maybe it also makes sense to adapt the code paths here and here to be consistent.

@shunping
Copy link
Contributor Author

shunping commented Feb 5, 2024

Should .get_bucket in self._gcs_object also be replaced with .bucket?

It seems like bucket.get_blob already makes a HTTP request to check whether the blob exists, or am I missing something?

I checked the code, it should be fine to replace the get_bucket() with bucket() within _gcs_object().

@shunping shunping changed the title Reduce the number of get requests in gcsio gcsio: reduce the number of get requests in function calls Feb 5, 2024
@shunping shunping changed the title gcsio: reduce the number of get requests in function calls gcsio: reduce number of get requests in function calls Feb 5, 2024
@shunping
Copy link
Contributor Author

shunping commented Feb 5, 2024

Run Python_Coverage PreCommit

bucket.delete_blob(blob_name)

for i, path in enumerate(current_paths):
error_code = None
for j in range(2):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. That was why it needed to be range(2) or range(4) in delete_batch and copy_batch

@johnjcasey
Copy link
Contributor

LGTM

@Abacn
Copy link
Contributor

Abacn commented Feb 7, 2024

Checked that tests passed and Comments are resolved, merging for now

@Abacn Abacn merged commit 4645a76 into apache:master Feb 7, 2024
71 checks passed
@Abacn
Copy link
Contributor

Abacn commented Feb 8, 2024

seems this change need to make test change accordingly. PythonPostCommit failing apache_beam.io.gcp.gcsfilesystem_integration_test.GcsFileSystemIntegrationTest.test_rename_error failing as it was on the premise of the request of delete one file returning two response code CC: @shunping

https://github.com/apache/beam/runs/21333859365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants