-
Notifications
You must be signed in to change notification settings - Fork 810
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
Conversation
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. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
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.
Thank you for your contribution! Looks good overall, just had a few comments.
@shantuo, could you add integration tests for GCS and S3?
blob/gcsblob/gcsblob.go
Outdated
@@ -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) |
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.
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.
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.
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?
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.
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.
blob/driver/driver.go
Outdated
@@ -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. |
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.
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, |
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 also add tests for this new functionality for fileblob
.
@benhinchley Is this ready for @shantuo's review? |
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.
(Approving to unblock further review, but I'm going to let @shantuo review.)
@zombiezen yep changes you suggested have been made |
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.
Thank you for the PR, it generally look good. I just left a comment about the decision on the GCS implementation.
blob/gcsblob/gcsblob.go
Outdated
@@ -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) |
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.
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.
ModTime has the potenital to be time.Time zero value if a cloud storage impl doesn't provide this information
@shantuo I've update the gcsblob impl and added the comment to |
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 ourstorage.File
struct.This adds ModTime to
driver.ObjectAttrs
and adds it to the current driver implementations.