Allow multi-shard read-only transactions in SINGLE transaction mode#18173
Conversation
… shard session Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #18173 +/- ##
=======================================
Coverage 67.46% 67.47%
=======================================
Files 1602 1602
Lines 262245 262243 -2
=======================================
+ Hits 176930 176946 +16
+ Misses 85315 85297 -18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…reated on executing a read query Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
|
It'd be nice to have a way to test for queries that would bounce against the new policy rather than actually bouncing it (producing a metric). That'd give us confidence to roll it out in prod |
|
Would it be possible to make cross shard writes opt-in via a comment directive (example)? |
|
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
@eeSeeGee There is no easy way to add this metric. What mode currently you are running in production? |
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
|
|
It is totally doable to add I can add that in a follow up PR |
@GrahamCampbell Only Select/Show statement are considered read-only and others are considered as write. |
That's amazing @harshit-gangal, thank you! I can foresee us heavily using that feature at Block to guardrail and test queries |
## Vitess v23 bump Upgrade VitessTestDb from v22 to v23.0.3. v23 includes vitessio/vitess#18173 which allows read-only multi-shard transactions in SINGLE transaction mode. This prevents false positive cross-shard detection failures when read-only queries touch multiple shards (e.g. from stale reserved connection shard sessions). ## allowCrossShardTransactions afterCompletion fix When the Hibernate session is still open after transaction commit (e.g. onSessionClose hooks pending), re-set transaction_mode to MULTI so those hooks can use cross-shard transactions. Without this, vtgate's reserved connection mode (triggered by SET) retains stale shard sessions across COMMIT (vitessio/vitess#11616), causing subsequent WRITE operations on the same pooled connection to fail in SINGLE mode. Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrade VitessTestDb from v22 to v23.0.0. v23 includes vitessio/vitess#18173 which allows read-only multi-shard transactions in SINGLE transaction mode. This changes SINGLE mode semantics: - v22: ALL multi-shard transactions rejected (reads and writes) - v23: Only multi-shard WRITES rejected; reads pass through Updated tests: - `cross-shard read` now succeeds (was expected to fail) - `cross-shard read + single-shard write` now succeeds (only multi-shard writes are rejected) - Added `onSessionClose hooks` test verifying read-only hooks work after allowCrossShardTransactions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrade VitessTestDb from v22 to v23.0.0. v23 includes vitessio/vitess#18173 which changes SINGLE transaction mode semantics: - v22: ALL multi-shard transactions rejected (reads and writes) - v23: Only multi-shard WRITES rejected; multi-shard reads allowed Updated tests to match v23 behavior: - cross-shard reads now succeed (previously expected to fail) - cross-shard read + single-shard write now succeeds - Added onSessionClose test for read-only hooks after allowCrossShardTransactions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrade VitessTestDb from v22 to v23.0.0. v23 includes vitessio/vitess#18173 which changes SINGLE transaction mode semantics: - v22: ALL multi-shard transactions rejected (reads and writes) - v23: Only multi-shard WRITES rejected; multi-shard reads allowed Updated tests to match v23 behavior: - cross-shard reads now succeed (previously expected to fail) - cross-shard read + single-shard write now succeeds - Added onSessionClose test for read-only hooks after allowCrossShardTransactions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrade VitessTestDb from v22.0.4 to v23.0.3. v23 includes vitessio/vitess#18173 which changes SINGLE transaction mode semantics: - v22: ALL multi-shard transactions rejected (reads and writes) - v23: Multi-shard reads allowed; only multi-shard writes rejected Changes: - Bump VITESS_IMAGE to v23.0.3-mysql84 and VTCTLD_CLIENT_IMAGE to v23.0.3 - Add platform fallback to linux/amd64 for Docker pull (Vitess does not publish ARM images; this enables transparent Rosetta emulation on Apple Silicon without breaking when ARM images are eventually published) - Update VitessTransactionModeIntegrationTest: cross-shard reads now succeed in SINGLE mode; multi-shard writes still fail Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Upgrade VitessTestDb from v22.0.4 to v23.0.3. v23 includes vitessio/vitess#18173 which changes SINGLE transaction mode semantics: - v22: ALL multi-shard transactions rejected (reads and writes) - v23: Multi-shard reads allowed; only multi-shard writes rejected Changes: - Bump VITESS_IMAGE to v23.0.3-mysql84 and VTCTLD_CLIENT_IMAGE to v23.0.3 - Add platform fallback to linux/amd64 for Docker pull (Vitess does not publish ARM images; this enables transparent Rosetta emulation on Apple Silicon without breaking when ARM images are eventually published) - Update VitessTransactionModeIntegrationTest: cross-shard reads now succeed in SINGLE mode; multi-shard writes still fail Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Bump Vitess test image to v23 and update SINGLE mode tests Upgrade VitessTestDb from v22.0.4 to v23.0.3. v23 includes vitessio/vitess#18173 which changes SINGLE transaction mode semantics: - v22: ALL multi-shard transactions rejected (reads and writes) - v23: Multi-shard reads allowed; only multi-shard writes rejected Changes: - Bump VITESS_IMAGE to v23.0.3-mysql84 and VTCTLD_CLIENT_IMAGE to v23.0.3 - Add platform fallback to linux/amd64 for Docker pull (Vitess does not publish ARM images; this enables transparent Rosetta emulation on Apple Silicon without breaking when ARM images are eventually published) - Update VitessTransactionModeIntegrationTest: cross-shard reads now succeed in SINGLE mode; multi-shard writes still fail Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Use explicit BEGIN in executeTransaction for reliable timeout enforcement Since vitessio/vitess#19277 (backported to v22.0.4 via #19341), vtgate defers implicit transaction start for autocommit=0 sessions. This means vttablet no longer applies --queryserver-config-transaction-timeout to queries running under SET autocommit=0. Switching to explicit BEGIN ensures vttablet tracks the transaction and enforces the timeout. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Description
This change updates the behavior of
transaction_mode = SINGLEto allow transactions that span multiple shards, as long as they only execute read queries.Previously, any query that opened sessions on more than one shard would cause the transaction to fail, even if all operations were reads. With this change:
This avoids unnecessary failures in common multi-shard read use cases, while still enforcing the single-shard write guarantee of
SINGLEmode.Related Issue(s)
Checklist