-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Initial interface for transaction manager for manually managing retries of a transaction #2776
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
fabbb15
More fixes
vkedia 3d40e30
Fixed findbugs version
vkedia 14fb803
Merge branch 'master' into tracing
vkedia b62dee7
Add tracing to cloud spanner client
vkedia 027e3fb
Fix version of findbugs
vkedia 2804e1b
Made changes per code review comments
vkedia b118cf2
Merge remote-tracking branch 'upstream/master' into tracing
vkedia 9d06238
Fixed dependencies
vkedia 01c1085
Fixes style issues
vkedia c2c6240
Removed empty spaces
vkedia 8fe2ba2
Fixed NPE
vkedia 37a54fb
Handles the case of null SampledSpanStore
vkedia b369d9e
Changed error_prone version to 2.1.2
vkedia b279588
Changed opencensus version to 0.9.1
vkedia 755bf5d
Reverts the change to eclipse prefs file
vkedia 4fdd48a
Merge remote-tracking branch 'upstream/master' into tracing
vkedia 705c773
Merge remote-tracking branch 'upstream/master' into txn-api
vkedia 74bff14
Interface for manual transaction manager
vkedia 9dc4df9
More updates
vkedia 7b0b2e0
Merge remote-tracking branch 'upstream/master' into txn-api
vkedia be0e510
Tests for transaction manager.
vkedia 1ce2470
Merge remote-tracking branch 'upstream/master' into txn-api
vkedia 7ca9a0f
Indentation fix
vkedia 899d3df
Fixes TransactionRunner tests and adds 2 more tests
vkedia e01a554
Addresses codacy comments
vkedia e15694b
Added snippets in Javadoc
vkedia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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
104 changes: 104 additions & 0 deletions
104
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionManager.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright 2017 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.spanner; | ||
|
|
||
| import com.google.cloud.Timestamp; | ||
|
|
||
| /** | ||
| * An interface for managing the life cycle of a read write transaction including all its retries. | ||
| * See {@link TransactionContext} for a description of transaction semantics. | ||
| * | ||
| * <p>At any point in time there can be at most one active transaction in this manager. When that | ||
| * transaction is committed, if it fails with an {@code ABORTED} error, calling | ||
| * {@link #resetForRetry()} would create a new {@link TransactionContext}. The newly created | ||
| * transaction would use the same session thus increasing its lock priority. If the transaction is | ||
| * committed successfully, or is rolled back or commit fails with any error other than | ||
| * {@code ABORTED}, the manager is considered complete and no further transactions are allowed to be | ||
| * created in it. | ||
| * | ||
| * <p>Every {@code TransactionManager} should either be committed or rolled back. Failure to do so | ||
| * can cause resources to be leaked and deadlocks. Easiest way to guarantee this is by calling | ||
| * {@link #close()} in a finally block. | ||
| * | ||
| * @see DatabaseClient#transactionManager() | ||
| */ | ||
| public interface TransactionManager extends AutoCloseable { | ||
|
|
||
| /** | ||
| * State of the transaction manager. | ||
| */ | ||
| public enum TransactionState { | ||
| // Transaction has been started either by calling {@link #begin()} or via | ||
| // {@link resetForRetry()} but has not been commited or rolled back yet. | ||
| STARTED, | ||
| // Transaction was sucessfully committed. This is a terminal state. | ||
| COMMITTED, | ||
| // Transaction failed during commit with an error other than ABORTED. Transaction cannot be | ||
| // retried in this state. This is a terminal state. | ||
| COMMIT_FAILED, | ||
| // Transaction failed during commit with ABORTED and can be retried. | ||
| ABORTED, | ||
| // Transaction was rolled back. This is a terminal state. | ||
| ROLLED_BACK | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new read write transaction. This must be called before doing any other operation and | ||
| * can only be called once. To create a new transaction for subsequent retries, see | ||
| * {@link #resetForRetry()}. | ||
| */ | ||
| TransactionContext begin(); | ||
|
|
||
| /** | ||
| * Commits the currently active transaction. If the transaction was already aborted, then this | ||
| * would throw an {@link AbortedException}. | ||
| */ | ||
| void commit(); | ||
|
|
||
| /** | ||
| * Rolls back the currently active transaction. In most cases there should be no need to call this | ||
| * explicitly since {@link #close()} would automatically roll back any active transaction. | ||
| */ | ||
| void rollback(); | ||
|
|
||
| /** | ||
| * Creates a new transaction for retry. This should only be called if the previous transaction | ||
| * failed with {@code ABORTED}. In all other cases, this will throw an | ||
| * {@link IllegalStateException}. Users should backoff before calling this method. Backoff delay | ||
| * is specified by {@link SpannerException#getRetryDelayInMillis()} on the | ||
| * {@code SpannerException} throw by the previous commit call. | ||
| */ | ||
| TransactionContext resetForRetry(); | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
|
||
| /** | ||
| * Returns the commit timestamp if the transaction committed successfully otherwise it will throw | ||
| * {@code IllegalStateException}. | ||
| */ | ||
| Timestamp getCommitTimestamp(); | ||
|
|
||
| /** | ||
| * Returns the state of the transaction. | ||
| */ | ||
| TransactionState getState(); | ||
|
|
||
| /** | ||
| * Closes the manager. If there is an active transaction, it will be rolled back. Underlying | ||
| * session will be released back to the session pool. | ||
| */ | ||
| @Override | ||
| void close(); | ||
| } | ||
Oops, something went wrong.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.