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

DISCUSSION: abstractions of service calls in storage #545

Closed
silvolu opened this issue Jan 14, 2015 · 4 comments
Closed

DISCUSSION: abstractions of service calls in storage #545

silvolu opened this issue Jan 14, 2015 · 4 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. type: question Request for information or clarification. Not an issue.

Comments

@silvolu
Copy link
Contributor

silvolu commented Jan 14, 2015

Generally speaking, the library functions seem to abstract when service interactions occur from the user. In other words, some operations are local to the object (e.g acl.grant), others interact with the service (e.g. acl.save), while still others interact only some of the time (e.g. bucket.default_object_acl).
If you're going to follow this model (and I'm not sure you should), I think you need to add preconditions to most service calls to ensure that confusing things don't happen.
A good example of this would be the save and reload functions in the ACL class. When should the user call reload()? I don't think it's clear. What happens when the user calls save() but the target ACL has changed on the service side since we last loaded it?

This abstraction is especially dangerous because it works very well when a single client is involved but creates subtle problems when deployed at scale.

/cc @thobrla

@silvolu silvolu added type: question Request for information or clarification. Not an issue. api: storage Issues related to the Cloud Storage API. labels Jan 14, 2015
@dhermes
Copy link
Contributor

dhermes commented Jan 23, 2015

In addition to a more focused / consistent approach, I think the methods in Connection should have no side effects, just as we do in the datastore subpackage.

Just look at something like Connection.delete_bucket. When called with force=True it makes an arbitrary (potentially large) number of delete calls for individual objects. This abstraction should happen on the Bucket class (if at all), not on the Connection. (has been done)

Some other differences / poorly aligned overlap (as of 86acc4a):

  • Connection.make_request in storage vs. Connection._request in datastore (big overlap) (_make_request is now protected)
  • Connection.api_request in storage vs. Connection._rpc in datastore (public vs. private) (api_request is used a lot elsewhere, so SHOULD be public)
  • Connection.__iter__ loops through all buckets (seems out of place). This is used in get_all_buckets. (has been removed)
  • Connection.lookup does what Connection.get_bucket (probably) should do. Either way, they are too similar and one should be removed. (has been removed)
  • Connection.new_bucket factory should be scrapped and higher quality Bucket constructor implemented (if needed) (ditto on Bucket.from_dict, a classmethod which could be incorporated into the constructor) (has been done)
  • Connection.generate_signed_url does not actually make any HTTP request and only relies on the associated credentials object for the connect. Consider making a function? (has been done)
  • Connection.__contains__ feels out of place and is a proxy for "does connection have access to this bucket? / does this bucket exist?" ((has been removed)

In addition, there are 10 uses of Connection.api_request outside of the Connection class:

$ git grep '\.api_request' | egrep -v 'storage/connection' | egrep -v test
gcloud/storage/_helpers.py:        self._properties = self.connection.api_request(
gcloud/storage/_helpers.py:        self._properties = self.connection.api_request(
gcloud/storage/acl.py:        found = self.bucket.connection.api_request(method='GET', path=url_path)
gcloud/storage/acl.py:            result = self.bucket.connection.api_request(
gcloud/storage/acl.py:        found = self.key.connection.api_request(method='GET', path=url_path)
gcloud/storage/acl.py:            result = self.key.connection.api_request(
gcloud/storage/bucket.py:            response = self.connection.api_request(method='GET', path=key.path)
gcloud/storage/bucket.py:        self.connection.api_request(method='DELETE', path=key.path)
gcloud/storage/bucket.py:        self.connection.api_request(method='POST', path=api_path)
gcloud/storage/iterator.py:        response = self.connection.api_request(

These should be consolidated inside Connection itself. (Ditto for the 2 uses of build_api_url in storage.key.)

@dhermes dhermes self-assigned this Jan 23, 2015
dhermes added a commit to dhermes/google-cloud-python that referenced this issue Jan 26, 2015
dhermes added a commit to dhermes/google-cloud-python that referenced this issue Jan 27, 2015
@jgeewax jgeewax added this to the Storage Stable milestone Jan 30, 2015
@dhermes
Copy link
Contributor

dhermes commented Feb 10, 2015

@thobrla We are trying to distill your concerns further. /cc @tseaver

RE: "others interact only some of the time": this is done mostly for lazy loading, which is a benefit for users. Do you think this is problematic?

RE: "ACL.save() without an ACL.reload()" I've been trying to unravel service calls and but having a hard time keeping track due to the convenience mapping of metadata keys to native Python properties. We have been discussing a bit, but don't have a clear solution / path forward.

Are you aware of

with bucket.batch:
    bucket.enable_versioning()
    bucket.disable_website()

@thobrla
Copy link

thobrla commented Feb 10, 2015

It is a benefit for users until an error occurs (even a transient service error) and breaks the illusion of atomicity.

Batching configuration changes into a single patch request is fine.

@dhermes
Copy link
Contributor

dhermes commented Feb 13, 2015

Closing based on @thobrla comment.

@dhermes dhermes closed this as completed Feb 13, 2015
vchudnov-g pushed a commit that referenced this issue Sep 20, 2023
…tectIntentRequest's text input is limited by 256 characters (#545)

* docs: updated some method comments and added an explicit note that DetectIntentRequest's text input is limited by 256 characters

PiperOrigin-RevId: 463362184

Source-Link: googleapis/googleapis@1805fc2

Source-Link: googleapis/googleapis-gen@c47083a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzQ3MDgzYTdiODI5Yzg1ZTM0MjMyNTBmN2NmNDMxZjA3MjM4YWQwNCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Sep 22, 2023
)

Source-Link: googleapis/synthtool@d6103f4
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:39f0f3f2be02ef036e297e376fe3b6256775576da8a6ccb1d5eeb80f4c8bf8fb

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Oct 21, 2023
* fix: Add async context manager return types

chore: Mock return_value should not populate oneof message fields

chore: Support snippet generation for services that only support REST transport

chore: Update gapic-generator-python to v1.11.0
PiperOrigin-RevId: 545430278

Source-Link: googleapis/googleapis@601b532

Source-Link: googleapis/googleapis-gen@b3f18d0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjNmMThkMGY2NTYwYTg1NTAyMmZkMDU4ODY1ZTc2MjA0NzlkN2FmOSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this issue Oct 21, 2023
Source-Link: googleapis/synthtool@eaef28e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f8ca7655fa8a449cadcabcbce4054f593dcbae7aeeab34aa3fcc8b5cf7a93c9e

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants