Skip to content

Commit 7123991

Browse files
authoredMay 4, 2024··
feat: support concurrent transactions on the emulator (#1601)
Adds support for overlapping transactions on the emulator in the Connection API, even when these are executed on one thread. This is normally not supported, as it requires multiple transactions to run concurrently on the emulator. This change works around that by keeping track of what the active transaction on the emulator is, and then abort that transaction when another transaction needs to make progress. The transaction that was aborted will be retried up to the point where it was when it again wants to make progress. This step-by-step progress is implemented by automatically setting a savepoint in the transaction after each successful step. The transaction is then rolled back to that savepoint when another transaction needs to make progress. The feature is only enabled if the autoConfigEmulator flag is enabled.
1 parent a61c25d commit 7123991

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@
8484
* instance and database in the connection string will automatically be created if these do
8585
* not yet exist on the emulator. This means that you do not need to execute any `gcloud`
8686
* commands on the emulator to create the instance and database before you can connect to it.
87+
* Setting this property to true also enables running concurrent transactions on the emulator.
88+
* The emulator aborts any concurrent transaction on the emulator, and the JDBC driver works
89+
* around this by automatically setting a savepoint after each statement that is executed.
90+
* When the transaction has been aborted by the emulator and the JDBC connection wants to
91+
* continue with that transaction, the transaction is replayed up until the savepoint that had
92+
* automatically been set after the last statement that was executed before the transaction
93+
* was aborted by the emulator.
8794
* <li>endpoint (string): Set this property to specify a custom endpoint that the JDBC driver
8895
* should connect to. You can use this property in combination with the autoConfigEmulator
8996
* property to instruct the JDBC driver to connect to an emulator instance that uses a

0 commit comments

Comments
 (0)
Please sign in to comment.