vreplication: fix OOM on tables with large JSON columns (#19878)#869
Draft
pedroalb wants to merge 4 commits into
Draft
vreplication: fix OOM on tables with large JSON columns (#19878)#869pedroalb wants to merge 4 commits into
pedroalb wants to merge 4 commits into
Conversation
|
Thanks for the contribution! Before we can merge this, we need @nickvanw to sign the Salesforce Inc. Contributor License Agreement. |
Signed-off-by: Nick Van Wiggeren <nick@planetscale.com> Signed-off-by: Arthur Schreiber <arthur@planetscale.com> Co-authored-by: Arthur Schreiber <arthur@planetscale.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9191813 to
c0689d2
Compare
ejortegau
previously approved these changes
Jun 9, 2026
The cherry-pick of vitessio#19878 added maxQuerySize() calls in the copy phase. The tabletmanager test framework uses a strict mock DB client that didn't expect this query, causing test failures.
Take the upstream refactor instead of keeping our inline version. One implementation in maxQuerySize(), used by both vplayer and vcopier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of vitessio#19878 to
slack-22.0.Fixes two compounding issues in VReplication when processing tables with large JSON columns:
Unbounded SQL buffer in copy phase:
applyBulkInsertbuilt one giant SQL INSERT with ALL rows in a single statement, no size limit. With large JSON columns, this could produce a statement exceedingmax_allowed_packetor exhausting memory.56x memory amplification in JSON encoding:
vjson.MarshalSQLValue()converted binary JSON into SQL via an intermediate Go object tree. Fix replaces withvjson.AppendMarshalSQL()which streams token-by-token (~8x memory instead of 56x).What changes in VReplication behavior
No semantic change -- same rows get inserted, same data arrives at the target.
vcopier.go): Each copy worker now queriesmax_allowed_packetand splits bulk INSERTs when the statement buffer exceeds that size. Same batch of rows, multiple smaller INSERT statements instead of one unbounded one.replicator_plan.go):applyBulkInserttracks buffer size as it appends rows. When buffer exceedsmaxQuerySize, it flushes and starts a new INSERT. AccumulatesRowsAffectedacross flushes.applyBulkInsertChangesadds!newStmtguard to prevent flushing on the first row of a new statement.marshal.go):vjson.AppendMarshalSQL(buf, raw)streams JSON directly into the buffer instead of building an intermediate object tree.maxAllowedPacketlogic replaced with sharedvr.maxQuerySize()(one implementation for both copy and replay paths).Why we need this
We need this backport to safely perform reshards on keyspaces with tables containing large JSON columns. Without this fix, VDiff and VReplication can cause OOM or severe memory/CPU pressure on target primaries during the comparison and copy phases.
Related Issue(s)
Checklist
Test Plan
stepsandexecution_datacolumns with 1-5 MB JSON documents)Deployment Notes
Deploy with next vttablet build from
slack-22.0. No migrations required.AI Disclosure
Cherry-pick and conflict resolution performed with Claude Code assistance.