Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

feat: add blob.open() for file-like I/O - #385

Merged
gcf-merge-on-green[bot] merged 9 commits into
masterfrom
fileio
Mar 24, 2021
Merged

feat: add blob.open() for file-like I/O#385
gcf-merge-on-green[bot] merged 9 commits into
masterfrom
fileio

Conversation

@andrewsg

Copy link
Copy Markdown
Contributor

Fixes#29

@andrewsg
andrewsg requested review from a teamFebruary 22, 2021 02:24
@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Feb 22, 2021
@product-auto-labelproduct-auto-labelBot added the api: storage Issues related to the googleapis/python-storage API. label Feb 22, 2021
@andrewsg

Copy link
Copy Markdown
ContributorAuthor

Docstrings are WIP and system tests should be expanded before merging.

@andrewsgandrewsg added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Feb 22, 2021

@frankynfrankyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added some feedback that I want to talk through in implementation. Otherwise this is looking good. I'll review the design document as well.

Comment threadgoogle/cloud/storage/blob.py

# Upload chunks. The SlidingBuffer class will manage seek position.
for _ in range(num_chunks):
upload.transmit_next_chunk(transport)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know if partial success occurs does transmit_next_chunk handle the retry from the remote offset?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Define "partial success"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GCS may receive a subset of bytes from client upload, leaving the client and server next byte offset unaligned. A request to get current GCS offset can be made per Step Checking the status of a resumable upload.

If the client doesn't attempt to recover from this state, the inconsistent byte alignment will cause a 400 error which is not recoverable.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Got it. With the changes in this recent update, sliding buffer implements seek() so this feature is as supported as it's going to be in python-storage. If we want further support we need to flesh it out in resumable media.

@frankynfrankynMar 22, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's do that for recovering in a mismatch (address it in resumable media repo). Could you file a tracking issue in that repo?

Comment threadgoogle/cloud/storage/fileio.py Outdated
@andrewsgandrewsg removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 20, 2021
@andrewsg

Copy link
Copy Markdown
ContributorAuthor

Added docstrings, seek functionality in the sliding buffer, and other features. PTAL. Remaining questions: can we set up a system test to test end-to-end the error-on-chunk-upload-and-retry behavior? And, even though blob.download methods do not populate the blob generation, can we fetch that generation information from download metadata somehow in order to implement generation lock? (alternative: force blob.reload() before d/l if generation is not populated - race condition possible).

@frankyn

Copy link
Copy Markdown
Contributor

Remaining questions:

  1. Can we set up a system test to test end-to-end the error-on-chunk-upload-and-retry behavior?
  • Not without GCS emulator. You'd be better off mocking out the API request at this time.
  1. Even though blob.download methods do not populate the blob generation, can we fetch that generation information from download metadata somehow in order to implement generation lock? (alternative: force blob.reload() before d/l if generation is not populated - race condition possible).
  • You can get generation information from response headers. A similar issue came up in Node.js (for checksums) and here's example of responses specifically the header is named X-goog-generation:.

@frankynfrankyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Over LGTM, I have a few nits.

Also retrying on mismatched offset may be better handled / addressed in resumable media than in this wrapper so we could table it for now and open tracking issues in resumable media repo. WDYT?

Comment threadgoogle/cloud/storage/blob.py Outdated
Comment threadgoogle/cloud/storage/blob.py
Comment threadgoogle/cloud/storage/blob.py Outdated
Comment threadgoogle/cloud/storage/blob.py

@frankynfrankyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! 🚢

@andrewsgandrewsg added the automerge Merge the pull request once unit tests and other checks pass. label Mar 24, 2021
@gcf-merge-on-green
gcf-merge-on-greenBot merged commit 440a0a4 into masterMar 24, 2021
@gcf-merge-on-green
gcf-merge-on-greenBot deleted the fileio branch March 24, 2021 19:06
@gcf-merge-on-greengcf-merge-on-greenBot removed the automerge Merge the pull request once unit tests and other checks pass. label Mar 24, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: storageIssues related to the googleapis/python-storage API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an API method to give us a streaming file object

2 participants

@andrewsg@frankyn