Skip to content

VReplication: Sync in-memory workflow state metric on workflow read#20013

Open
mcrauwel wants to merge 3 commits into
vitessio:mainfrom
planetscale:mcrauwel/fix-vreplicate-state-does-not-advance
Open

VReplication: Sync in-memory workflow state metric on workflow read#20013
mcrauwel wants to merge 3 commits into
vitessio:mainfrom
planetscale:mcrauwel/fix-vreplicate-state-does-not-advance

Conversation

@mcrauwel
Copy link
Copy Markdown
Contributor

@mcrauwel mcrauwel commented May 4, 2026

Description

Use the stored state of the workflow as source of truth for the stats/metrics reporting.

Related Issue(s)

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

AI Disclosure

I worked with Claude Opus 4.7 on this

Copilot AI review requested due to automatic review settings May 4, 2026 14:11
@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 May 4, 2026
@mcrauwel mcrauwel changed the title fix for #20012 do not update the in-memory structure when the error persisting fails May 4, 2026
@github-actions github-actions Bot added this to the v25.0.0 milestone May 4, 2026
@vitess-bot
Copy link
Copy Markdown
Contributor

vitess-bot Bot commented May 4, 2026

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a VReplication observability/correctness issue where in-memory stream state metrics could advance to Error even when the corresponding _vt.vreplication row update fails (e.g., MySQL is read_only during reparent), causing operators to see misleading stream state in metrics and /debug/vars.

Changes:

  • Move in-memory State metric updates to occur only after the _vt.vreplication UPDATE succeeds (for both vreplicator and BinlogPlayer paths).
  • Add unit tests ensuring state metrics do not advance when the DB update fails.

Reviewed changes

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

File Description
go/vt/vttablet/tabletmanager/vreplication/vreplicator.go Defers vr.stats.State update until after the DB UPDATE succeeds.
go/vt/vttablet/tabletmanager/vreplication/vreplicator_test.go Adds a test ensuring setState doesn’t advance the metric on DB error.
go/vt/binlog/binlogplayer/binlog_player.go Defers blp.blplStats.State update until after the DB UPDATE succeeds.
go/vt/binlog/binlogplayer/binlog_player_test.go Adds a test ensuring setVReplicationState doesn’t advance the metric on DB error.

Comment thread go/vt/vttablet/tabletmanager/vreplication/vreplicator.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.82%. Comparing base (70c7a72) to head (e07ae8d).
⚠️ Report is 221 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #20013       +/-   ##
===========================================
+ Coverage   69.67%   73.82%    +4.15%     
===========================================
  Files        1614       34     -1580     
  Lines      216793     5845   -210948     
===========================================
- Hits       151044     4315   -146729     
+ Misses      65749     1530    -64219     
Flag Coverage Δ
partial 73.82% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mattlord mattlord changed the title do not update the in-memory structure when the error persisting fails VReplication: Sync in-memory workflow state on workflow read May 5, 2026
@mattlord mattlord added Backport to: release-23.0 Needs to be backport to release-23.0 Backport to: release-24.0 Needs to be backport to release-24.0 and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request Backport to: release-23.0 Needs to be backport to release-23.0 Backport to: release-24.0 Needs to be backport to release-24.0 labels May 5, 2026
mcrauwel added 3 commits May 5, 2026 14:51
Signed-off-by: Matthias Crauwels <matthias.crauwels@planetscale.com>
fixes vitessio#20012

Signed-off-by: Matthias Crauwels <matthias.crauwels@planetscale.com>
@mattlord mattlord changed the title VReplication: Sync in-memory workflow state on workflow read VReplication: Sync in-memory workflow state metric on workflow read May 5, 2026
@mattlord mattlord changed the title VReplication: Sync in-memory workflow state metric on workflow read VReplication: Sync in-memory workflow stat metric on workflow read May 5, 2026
@mattlord mattlord changed the title VReplication: Sync in-memory workflow stat metric on workflow read VReplication: Sync in-memory workflow state metric on workflow read May 5, 2026
Copilot AI review requested due to automatic review settings May 5, 2026 12:51
@mcrauwel mcrauwel force-pushed the mcrauwel/fix-vreplicate-state-does-not-advance branch from 11a6303 to 97b5678 Compare May 5, 2026 12:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

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

Labels

Component: TabletManager Component: VTTablet NeedsBackportReason If backport labels have been applied to a PR, a justification is required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: VReplication: stream state metric falsely reports Error when _vt.vreplication UPDATE fails

3 participants