-
Notifications
You must be signed in to change notification settings - Fork 597
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
Inaccessible transaction.rollback
#633
Comments
I think we need to allow a way to get a (using datastore v1beta3 as an example) var transaction = datastore.transaction('transaction-id');
transaction.rollback(function(err, apiResponse) {}); This solves the second problem. But maybe it can help out with the first if we lose "runInTransaction" and just have "transaction.run"? var transaction = datastore.transaction(); // no args, it's a new one
transaction.run(function(err) {
transaction.get(['...'], function(err) {
if (err) {
return;
}
transaction.commit(function(err) {
if (err) {
return;
}
// If you want to rollback:
transaction.rollback(function(err) {});
});
});
}); I think it's more clear to remove the magic argument "done()" (which maps to commit) as well as the second callback that went to |
@callmehiphop any thoughts on this idea? |
I like it! It feels more consistent with our current APIs. |
My only comment would be all the nesting, but if and when we switch to promises, I think it'll actually be really nice.. datastore
.transaction()
.run(function() {
return transaction.get(['...']);
})
.then(function() {
return transaction.commit();
})
.then(function() {
return transaction.rollback();
}); |
👍 |
from my own testing, it looks like the logic being discussed here isn't actually how here is my example code:
From my various combinations of tests, it seems to behave how I would naturally expect it to : you can only |
A Transaction only makes a total of 2 requests to the Google API:
A transaction doesn't commit until So in other words, until
|
hmmm, actually i retried my example code above and it works like what you said.... strange... I could have swore it wasn't working properly when i checked last time! that said, given my simple example, you can also call
I can see how it only sets some state twice (creating the transaction and actually writing all the changes) but transactions must round-trip other stuff like transaction.get() requests. I am guessing (since in my other issue, atomic increments work!) that the transaction verifies the entity version I retrieved via by the way, I just tested, and you _can not rollback the transaction in the final callback_ such as shown below. the transaction is already done and can not be rolled back at that point:
|
@pcostell can you fill us in on how are rolling back a transaction is meant to work? |
@stephenplusplus can you clarify what the exact question is? Some general information: |
Okay, I was thinking rolling back a transaction is an undo of whatever occurred during the transaction. If it's more of a clean-up, is that something our library should just do automatically after a transactional commit? |
Transaction code should always look something like (excuse the python pseudocode):
In general, we should be able to hide this in the clients. However, the user needs to be able to say "actually this commit is problematic, abort". Perhaps passing an error into For example, in the case of a bank transaction, you might read both accounts, and if the source account doesn't have the necessary funds you would rollback, rather than commit the transfer of funds. Right now it doesn't really matter if you rollback or not, but that is purely a Datastore implementation detail. You should approach the problem assuming that the transaction locks all of your reads, so failing to rollback would cause all transactions afterwards on those entities to fail due to contention until the transaction times out. |
That makes a lot of sense, thanks for the explanation. |
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 408439482 Source-Link: googleapis/googleapis@b9f6184 Source-Link: googleapis/googleapis-gen@eb888bc Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWI4ODhiYzIxNGVmYzdiZjQzYmY0NjM0YjQ3MDI1NDU2NWE2NTlhNSJ9
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 408439482 Source-Link: googleapis/googleapis@b9f6184 Source-Link: googleapis/googleapis-gen@eb888bc Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWI4ODhiYzIxNGVmYzdiZjQzYmY0NjM0YjQ3MDI1NDU2NWE2NTlhNSJ9
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [sinon](https://sinonjs.org/) ([source](https://togithub.com/sinonjs/sinon)) | [`^9.0.1` -> `^10.0.0`](https://renovatebot.com/diffs/npm/sinon/9.2.4/10.0.0) | [![age](https://badges.renovateapi.com/packages/npm/sinon/10.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/sinon/10.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/sinon/10.0.0/compatibility-slim/9.2.4)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/sinon/10.0.0/confidence-slim/9.2.4)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>sinonjs/sinon</summary> ### [`v10.0.0`](https://togithub.com/sinonjs/sinon/blob/master/CHANGELOG.md#​1000--2021-03-22) [Compare Source](https://togithub.com/sinonjs/sinon/compare/v9.2.4...v10.0.0) ================== - Upgrade nise to 4.1.0 - Use [@​sinonjs/eslint-config](https://togithub.com/sinonjs/eslint-config)[@​4](https://togithub.com/4) => Adopts ES2017 => Drops support for IE 11, Legacy Edge and legacy Safari </details> --- ### Renovate configuration :date: **Schedule**: "after 9am and before 3pm" (UTC). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-translate).
* chore(main): release 4.1.1 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/2a81bca4-7abd-4108-ac1f-21340f858709/targets - [ ] To automatically regenerate this PR, check this box. Source-Link: googleapis/synthtool@dc9caca
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
🤖 I have created a release \*beep\* \*boop\* --- ### [3.1.5](https://www.github.com/googleapis/nodejs-dlp/compare/v3.1.4...v3.1.5) (2021-07-12) ### Bug Fixes * **deps:** google-gax v2.17.1 ([#632](https://www.github.com/googleapis/nodejs-dlp/issues/632)) ([78e120a](https://www.github.com/googleapis/nodejs-dlp/commit/78e120a74629cb3b165d4bcc3a3a880bad00caf6)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…#633) This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/7b446397-88f3-4463-9e7d-d2ce7069989d/targets - [ ] To automatically regenerate this PR, check this box. Source-Link: googleapis/synthtool@5936421
…#633) This PR was generated using Autosynth. 🌈 Synth log will be available here: https://source.cloud.google.com/results/invocations/7b446397-88f3-4463-9e7d-d2ce7069989d/targets - [ ] To automatically regenerate this PR, check this box. Source-Link: googleapis/synthtool@5936421
From https://github.com/GoogleCloudPlatform/gcloud-node/pull/627/files#r31352472
Question 1
A rollback can only be done on a transaction that has been committed (I think?), but that's a problem:
An option would be to remove the last callback.
Question 2
Is there a use case for rolling back a transaction that wasn't just created? We currently don't support this.
The text was updated successfully, but these errors were encountered: