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: Is there a way for a Transaction to indicate success/failure from __exit__ #496

Closed
dhermes opened this issue Jan 7, 2015 · 3 comments · Fixed by #595
Closed
Assignees
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.

Comments

@dhermes
Copy link
Contributor

dhermes commented Jan 7, 2015

From #336.

Currently, there is no way to determine if this occurs. It's unclear what a way forward would look like but in ndb transactions have retries and can create Future objects which know about the success or failure.

@dhermes dhermes added type: question Request for information or clarification. Not an issue. api: datastore Issues related to the Datastore API. labels Jan 7, 2015
@tseaver
Copy link
Contributor

tseaver commented Jan 7, 2015

The transaction package has a concept of a "doomed" transaction: one which is in a hosed state, from which it can never be committed. Having our code fail inside __exit__ would be something like that with two sharp edges:

  • Failing while committing is actually more reasonable: the back-end might actually barf here.
  • Failing while aborting is a real problem: which exception should surface?

FWIW, the Zope transaction's "two-phase commit" tries to deal with the problems of the first, by breaking up the "commit" into slices, for distribution across multiple resource managers (e.g., a database and a mail-sender). For each of the following methods, the transaction calls each resource manager in turn):

  • tpc_begin (can we commit?)
  • commit(do the work, but don't finalize)
  • tpc_vote (were there problems? last chance to back out)
  • tpc_finish (finalize; this must never fail: if it does, we've lost consistency)
  • tpc_abort (called if any RM raises from tpc_vote: must never fail).

@dhermes
Copy link
Contributor Author

dhermes commented Jan 8, 2015

For the most part the backend handles this.

It seems a concept of "doomed" would be nice since it would make it so that.

txn = Transaction()
with txn:
    entity.save()
    ...

# This fails since txn has already been used, hence is doomed.
with txn:
    new_entity.save()

I was thinking something simple along the lines of

>>> txn.in_progress
False
>>> txn.succeeded
True
>>> txn.finished
True

There seem to be less than 8 states (implied by 3 bools) but more than 4, so maybe there is a better way to get the information to answer the questions:

  • txn is in progress or not?
  • txn has already been "used"?
  • txn finished in commit (success) or rollback (failure)

@elibixby
Copy link

elibixby commented Jan 8, 2015

You also need some way to get auto allocated keys back from the transaction right? Could this be incorporated into the method which indicates failure or success?

@jgeewax jgeewax modified the milestones: Datastore Stable, Datastore Future Feb 2, 2015
@dhermes dhermes self-assigned this Feb 5, 2015
dhermes added a commit to dhermes/google-cloud-python that referenced this issue Feb 5, 2015
Fixes googleapis#496.

NOTE: Some of these changes may belong on Batch, but the concept
of "tombstone"-ing is unique to a Transaction (i.e. once started,
can only be committed once and the transaction ID can never be
used again).
dhermes added a commit to dhermes/google-cloud-python that referenced this issue Feb 6, 2015
Fixes googleapis#496.

NOTE: Some of these changes may belong on Batch, but the concept
of "tombstone"-ing is unique to a Transaction (i.e. once started,
can only be committed once and the transaction ID can never be
used again).
tswast added a commit to tswast/google-cloud-python that referenced this issue Apr 1, 2019
atulep pushed a commit that referenced this issue Apr 6, 2023
…p/templates/python_library/.kokoro (#496)

Source-Link: https://github.com/googleapis/synthtool/commit/bb171351c3946d3c3c32e60f5f18cee8c464ec51
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f62c53736eccb0c4934a3ea9316e0d57696bb49c1a7c86c726e9bb8a2f87dadf
atulep pushed a commit that referenced this issue Apr 18, 2023
…p/templates/python_library/.kokoro (#496)

Source-Link: https://github.com/googleapis/synthtool/commit/bb171351c3946d3c3c32e60f5f18cee8c464ec51
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f62c53736eccb0c4934a3ea9316e0d57696bb49c1a7c86c726e9bb8a2f87dadf
parthea pushed a commit that referenced this issue Aug 15, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
vchudnov-g pushed a commit that referenced this issue Sep 20, 2023
)

Source-Link: googleapis/synthtool@7804ade
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:eede5672562a32821444a8e803fb984a6f61f2237ea3de229d2de24453f4ae7d
parthea pushed a commit that referenced this issue Sep 22, 2023
Source-Link: https://github.com/googleapis/synthtool/commit/92006bb3cdc84677aa93c7f5235424ec2b157146
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2e247c7bf5154df7f98cce087a20ca7605e236340c7d6d1a14447e5c06791bd6
parthea pushed a commit that referenced this issue Oct 21, 2023
…496)

* feat: Add client library support for AssetService v1 SavedQuery APIs
Committer: jeffreyai@

PiperOrigin-RevId: 475366952

Source-Link: googleapis/googleapis@7428dad

Source-Link: googleapis/googleapis-gen@5629e2a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTYyOWUyYWI3Mjg0NDNhMWE2YWJiMDNmMzRmOTI1ZDVjZDRlMGM0NyJ9

* 🦉 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 added a commit that referenced this issue Oct 21, 2023
* chore: exclude requirements.txt file from renovate-bot

Source-Link: googleapis/synthtool@f58d313
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7a40313731a7cb1454eef6b33d3446ebb121836738dc3ab3d2d3ded5268c35b6

* update constraints files

* fix(deps): require protobuf 3.20.2

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
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@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 22, 2023
…p/templates/python_library/.kokoro (#496)

Source-Link: https://github.com/googleapis/synthtool/commit/bb171351c3946d3c3c32e60f5f18cee8c464ec51
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f62c53736eccb0c4934a3ea9316e0d57696bb49c1a7c86c726e9bb8a2f87dadf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants