Repository navigation
vtgate: retry buffered queries on a recovered primary - #22169
ZainnQureshii wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Zain Qureshi <43629888+ZainnQureshii@users.noreply.github.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
|
There was a problem hiding this comment.
🟡 Changes recommended
The test can pass without exercising the fix because a health-update race may buffer the query before it reaches the old primary; it must synchronize with shutdown and verify the initial tablet-side CLUSTER_EVENT rejection.
1 open issue
What changed in this PR
Fixes #21395 by allowing buffered VTGate queries to retry the same primary after a failed reparent restores it to service.
Changes:
- Clear request-local tablet exclusions when buffering releases a query for retry.
- Add gateway and end-to-end regressions for recovery of the original primary.
- Support tablet argument overrides in the test helper and include the new test package in CI.
| File | Description |
|---|---|
test/config.json |
Adds the buffer package to the reparent CI suite. |
go/vt/vtgate/tabletgateway.go |
Clears tablet exclusions after buffering. |
go/vt/vtgate/tabletgateway_flaky_test.go |
Tests retrying the same primary after recovery. |
go/test/endtoend/tabletgateway/buffer/reparent_rollback_test.go |
Adds a failed-reparent cluster regression. |
go/test/endtoend/tabletgateway/buffer/buffer_test_helpers.go |
Allows per-test tablet argument overrides. |
Review effort: Balanced
| result, queryErr = conn.ExecuteFetch("select id from buffer where id = 1", 1, false) | ||
| buffered, _ := cluster.VtgateProcess.GetVars()["BufferRequestsBuffered"].(map[string]any) | ||
| return queryErr != nil || buffered[statsLabel] == float64(1) |
There was a problem hiding this comment.
Fair point that buffered == 1 on its own doesn't prove the query reached the old primary first, but I don't think that race can realistically happen in this test, so I've left it as is. The old primary only reports itself as not serving on the 20s health tick or once unserveCommon finishes and setState broadcasts (go/vt/vttablet/tabletserver/state_manager.go:510 and :752), and that drain is held up by the open transaction, while the test sends the SELECT every 100ms from the moment PRS starts. A false pass would need a 20s tick to land inside the single 100ms gap after the tablet starts shutting down. The run against main without the fix also failed on the tablet's own rejection, operation not allowed in state SHUTTING_DOWN with code 17 (CLUSTER_EVENT), which is the initial rejection this asks to verify, and the gateway unit test covers the same path deterministically. I can tighten the polling if a maintainer would rather have that.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22169 +/- ##
===========================================
+ Coverage 69.67% 85.31% +15.64%
===========================================
Files 1614 310 -1304
Lines 216793 48199 -168594
===========================================
- Hits 151044 41122 -109922
+ Misses 65749 7077 -58672
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|

Description
With VTGate buffering enabled, an in-flight primary query can reach the old primary during
PlannedReparentShardand receiveCLUSTER_EVENTwhile the tablet is shutting down. Onmain, VTGate records that alias in the request's exclusion map (go/vt/vtgate/tabletgateway.go:449). When demotion fails and the same primary resumes serving, the candidate filter still drops it (go/vt/vtgate/tabletgateway.go:466), and the MySQL client receives the originalSHUTTING_DOWNerror.Clear the request's tablet exclusions when the buffer hands back a retry callback (
go/vt/vtgate/tabletgateway.go:385). VTGate then selects from current health data (go/vt/vtgate/tabletgateway.go:396), so the recovered primary can serve the retry.The gateway wrapper at
go/vt/vtgate/tabletgateway.go:157leads to the sole production call toWaitForFailoverEnd. Both balancer paths share its candidate filter. The other references exercise the buffer directly in tests and benchmarks, outside the gateway's exclusion map. Direct-by-alias calls use a specified tablet and the shard-error wrapper (go/vt/vtgate/tabletgateway.go:236).Motivation
How do you use Vitess?
Did you run this change against a real Vitess deployment? Yes. A local Linux/arm64 cluster used MySQL 8.4.11, etcd 3.6.7, a primary and replica, and VTGate with buffering enabled. A MySQL table lock made
PlannedReparentShardtime out settingsuper_read_onlyin both runs. With base VTGate the bufferedSELECTreturnedSHUTTING_DOWN(errno 1105). With patched VTGate the query returned the expected row after the original primary resumed serving.Both regressions were adapted from mhamza15's reproductions. The gateway test synchronizes the initial health events and checks both attempts against the same tablet (
go/vt/vtgate/tabletgateway_flaky_test.go:274). The cluster test checks that the request entered and left the buffer and received the expected row (go/test/endtoend/tabletgateway/buffer/reparent_rollback_test.go:75). Issue #21395With the Vitess binaries, MySQL, and etcd configured, the cluster test was built and run with:
The gateway regression failed on the base code with
CLUSTER_EVENTafter the buffer drained and passed 100 runs with the fix. The package and style checks passed locally with Go 1.27.4 and golangci-lint 2.15.0.Related Issue(s)
Fixes #21395
Checklist
Deployment Notes
No migration or configuration changes are required.
AI Disclosure
Codex wrote the code change, adapted the tests, ran verification, and drafted this description. Claude Code coordinated the investigation and review.
Prepared with AI assistance (Codex and Claude Code) and reviewed with GitHub Copilot.
🤖 Generated with Claude Code