-
Notifications
You must be signed in to change notification settings - Fork 116
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
chore(spanner): preserving lock order - R/W mux session #3348
Conversation
google-cloud-spanner/src/main/java/com/google/cloud/spanner/AsyncTransactionManagerImpl.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionImpl.java
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
Show resolved
Hide resolved
...r/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java
Outdated
Show resolved
Hide resolved
...r/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java
Outdated
Show resolved
Hide resolved
// TODO(sriharshach): Uncomment test once Lock order preservation proto is published | ||
/* | ||
@Test | ||
public void testAbortedReadWriteTxnUsesPreviousTxnIdOnRetryWithExplicitBegin() |
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.
Test Scenario
- Transaction 1 is started and the inline begin fails due to invalid update statement. This leads to ABORTED exception and transaction is retried.
- Transaction 2 is initiated with explicit begin transaction which succeeds and creates a transactionId (txn2). however transaction2 gets aborted during commit (The test forces the commit rpc to return ABORTED the first time it is called).
- Transaction 3 is started but again inline begin fails. Here txn id is null, but prevTransactionId will be txn2.
- Transaction 4 is started with explicit begin. As Transaction 3 never got an ID, the transaction id of Transaction 2 (txn2) is used in TransactionOptions.
This behavior is verified in test by checking that second explicit BeginTransaction RPC carries the txn2 as previous transaction id.
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.
Looks generally good to me. Waiting with approving until we can run the tests and verify that those are all green.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
Show resolved
Hide resolved
...r/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java
Outdated
Show resolved
Hide resolved
...r/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java
Outdated
Show resolved
Hide resolved
@olavloite The checks are green. Can you please help review? |
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.
LGTM, but with a minor request on making previousTransactionId
final.
google-cloud-spanner/src/main/java/com/google/cloud/spanner/TransactionRunnerImpl.java
Outdated
Show resolved
Hide resolved
f370394
into
googleapis:main
This PR introduces changes to support the lock order preservation protocol for multiplexed sessions in read/write transactions. According to this protocol, when a read/write transaction on a multiplexed session is retried, the transaction ID from the previous abort must be passed when creating a new transaction. This ensures that the retried transaction is recognized as older, rather than being treated as a new one.
The transaction context object is structured as follows,