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

blob: add modification time to driver.ObjectAttrs #240

Merged
merged 8 commits into from
Aug 9, 2018
Merged

blob: add modification time to driver.ObjectAttrs #240

merged 8 commits into from
Aug 9, 2018

Conversation

benhinchley
Copy link
Contributor

@benhinchley benhinchley commented Jul 26, 2018

At Sajari we have been doing something similar to blob with our own storage pkg for quite some time now.

I started working on migrating our storage pkg to use go-cloud/blob underneath, and noticed that modification time was not a part of the driver.ObjectAttrs struct. This is something that we use internally and is a part of our storage.File struct.

This adds ModTime to driver.ObjectAttrs and adds it to the current driver implementations.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@benhinchley
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@benhinchley benhinchley changed the title blob(WIP): add modification time to driver.ObjectAttrs blob: add modification time to driver.ObjectAttrs Jul 26, 2018
@zombiezen zombiezen added the enhancement New feature or request label Jul 26, 2018
Copy link
Contributor

@zombiezen zombiezen left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Looks good overall, just had a few comments.

@shantuo, could you add integration tests for GCS and S3?

@@ -65,11 +68,18 @@ func (r *reader) Attrs() *driver.ObjectAttrs {
func (b *bucket) NewRangeReader(ctx context.Context, key string, offset, length int64) (driver.Reader, error) {
bkt := b.client.Bucket(b.name)
obj := bkt.Object(key)
attrs, err := obj.Attrs(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unfortunate that this requires a second network call, but it was bound to happen eventually.

My one concern is that there is a race here: Attrs could be for a different version than the reader is for. In this case, there's not that much cause for concern, but I'd like to add the constraint now so that as the code evolves, we don't hit the issue later.

Copy link
Contributor

Choose a reason for hiding this comment

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

One alternative is to not call obj.Attrs inside NewRangeReader, instead, call it when user explicitly asks for it the first time. At that point we can check whether this field is non-zero and decide to make the call. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

The updated field is included in the object but not carried by the client library we use here. I suggest removing the implementation here for GCS and keep those for S3 and file, add comments to the blob package saying that this ModTime field is optional. We'll try to have it supported by the client library first and add it back here.

@@ -66,6 +67,8 @@ type ObjectAttrs struct {
Size int64
// ContentType is the MIME type of the blob object. It must not be empty.
ContentType string
// ModTime is the modified time of the blob object.
Copy link
Contributor

Choose a reason for hiding this comment

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

I can imagine circumstances where implementations might not have this information. Let's add a comment to the effect that ModTime might be the zero time if unknown.

@@ -148,6 +152,7 @@ func (r reader) Attrs() *driver.ObjectAttrs {
return &driver.ObjectAttrs{
Size: r.size,
ContentType: r.xa.ContentType,
ModTime: r.modTime,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add tests for this new functionality for fileblob.

@zombiezen
Copy link
Contributor

@benhinchley Is this ready for @shantuo's review?

@zombiezen zombiezen requested review from shantuo and zombiezen and removed request for zombiezen August 6, 2018 20:40
Copy link
Contributor

@zombiezen zombiezen left a comment

Choose a reason for hiding this comment

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

(Approving to unblock further review, but I'm going to let @shantuo review.)

@benhinchley
Copy link
Contributor Author

@zombiezen yep changes you suggested have been made

@googlebot googlebot added the cla: yes Google CLA has been signed! label Aug 7, 2018
Copy link
Contributor

@shantuo shantuo left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, it generally look good. I just left a comment about the decision on the GCS implementation.

@@ -65,11 +68,18 @@ func (r *reader) Attrs() *driver.ObjectAttrs {
func (b *bucket) NewRangeReader(ctx context.Context, key string, offset, length int64) (driver.Reader, error) {
bkt := b.client.Bucket(b.name)
obj := bkt.Object(key)
attrs, err := obj.Attrs(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

The updated field is included in the object but not carried by the client library we use here. I suggest removing the implementation here for GCS and keep those for S3 and file, add comments to the blob package saying that this ModTime field is optional. We'll try to have it supported by the client library first and add it back here.

@benhinchley
Copy link
Contributor Author

@shantuo I've update the gcsblob impl and added the comment to blob.ModTime() about this possibly returning time.Time zero value

@shantuo shantuo merged commit cddd637 into google:master Aug 9, 2018
@benhinchley benhinchley deleted the add-modtime-to-blob branch August 10, 2018 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA has been signed! enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants