Skip to content

Conversation

rahul2393
Copy link
Contributor

@rahul2393 rahul2393 commented Jul 16, 2025

Read-Only, Read-Write and Partition Ops transactions now use a single multiplexed session, instead of a session from the session pool. Multiplexed sessions can handle any number of queries and read-only, read-write and partition ops transactions transactions at the same time.

The use of multiplexed sessions can be disabled for read-only, read-write and partition-ops transactions by setting the environment variables.

GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS=false
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW=false.
GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS=false.

See https://cloud.google.com/spanner/docs/sessions#multiplexed_sessions for more background information about multiplexed sessions.

@rahul2393 rahul2393 requested review from a team as code owners July 16, 2025 06:05
@rahul2393 rahul2393 requested a review from sakthivelmanii July 16, 2025 06:05
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/python-spanner API. size: m Pull request size is medium. and removed size: s Pull request size is small. labels Jul 16, 2025
@rahul2393 rahul2393 changed the title feat: enable multiplex session for all operations unless explicitly set to false feat: default enable multiplex session for all operations unless explicitly set to false Jul 16, 2025
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 2c80c1b to 4878ff3 Compare July 16, 2025 06:36
@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 Jul 16, 2025
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 776b838 to f224acb Compare July 16, 2025 07:43
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 85dddcf to 311451a Compare July 16, 2025 07:51
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 3e87b78 to e5993ff Compare July 16, 2025 08:31
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from eef951f to 3ad9ce9 Compare July 17, 2025 03:52
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 0798969 to 8741633 Compare July 17, 2025 07:43
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 8741633 to 67ea777 Compare July 17, 2025 07:43
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Jul 17, 2025
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from 3c5c5ad to 6450b4d Compare July 17, 2025 09:38
@rahul2393 rahul2393 force-pushed the multiplex-default-enable branch from eefc798 to 63bac62 Compare July 17, 2025 09:43
@@ -21,7 +21,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.12
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is because in followup PR we will be removing 3.8 runtime support
#1395


if is_multiplexed_enabled(transaction_type=TransactionType.READ_WRITE):
pytest.skip(
"Mutiplexed session can't be deleted and this test relies on session deletion."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sakthivelmanii
sakthivelmanii previously approved these changes Jul 17, 2025
surbhigarg92
surbhigarg92 previously approved these changes Jul 18, 2025
@rahul2393 rahul2393 dismissed stale reviews from surbhigarg92 and sakthivelmanii via 739a78e July 24, 2025 02:21
@@ -1031,7 +1030,7 @@ def _update_for_transaction_pb(self, transaction_pb: Transaction) -> None:
self._transaction_id = transaction_pb.id

if transaction_pb.precommit_token:
self._update_for_precommit_token_pb(transaction_pb.precommit_token)
self._update_for_precommit_token_pb_unsafe(transaction_pb.precommit_token)
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why we need two methods?

_update_for_precommit_token_pb, _update_for_precommit_token_pb_unsafe

Copy link
Contributor Author

@rahul2393 rahul2393 Jul 24, 2025

Choose a reason for hiding this comment

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

there was a deadlock happening, transaction was locked already when calling _update_for_transaction_pb, and in _update_for_precommit_token_pb we were again trying to lock it.

This was the issue from previous release which got uncovered once I tried making mux default enabled.

Copy link
Contributor Author

@rahul2393 rahul2393 Jul 24, 2025

Choose a reason for hiding this comment

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

Read this comment The caller is responsible for locking until the transaction ID is updated.

https://github.com/googleapis/python-spanner/blob/main/google/cloud/spanner_v1/snapshot.py#L1026-L1029

And then when we were calling _update_for_precommit_token_pb we were taking the lock again
https://github.com/googleapis/python-spanner/blob/main/google/cloud/spanner_v1/snapshot.py#L1046

So we needed 2 methods which takes lock when updating precommit token from unlocked code, and one which is called from places which assume lock is already taken

@rahul2393 rahul2393 merged commit 651ca9c into main Jul 24, 2025
31 of 32 checks passed
@rahul2393 rahul2393 deleted the multiplex-default-enable branch July 24, 2025 05:27
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/python-spanner API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants