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

Add support for object attributes in Iter call #63

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fpetkovski
Copy link
Contributor

This commit adds support for passing in object attributes to the Iter callback. This PR makes a breaking change to the API since it adds a new parameter to the callback. The option is currently supported for GCS and Filesystem buckets only, but can be extended to other providers on demand.

An alternative implementation would be to add a new IterWithAttrs method and implement it only for a subset of providers. This will avoid a breaking change and will make the support of the feature more explicit. The downside is we need a new interface for something that is only an option and that could be supported for all providers in the future.

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Verification

This commit adds support for passing in object attributes to the Iter
callback. This PR makes a breaking change to the API since it adds
a new parameter to the callback. The option is currently supported
for GCS and Filesystem buckets only, but can be extended to other
providers on demand.

An alternative implementation would be to add a new IterWithAttrs
method and implement it only for a subset of providers. This will
avoid a breaking change and will make the support of the feature
more explicit. The downside is we need a new interface for something
that is only an option and that could be supported for all providers
in the future.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
Copy link
Member

@brancz brancz left a comment

Choose a reason for hiding this comment

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

I like this change a lot!

return p.bkt.Iter(ctx, pdir, func(s string) error {
return f(strings.TrimPrefix(s, p.prefix+DirDelim))
return p.bkt.Iter(ctx, pdir, func(s string, _ ObjectAttributes) error {
return f(strings.TrimPrefix(s, p.prefix+DirDelim), EmptyObjectAttributes)
Copy link
Member

Choose a reason for hiding this comment

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

why wouldn't it be passed through here?

// Entries are passed to function in sorted order.
Iter(ctx context.Context, dir string, f func(string) error, options ...IterOption) error
Iter(ctx context.Context, dir string, f func(name string, attrs ObjectAttributes) error, options ...IterOption) error
Copy link
Member

Choose a reason for hiding this comment

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

If we're already breaking this signature, I think we should instead make the whole thing pass only the ObjectAttributes struct and add the Name field to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense, and would allow us to extend supported attributes in the future.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly!

Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

Rather than breaking the API, could we add a new API?

@fpetkovski
Copy link
Contributor Author

Yeah I will look into adding a new APi. I am still not sure how to handle cases where a provider does not support returning attributes.

@pracucci
Copy link
Contributor

pracucci commented Aug 9, 2023

Yeah I will look into adding a new APi. I am still not sure how to handle cases where a provider does not support returning attributes.

An idea may be having a function on the objstore client to check if the feature is supported. Then the Iter() contract is that if the feature is supported, attributes will be fetched, otherwise if the feature is not supported it will error out. It's caller responsability to check if the feature is supported by the actual objstore client and take an informed decision about requesting attributes or not.

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

Successfully merging this pull request may close these issues.

None yet

4 participants