Skip to content

Commit

Permalink
feat: support concurrent transactions on the emulator (#1601)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olavloite committed May 4, 2024
1 parent a61c25d commit 7123991
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
* instance and database in the connection string will automatically be created if these do
* not yet exist on the emulator. This means that you do not need to execute any `gcloud`
* commands on the emulator to create the instance and database before you can connect to it.
* Setting this property to true also enables running concurrent transactions on the emulator.
* The emulator aborts any concurrent transaction on the emulator, and the JDBC driver works
* around this by automatically setting a savepoint after each statement that is executed.
* When the transaction has been aborted by the emulator and the JDBC connection wants to
* continue with that transaction, the transaction is replayed up until the savepoint that had
* automatically been set after the last statement that was executed before the transaction
* was aborted by the emulator.
* <li>endpoint (string): Set this property to specify a custom endpoint that the JDBC driver
* should connect to. You can use this property in combination with the autoConfigEmulator
* property to instruct the JDBC driver to connect to an emulator instance that uses a
Expand Down

0 comments on commit 7123991

Please sign in to comment.