Thanks to visit codestin.com
Credit goes to github.com

Skip to content

improve S3 v3 storage layer #8927

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

Merged
merged 9 commits into from
Aug 30, 2023
Merged

improve S3 v3 storage layer #8927

merged 9 commits into from
Aug 30, 2023

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Aug 16, 2023

Motivation

Improving the current S3 storage layer, introduce 2 more operations to allow easier cleanup of resources with bucket creation and deletion. Also separate between close and reset the store, to have better semantics between these 2 operations (closing does not always mean deleting all underlying objects, especially with persistence enabled).
Separate between the close call for the Ephemeral object, so that it doesn't close the underlying file object, which would delete it in Ephemeral mode, following the fix to the response with #8926.

Changes

Introduce said changes above, create_bucket and delete_bucket for the storage layer, and preparing support for persistence.

Also added a quick fix regarding creating bucket in us-east-1, I wasn't returning early from the method and ended up overwriting the bucket in the store.

Make close a noop for EphemeralS3StoredObject, and implement a delete method for cleaning up.

@bentsku bentsku added aws:s3 Amazon Simple Storage Service semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Aug 16, 2023
@bentsku bentsku self-assigned this Aug 16, 2023
@bentsku bentsku changed the title S3 native storage layer improve S3 s3 storage layer Aug 16, 2023
@coveralls
Copy link

coveralls commented Aug 16, 2023

Coverage Status

coverage: 80.347% (-0.02%) from 80.37% when pulling d7f237f on s3-native-storage-layer into 5b16d3b on master.

@@ -309,8 +309,16 @@ def on_after_init(self):
modify_service_response.append(S3Provider.service, s3_presigned_url_response_handler)
register_website_hosting_routes(router=ROUTER)

def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(s3_stores)
visitor.visit(AssetDirectory(self._storage_backend.root_directory))
Copy link
Contributor Author

@bentsku bentsku Aug 21, 2023

Choose a reason for hiding this comment

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

note: this won't work for community cloud pods, as there's a check that the path should start with config.dirs.data, and files might not be saved here in the community version as they're spooled

Copy link
Member

Choose a reason for hiding this comment

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

acceptable limitation for now 👍

@bentsku bentsku force-pushed the s3-native-pre-signed-handler branch from bcce35f to 626bc96 Compare August 21, 2023 19:36
@bentsku bentsku force-pushed the s3-native-storage-layer branch from edfad3a to 12b47d5 Compare August 21, 2023 19:36
@bentsku bentsku requested a review from thrau August 21, 2023 19:39
@bentsku bentsku marked this pull request as ready for review August 21, 2023 19:39
@bentsku bentsku requested a review from macnev2013 as a code owner August 21, 2023 19:39
@bentsku bentsku force-pushed the s3-native-pre-signed-handler branch 2 times, most recently from 555135b to 2c1a505 Compare August 22, 2023 14:55
Base automatically changed from s3-native-pre-signed-handler to master August 22, 2023 21:48
@bentsku bentsku force-pushed the s3-native-storage-layer branch from 12b47d5 to 952e428 Compare August 22, 2023 21:49
@github-actions
Copy link

github-actions bot commented Aug 22, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 23m 28s ⏱️
2 150 tests 1 676 ✔️ 474 💤 0
2 151 runs  1 676 ✔️ 475 💤 0

Results for commit d7f237f.

♻️ This comment has been updated with latest results.

@bentsku bentsku force-pushed the s3-native-storage-layer branch 2 times, most recently from 4dedad3 to bc4a45b Compare August 24, 2023 14:30
@bentsku bentsku changed the title improve S3 s3 storage layer improve S3 v3 storage layer Aug 28, 2023
@bentsku bentsku force-pushed the s3-native-storage-layer branch from bc4a45b to 68e49ac Compare August 30, 2023 11:29
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

nice! glad we did the iterations and now have a clean distinction between reset/flush/close in the contract 👍

@@ -309,8 +309,16 @@ def on_after_init(self):
modify_service_response.append(S3Provider.service, s3_presigned_url_response_handler)
register_website_hosting_routes(router=ROUTER)

def accept_state_visitor(self, visitor: StateVisitor):
visitor.visit(s3_stores)
visitor.visit(AssetDirectory(self._storage_backend.root_directory))
Copy link
Member

Choose a reason for hiding this comment

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

acceptable limitation for now 👍

Comment on lines 186 to 199
def create_bucket(self, bucket: BucketName):
pass

def delete_bucket(self, bucket: BucketName):
pass

def flush(self):
pass

def close(self):
pass

def reset(self):
pass
Copy link
Member

Choose a reason for hiding this comment

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

maybe some doc strings would be helpful to explain what the different behavior of flush,close,reset are

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do 👍 funnily, I don't think we use flush anywhere at the moment, as persistence is always "on" for the filesystem storage backend. But we could keep it for some fun behaviour with community pods or something?

Comment on lines 296 to 298
def __init__(self) -> None:
super().__init__()
self._storage_backend = EphemeralS3ObjectStore()
self._storage_backend = EphemeralS3ObjectStore(DEFAULT_S3_TMP_DIR)
Copy link
Member

Choose a reason for hiding this comment

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

i mentioned this before: maybe we could allow injecting a storage backend into the constructor

Copy link
Contributor Author

@bentsku bentsku Aug 30, 2023

Choose a reason for hiding this comment

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

Agreed. But isn't having the logic of the storage backend inside providers.py, depending on config be a bit weird? Are there other services doing this?
Thanks for the quick chat on Slack, I will make it optional so that we can inject it from pro and have the same default value. Awesome 👍

@bentsku bentsku merged commit 0b1f249 into master Aug 30, 2023
@bentsku bentsku deleted the s3-native-storage-layer branch August 30, 2023 15:06
ashish1500616 pushed a commit to ashish1500616/localstack that referenced this pull request Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:s3 Amazon Simple Storage Service semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants