Skip to content
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

Merged
merged 18 commits into from
Oct 16, 2024

Conversation

harshachinta
Copy link
Contributor

@harshachinta harshachinta commented Sep 25, 2024

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,

txn {
    transactionId: The transaction ID.
    previousTransactionId: The transaction ID of the most recently failed transaction.
}

@harshachinta harshachinta requested a review from a team as a code owner September 25, 2024 09:43
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/java-spanner API. labels Sep 25, 2024
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Sep 27, 2024
@harshachinta harshachinta changed the title chore(spanner): preserving lock order chore(spanner): preserving lock order - R/W mux session Sep 27, 2024
// TODO(sriharshach): Uncomment test once Lock order preservation proto is published
/*
@Test
public void testAbortedReadWriteTxnUsesPreviousTxnIdOnRetryWithExplicitBegin()
Copy link
Contributor Author

@harshachinta harshachinta Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Scenario

  1. Transaction 1 is started and the inline begin fails due to invalid update statement. This leads to ABORTED exception and transaction is retried.
  2. 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).
  3. Transaction 3 is started but again inline begin fails. Here txn id is null, but prevTransactionId will be txn2.
  4. 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.

Copy link
Collaborator

@olavloite olavloite left a 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.

@harshachinta
Copy link
Contributor Author

harshachinta commented Oct 14, 2024

Looks generally good to me. Waiting with approving until we can run the tests and verify that those are all green.

@olavloite The checks are green. Can you please help review?

Copy link
Collaborator

@olavloite olavloite left a 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.

@harshachinta harshachinta added the automerge Merge the pull request once unit tests and other checks pass. label Oct 16, 2024
@gcf-merge-on-green gcf-merge-on-green bot merged commit f370394 into googleapis:main Oct 16, 2024
30 of 31 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants