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

source-s3: use context for file listing #350

Merged
merged 3 commits into from
Sep 21, 2022

Conversation

williamhbaker
Copy link
Member

@williamhbaker williamhbaker commented Sep 21, 2022

Closes #345

Description:

Threads the context through to the source-s3 connector List operation. #344 accomplished the same thing for Read. This will allow for better handling of context cancellations or timeouts.

Workflow steps:

Should be minimal observable impact. This will eliminate the potential for very large and/or slow file listings to lock up schema discovery indefinitely.

Documentation links affected:

N/A

Notes for reviewers:

I had initially thought this would take more work to get done, but it turned out to be pretty simple with the filesource.ListingFunc adapter already available. There wasn't much possible improvement I could see from refactoring the existing iterator code.


This change is Reviewable

@williamhbaker williamhbaker marked this pull request as ready for review September 21, 2022 18:47
@williamhbaker williamhbaker changed the title wip: use context for source-s3 file listing source-s3: use context for file listing Sep 21, 2022
Copy link
Member

@willdonnelly willdonnelly left a comment

Choose a reason for hiding this comment

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

LGTM % two nits

}, nil
}

return filesource.ListingFunc(func() (filesource.ObjectInfo, error) {
Copy link
Member

Choose a reason for hiding this comment

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

It feels a little bit weird to construct an s3Listing iterator and then wrap it in a closure. Perhaps add a ctx field to s3Listing instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I was trying perhaps a little too hard to not add a context field to a struct, but in this case it is probably more clear, and not that big of a deal anyway. Updated!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree with that guidance in general but IMO storing the context in a closure is morally equivalent to storing it in the struct proper.

The way to actually keep the spirit of those guidelines would be to refactor the listing iterator interface so it's .Next(ctx), but I didn't recommend that because it looks like other filesource implementations wouldn't be able to use that (for example, see source-gcs which takes the context from List() and makes that part of its *storage.ObjectIterator)

@@ -188,7 +192,7 @@ func (l *s3Listing) poll() error {
input.ContinuationToken = l.output.NextContinuationToken
}

if out, err := l.s3.ListObjectsV2(&input); err != nil {
if out, err := l.s3.ListObjectsV2WithContext(context.Background(), &input); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

It feels like this was intended to use ctx rather than context.Background()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally! Thanks.

@williamhbaker williamhbaker merged commit 537a5c9 into main Sep 21, 2022
@williamhbaker williamhbaker deleted the wb/source-s3-context-for-listing branch September 21, 2022 21:01
@oliviamiannone oliviamiannone added the docs complete / NA No (more) doc work related to this PR label Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs complete / NA No (more) doc work related to this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

source-s3: object listing does not use context
3 participants