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

deleteRows transaction not atomic #336

Closed
allenwang7 opened this issue Sep 19, 2018 · 7 comments
Closed

deleteRows transaction not atomic #336

allenwang7 opened this issue Sep 19, 2018 · 7 comments
Assignees
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. 🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@allenwang7
Copy link

allenwang7 commented Sep 19, 2018

Environment details

  • OS: mac 10.13.6
  • Node.js version: 8.11
  • npm version: 5.6.0
  • @google-cloud/spanner version: 2.0.0

Steps to reproduce

  1. ???
  2. ???

deleteRows(table, keys, callback) {
const mutation = {};
mutation['delete'] = {
table: table,
keySet: {
keys: arrify(keys).map(function(key) {
return {
values: arrify(key).map(codec.encode),
};
}),
},
};
if (this.transaction) {
this.queue_(mutation);
return;
}
const reqOpts = {
singleUseTransaction: {
readWrite: {},
},
mutations: [mutation],
};
return this.request(
{
client: 'SpannerClient',
method: 'commit',
reqOpts: reqOpts,
},
callback
);
}

Performed that command up above. I tried to delete around 8000 rows, each having multiple indices/keys, so it went over the 20k mutations per transaction limit. I did not realize this, and ran it. The entire transaction should fail, but it actually deleted as much as it could under the 20k limit, then threw the over 20k mutations/transaction error. Is this expected?

Thanks!

@JustinBeckwith JustinBeckwith added the triage me I really want to be triaged. label Sep 20, 2018
@crwilcox
Copy link
Contributor

@allenwang7, could you share the code fragment which caused this to happen? I imagine it resembles the sample code in the docstring, but I want to be sure I understand how this occurred.

@JustinBeckwith JustinBeckwith added the 🚨 This issue needs some love. label Sep 24, 2018
@allenwang7
Copy link
Author

@crwilcox , something like this.

const rows = [rows] // an array of rows
const keys = rows.map((row) => [row.id, row.shardId]);

// keys here have more than 20k mutations.
table.deleteRows(keys)
.catch((err) => console.log(err));

@stephenplusplus
Copy link
Contributor

Would the fix here be to do some local validation and throw an error? Or is this a bug or enhancement upstream?

@callmehiphop
Copy link
Contributor

/cc @snehashah16

@snehashah16
Copy link

Would the fix here be to do some local validation and throw an error? Or is this a bug or enhancement upstream?

There is no way to validate this in the client library.
That said, the backend should have thrown an error for exceeding mutations, and not committed any
change.

I notice the library is using the singleUse txn here. i would recommend we change it to an explicit begin txn -> buffer mutations -> commit workflow.

@JustinBeckwith JustinBeckwith added the status: investigating The issue is under investigation, which is determined to be non-trivial. label Oct 1, 2018
@JustinBeckwith JustinBeckwith added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Oct 1, 2018
@stephenplusplus
Copy link
Contributor

I'll close this, and we can let #347 serve as the tracker for implementing transaction usage throughout the library.

@snehashah16
Copy link

I recommend we open this bug again. This is also not a feature request.
Please keep this bug as a tracker to verify all issues are fixed after #347 is completed.

@JustinBeckwith JustinBeckwith reopened this Oct 4, 2018
@JustinBeckwith JustinBeckwith added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed status: investigating The issue is under investigation, which is determined to be non-trivial. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Oct 4, 2018
@snehashah16 snehashah16 added priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 4, 2018
@JustinBeckwith JustinBeckwith added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Oct 9, 2018
@JustinBeckwith JustinBeckwith added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Oct 14, 2018
@ghost ghost removed the priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. label Oct 16, 2018
@google-cloud-label-sync google-cloud-label-sync bot added the api: spanner Issues related to the googleapis/nodejs-spanner API. label Jan 31, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/nodejs-spanner API. 🚨 This issue needs some love. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

7 participants