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
feat(google-cloud-spanner): Implement "Inline Begin Transaction" #54
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit 83832a9.
SandeepTuniki
changed the title
Test ILB PR
feat: Implement "Inline Begin" in transactions
Aug 27, 2023
SandeepTuniki
changed the title
feat: Implement "Inline Begin" in transactions
feat(google-cloud-spanner): Implement "Inline Begin" in transactions
Aug 27, 2023
SandeepTuniki
changed the title
feat(google-cloud-spanner): Implement "Inline Begin" in transactions
feat(google-cloud-spanner): Implement "Inline Begin Transaction"
Aug 27, 2023
dazuma
requested changes
Aug 28, 2023
dazuma
reviewed
Aug 29, 2023
dazuma
reviewed
Aug 29, 2023
dazuma
approved these changes
Aug 29, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic looks good now. I have a few more recommendations on internal documentation, just to help with maintainability of the concurrency and synchronization.
NivedhaSenthil
approved these changes
Sep 4, 2023
This was referenced Sep 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements "Inline Begin Transaction" optimisation for Ruby Spanner.
Overview
Cloud Spanner allows users to query the data in several ways, including transactions. A transaction allows users to execute a series of statements as a single atomic unit, and allows them to rollback the changes in case of errors.
Most Cloud Spanner
*Request
APIs include aTransactionSelector
field for queries. TheTransactionSelector
field can be used within queries to specify an existing transaction ID or start a new transaction.Currently, we make an explicit
BeginTransaction
rpc to create a transaction in the backend, and get the transaction ID as the response. We pass the ID in theTransactionSelector
field in the subsequent operations within the transaction.This process has the following drawbacks:
Startup overhead - The client sets up the environment for transactions at the start of the client instantiation. This incurs an overhead in the instantiation time.
Prepared transactions - As we cannot predict in advance how many transactions the user will need, we must prepare several transactions during client instantiation. This is done by maintaining two separate session pools in a specific ratio, one for read-only transactions and the other for read-write transactions. As the user accesses this pool of sessions, the client must rebalance the ratio of the two stacks.
Transaction latency - The client makes an additional RPC to create a transaction. When the session pool runs out of available transactions, the client has to create more transactions. Both these factors increase the latency.
To address these drawbacks, we can defer the creation of transactions until the user executes the first query within the transaction. This is known as inlining the “begin transaction” call.
Implementation details
Below are the the high-level list of changes done throughout the codebase:
Pool
class:write_ratio
field and the corresponding code that maintains transactions through write_ratio.sessions_available
andsessions_in_use
to simplify the maintenance of session pool.all_sessions
,session_stack
andtransaction_stack
.Transaction
class:existing_transaction?
,safe_begin_transaction
,safe_execute
etc).Client
class:.transaction
method to handle inlining of transaction creation.check_and_propagate_err()
) to reduce code complexity issues identified by Rubocop.BatchUpdateResults
class:tx.batch_update()
API's response.Project
class:write_ratio
field as deprecated during client initialisation.Results
class:transaction
to facilitate extraction of a transaction from the results metadata.Session
class:Service
class:Tests
Unit tests
write_ratio
&transaction_stack
are removed, and some are modified to fit the new mechanism of the session pool.Acceptance tets