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

docs(spanner): fix the result handling after BufferWrite #3803

Merged
merged 6 commits into from Mar 31, 2021

Conversation

sryoya
Copy link
Contributor

@sryoya sryoya commented Mar 12, 2021

Fixes #3802

@sryoya sryoya requested review from skuruppu and a team as code owners March 12, 2021 12:36
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Mar 12, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 12, 2021
@skuruppu skuruppu requested a review from olavloite March 16, 2021 06:15
Copy link
Contributor

@olavloite olavloite left a comment

Choose a reason for hiding this comment

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

Good catch.

Transaction.BufferWrite will however normally not throw any errors (unless you have manually closed the transaction) as it only buffers the mutation in an in-memory data structure. So this would not affect transaction retries if you were to implement your own transaction functions using this sample. Any Aborted error would be returned by the Commit that is executed after the transaction function has returned.

spanner/doc.go Outdated
@@ -300,12 +300,10 @@ of the transaction:
}
balance -= 10
m := spanner.Update("Accounts", []string{"user", "balance"}, []interface{}{"alice", balance})
txn.BufferWrite([]*spanner.Mutation{m})

return txn.BufferWrite([]*spanner.Mutation{m})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could we move this line to after the comment. It does not feel right to have a comment after the return statement of a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I actually I wondered if it's right.
Then, fixed this with the similar code I referred to.

64546a2

@sryoya
Copy link
Contributor Author

sryoya commented Mar 19, 2021

@olavloite Thanks for your explanation.
As you say, BufferWrite doesn't seem to actually return an error.
But, One thing I've experienced is that since I added handling for error from the BufferWrite in my company's application , the failure rate of writes to Spanner has clearly decreased.
I'm not sure if it actually affected, but from that, I guessed the error from BufferWrite should be handled.
Also, I find the begin method, which mutates t.state, misses the Mutex lock. I guess it's irrelevant, but created the another PR for now #3841 (As commented in the description, if it's intentional, let me know that)

unless you have manually closed the transaction

Btw, how can we do this? I'm just curisous.

@sryoya sryoya requested a review from olavloite March 19, 2021 21:54
@olavloite
Copy link
Contributor

Btw, how can we do this? I'm just curisous.

You cannot do it with the normal transaction runner, but you could do it if you use statement-based transactions, by calling Rollback on the returned transaction. Using statement-based transactions is however only recommended for advanced usage (like writing a SQL driver), as it requires you to handle all retries of aborted transactions and other possible failures manually.

But, One thing I've experienced is that since I added handling for error from the BufferWrite in my company's application , the failure rate of writes to Spanner has clearly decreased.

I'm pretty sure that that is either coincidence or caused by a different change that was applied at the same time, as the BufferWrite function will never return a retryable error. It would therefore never affect the number of read/write transactions that need to be retried.

@olavloite olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 22, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 22, 2021
@olavloite olavloite added the automerge Merge the pull request once unit tests and other checks pass. label Mar 22, 2021
@gcf-merge-on-green
Copy link
Contributor

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Mar 22, 2021
@skuruppu skuruppu added kokoro:force-run Add this label to force Kokoro to re-run the tests. automerge Merge the pull request once unit tests and other checks pass. labels Mar 22, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 22, 2021
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Mar 23, 2021
@olavloite
Copy link
Contributor

@tbpg Would you be able to merge this one? The integration tests are not running as the PR comes from a fork. They are green however (and not really relevant, as it is only a documentation change).

@tbpg tbpg added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 31, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 31, 2021
@tbpg tbpg merged commit a93eddc into googleapis:master Mar 31, 2021
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 Spanner API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spanner: (Doc) Missing error handling after BufferWrite
5 participants