Skip to content

fix(vttablet): scope 2PC redo rows by tablet database - #20764

Draft
cengdall-blaze wants to merge 1 commit into
vitessio:mainfrom
cengdall-blaze:cengdall/19493
Draft

fix(vttablet): scope 2PC redo rows by tablet database#20764
cengdall-blaze wants to merge 1 commit into
vitessio:mainfrom
cengdall-blaze:cengdall/19493

Conversation

@cengdall-blaze

@cengdall-blaze cengdall-blaze commented Jul 30, 2026

Copy link
Copy Markdown

Description

Add db_name to the 2PC redo sidecar tables and include it in the primary keys so multiple vttablets sharing a mysqld instance do not collide when preparing the same distributed transaction DTID.

Record the tablet DB name when saving redo state/statements, and scope redo reads, updates, deletes, and unresolved counts by that DB name. Keep fallback visibility for rows with an empty db_name so pre-upgrade prepared redo records can still be recovered or cleaned up.

Update tabletserver, end-to-end, vtexplain, and binlog test expectations for the new redo table shape.

Issue was confirmed fixed locally when running vttestserver and executing 2PCs.

Fixes #19493

Related Issue(s)

#19493

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

2PC redo sidecar tables now include the tablet database name in their primary key. Existing prepared redo rows from before this change use an empty db_name and remain visible for recovery and cleanup during upgrade. New redo rows are scoped by tablet database name, preventing DTID collisions when multiple vttablets share the same mysqld instance.

Legacy redo rows without db_name remain recoverable for the existing isolated-sidecar deployment model. In shared-sidecar environments, legacy rows were already ambiguous because they did not record the owning tablet DB; this change fixes newly written redo rows but cannot safely infer ownership for pre-existing shared-sidecar redo.

AI Disclosure

AI Assistance: This PR was written primarily by Codex. I used Codex to help root cause the initial issue while using vttestserver, then used Codex to determine and implement an appropriate fix.

Add `db_name` to the 2PC redo sidecar tables and include it in the
primary keys so multiple vttablets sharing a mysqld instance do not
collide when preparing the same distributed transaction DTID.

Record the tablet DB name when saving redo state/statements, and scope
redo reads, updates, deletes, and unresolved counts by that DB name. Keep
fallback visibility for rows with an empty db_name so pre-upgrade
prepared redo records can still be recovered or cleaned up.

Update tabletserver, end-to-end, vtexplain, and binlog test expectations
for the new redo table shape.

Fixes vitessio#19493

Signed-off-by: Chase Engdall <173094250+cengdall-blaze@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 15:04
@github-actions github-actions Bot added this to the v25.0.0 milestone Jul 30, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jul 30, 2026
@vitess-bot

vitess-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@github-actions github-actions Bot added Component: Documentation docs related issues/PRs Component: vtexplain changes made to vtexplain code Component: VTTablet labels Jul 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Scopes 2PC redo metadata by tablet database to prevent DTID collisions on shared MySQL instances.

Changes:

  • Adds db_name to redo schemas and primary keys.
  • Scopes redo operations while retaining legacy-row fallback.
  • Updates tests, documentation, and expected query output.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
go/vt/vttablet/tabletserver/twopc.go Implements database-scoped redo operations.
go/vt/vttablet/tabletserver/twopc_test.go Tests scoped query generation.
go/vt/vttablet/tabletserver/tx_engine_test.go Updates failed-redo query expectations.
go/vt/vttablet/tabletserver/tabletserver_test.go Updates supported redo reads.
go/vt/vttablet/tabletserver/query_executor_test.go Updates executor query fixtures.
go/vt/vttablet/tabletserver/dt_executor_test.go Updates redo lifecycle fixtures.
go/vt/vttablet/endtoend/twopc/prepare_test.go Scopes redo locking expectations.
go/vt/vtexplain/vtexplain_vttablet.go Updates simulated sidecar schemas.
go/vt/vtexplain/testdata/twopc-output/updatesharded-output.txt Updates generated 2PC output.
go/vt/vtexplain/testdata/twopc-output/options-output.txt Updates generated option output.
go/vt/vtexplain/testdata/twopc-output/insertsharded-output.txt Updates generated insert output.
go/vt/vtexplain/testdata/twopc-output/deletesharded-output.txt Updates generated delete output.
go/vt/sidecardb/schema/twopc/redo_statement.sql Adds statement database scope.
go/vt/sidecardb/schema/twopc/redo_state.sql Adds state database scope.
go/test/endtoend/transaction/twopc/main_test.go Adjusts binlog column extraction.
doc/design-docs/AtomicDistributedTransaction.md Documents the new schema.

Comment on lines +53 to +54
join %s.redo_statement s on t.dtid = s.dtid and t.db_name = s.db_name
where t.db_name = %s or (t.db_name = '' and not exists (select 1 from %s.redo_state cur where cur.dtid = t.dtid and cur.db_name = %s))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hmm. That makes sense. The goal here was to try to avoid the need to migrate or drain legacy rows. A clean option is to have maintainers drain before upgrading, but that feels like a high impact for an issue that only impacts the vttestserver.

The issue only affects environments where multiple vttablets share the same mysqld and the same sidecar database, which my understanding is unique to the vttestserver / vtcombo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well actually, thinking about this more, I believe the scenario described here is already unsafe in the legacy format.

If multiple vttablets share the same sidecar database, legacy redo rows do not contain enough ownership information to determine which tablet/application DB should replay them. This is probably already failing as a DTID primary-key collision, and even when it does not fail visibly, recovery of an unscoped legacy row is ambiguous. That's the current status-quo.

My understanding is that this shared-sidecar setup is not a normal production topology and is mainly relevant to vttestserver/vtcombo, which is the case this PR is trying to fix for newly written redo rows.

So I agree the fallback is not safe in the abstract for old shared-sidecar rows, but that was already true.

One possible mitigation would be to add a setting for shared-sidecar environments to skip legacy db_name = '' redo recovery, but I’m not sure that is worth adding given that it's an already-ambiguous state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Documentation docs related issues/PRs Component: vtexplain changes made to vtexplain code Component: VTTablet NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: vtcombo/vttestserver: 2PC fails with DuplicateKeyException on redo_state when transaction spans multiple keyspaces

2 participants