Skip to content

SpannerToSourceDbLargeBacklogLT: fix assertion mechanism - #4514

Merged
aasthabharill merged 5 commits into
mainfrom
lt-backlog-shadow-count
Nov 5, 2026
Merged

aasthabharill merged 5 commits into
mainfrom
lt-backlog-shadow-count

Conversation

@aasthabharill

@aasthabharill aasthabharill commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

SpannerToSourceDbLargeBacklogLT now waits for the shadow table in the metadata database to reach the expected row count, instead of waiting for the Dataflow counter success_record_count. The counter can stay short forever even when every row has reached MySQL, which made the test time out.

Problem

About 5 of the last 12 runs failed the same way. The reverse replication job processed the whole 1B-row backlog, but success_record_count stopped a little short of 1e9 (318, 134,018 and 56 rows short on 10-06, 10-09 and 10-20) and never moved again. The test only runs the MySQL row count after the counter reaches 1e9, so it waited until the 600 min timeout and failed without ever checking MySQL. A longer timeout would not help: the counter stayed flat for up to 2.5 hours before the timeout in past runs.

Root cause

success_record_count is not an exact count of applied rows. For each record, the writer commits the MySQL write and the shadow table row in one Spanner transaction, and only then increments the counter. Dataflow reports counter increments from each worker periodically. If a worker is removed after the transaction commits but before its increments are reported, those increments are lost. The record is never counted again: on any retry the writer sees that its shadow row is already applied and skips it without counting.

At the end of the backlog, the Dataflow autoscaler removes about 199 of the 200 workers in one step. In every failed run we looked at, that downscale happened before the counter reached 1e9, and the counter froze right after it. In the passing runs, the downscale happened after the counter reached 1e9.

Fix

  • Poll SELECT COUNT(*) on the shadow table rev_shadow_MigrationLoadTest every 15 minutes and pass when it equals expectedSpannerCount. This is a valid stand-in for "all rows are in MySQL" because each shadow row is written in the same transaction as its MySQL write and commits after it, there is one shadow row per primary key, the table starts empty, and this test only inserts rows and has no custom filtering.
  • Keep the existing MySQL row count check after the gate as the final assertion.
  • Add SpannerToSourceDbOptions.DEFAULT_SHADOW_TABLE_PREFIX and use it for both the option default and the test's shadow table name, so the test keeps polling the right table if the default prefix changes.
  • Log how long each shadow COUNT(*) takes. This is temporary, to confirm the query cost on another run, and can be removed after that.
  • Remove the now unused metricThreshold property.

Evidence

I tracked the failure that happened this week (on 3rd nov) with a long running agent task - this run showed the counter stall and failed after timing out, but the shadow table count during this stall had reached 1 billion. This is proof that there's no data issue, its a counter mismatch and we need to stop asserting on it

Run What it showed
Past failures (10-06, 10-09, 10-20) Autoscaler cut 200 workers to 1-3 before the counter reached 1e9; counter froze within one poll
Past passes (6 checked) Downscale came after the counter reached 1e9, or not at all before cancel
Small repro (3 workers, 170k rows) Deleting 1 worker VM lost 10k increments of another counter and about 1.3k success counts; MySQL and shadow both had all 170k rows
Diagnostic 1B run (10-27, passed) Shadow = MySQL = 1e9. Ruled out lost commits after timeouts (4,694 timeouts, all retried and counted), lost counts from reprocessing (8.3M redelivered records, exact count), and duplicate writes
This branch, 1B run (11-02, passed) Autoscaler 200 to 3 at 16:44:41, before the counter reached 1e9. Counter froze at 999,999,996 and stayed there after cancel. Shadow = 1,000,000,000 at 16:45:07, MySQL = 250M on each of the 4 shards on the first check

The 11-02 run is the clearest case: with the old gate it would have timed out, while the data was complete.

Shadow COUNT(*) cost on 11-02 (metadata instance at 20 nodes during replication, 30 polls):

Shadow rows Query time
Under 50M 1-3 s
270M to 1B 7-21 s
Slowest poll (827M) 51.5 s

The only failed poll was the first one, about 2.5 minutes after the reverse job started, most likely because the template had not yet created the shadow table. The test retried 15 minutes later as intended.

Testing

CODELAB_BUG=b/12345678 (dummy)

…ad of success_record_count

success_record_count can permanently fall short of the real count (for example,
increments are lost when workers are removed), which made the test time out
even though all rows reached MySQL. Poll the row count of the shadow table in
the metadata database instead: each shadow row is written in the same Spanner
transaction as its MySQL write and commits after it. success_record_count is
still logged for information, and the shadow COUNT(*) duration is logged.
@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.60%. Comparing base (3edd1de) to head (3c8cc64).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4514      +/-   ##
============================================
+ Coverage     56.87%   63.60%   +6.73%     
+ Complexity     8087     3088    -4999     
============================================
  Files          1164      582     -582     
  Lines         74114    34524   -39590     
  Branches       8735     3961    -4774     
============================================
- Hits          42150    21960   -20190     
+ Misses        29164    11450   -17714     
+ Partials       2800     1114    -1686     
Components Coverage Δ
spanner-templates 83.99% <ø> (+0.29%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 87.60% <ø> (+0.67%) ⬆️
spanner-live-reverse-replication 79.81% <ø> (+0.59%) ⬆️
spanner-bulk-migration 88.27% <ø> (+0.38%) ⬆️
gcs-spanner-dv 86.50% <ø> (+0.78%) ⬆️
see 613 files with indirect coverage changes
🚀 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.

…, drop success_record_count logging

Add SpannerToSourceDbOptions.DEFAULT_SHADOW_TABLE_PREFIX and use it for both the
option default and the LT's shadow table name, so the LT keeps polling the right
table if the default prefix changes. Stop logging success_record_count, which the
LT no longer uses.
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Codelab Update Reminder Assured
A CODELAB_BUG reference was found. Thank you for tracking the DevSite Codelab documentation updates!

Please follow the step-by-step instructions in go/update-migrations-codelabs to update the codelabs with your changes.

@aasthabharill
aasthabharill marked this pull request as ready for review November 5, 2026 05:27
@aasthabharill
aasthabharill requested a review from a team as a code owner November 5, 2026 05:27
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses intermittent failures in the 'SpannerToSourceDbLargeBacklogLT' load test. The previous reliance on Dataflow's 'success_record_count' metric proved unreliable due to lost counter increments during worker downscaling. By switching to a direct 'SELECT COUNT(*)' on the shadow table, the test now accurately tracks replication completion, significantly improving the stability and reliability of the long-running load test.

Highlights

  • Improved Test Assertion Mechanism: Replaced the unreliable Dataflow 'success_record_count' metric with a direct poll of the shadow table row count in the metadata database to verify replication progress.
  • Configuration Updates: Added 'DEFAULT_SHADOW_TABLE_PREFIX' to 'SpannerToSourceDbOptions' to ensure consistent shadow table naming and removed the now-obsolete 'metricThreshold' property.
  • Test Stability: The new assertion logic prevents test timeouts caused by counter mismatches during Dataflow worker downscaling, ensuring more robust load test results.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the SpannerToSourceDbLargeBacklogLT load test to poll the row count of the shadow table in the metadata database instead of relying on the unreliable success_record_count Dataflow metric. It also defines a default shadow table prefix constant in SpannerToSourceDbOptions. The feedback suggests changing the exact equality check (==) for the shadow table row count to a greater-than-or-equal-to check (>=) to prevent the test from failing or timing out due to duplicate writes or retries.

…/v2/templates/SpannerToSourceDbLargeBacklogLT.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@bharadwaj-aditya bharadwaj-aditya 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.

LGTM

@aasthabharill
aasthabharill merged commit 5260a44 into main Nov 5, 2026
26 checks passed
@aasthabharill
aasthabharill deleted the lt-backlog-shadow-count branch November 5, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants