Skip to content

storage: Support negative offset range requests #1540

Closed
@brimworks

Description

The GCS service supports negative suffix length range requests:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range

Range: <unit>=-<suffix-length>

However, the Go client doesn't currently allow making range requests in this way. One use-case for this is fetching the last N bytes of a log file, something that is especially useful in the context of a log file for a failed build (since error messages typically are at the end of the log file).

Additionally, when specifying a suffix length, it is useful to know the absolute offset of the partial content which was returned. This is useful so one can implement "page backwards" functionality.

This information is in the Content-Range header which is already being parsed to obtain the total size of the object even though a partial response is being returned:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range

Content-Range: <unit> <range-start>-<range-end>/<size>

To that end, I've put forth two patches which would allow this functionality:

https://code-review.googlesource.com/c/gocloud/+/44131
https://code-review.googlesource.com/c/gocloud/+/44132

The 44131 patch extends the existing NewRangeReader() API so that instead of returning an error if the offset parameter is negative, it would interpret this to indicate that it is desired to obtain the absolute value number of bytes from the END of the object.

The 44132 patch extends the existing ReaderObjectAttrs structure with a new Offset field which would return the absolute offset of bytes that was returned. Specifically, if a positive offset is passed into NewRangeReader() API, then the ReaderObjectAttrs.Offset would reflect that exact same value. However, this becomes more useful when a negative offset is passed to ReadObjectAttrs, since this would reflect the actual absolute offset of bytes that was returned.

Activity

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

Metadata

Labels

api: storageIssues related to the Cloud Storage API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions