← Back to Pull requests

MDEV-42539 UPDATE of a CSV row to over 2 GB fails with Errcode 14, and the row is lost #6267

Open
unknown opened this pull request with 315 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 28, 2026 19:54 UTC
Author

  • The Jira issue number for this PR is: MDEV-42539
  • Description


    While looking into this, I found that there are actually two problems behind the lost row.

    The first one is the one in the report: encode_quote() returns the row length as an int, and write_row() / update_row() keep it in an int before passing it to mysql_file_write(). Once a row goes over 2 GB the length turns negative, and the write fails with EFAULT.

    The second one is why the row actually disappears. update_row() calls chain_append() (which marks the old row as deleted) before writing the new row. So if the write fails for any reason, not just a 2 GB row but also something like a full disk, the old row stays marked as deleted and rnd_end() leaves it out of the new data file. If the write fails halfway, part of the new row is also left in the .CSN file, and the remaining rows get appended right after it.

    What I changed:

  • encode_quote() now returns size_t, and the buffer size is calculated in size_t. If it fails (it returns 0), both callers now return HA_ERR_OUT_OF_MEM instead of silently writing nothing.

  • update_row() now writes the new row first and only then marks the old one as deleted. If the write fails, the temp file is truncated back to temp_file_length, so the old row is kept and no partial row is left behind.
  • How can this PR be tested?


    I added two tests to the csv suite:

  • csv.csv_update_failed_write (debug builds): uses a new DBUG keyword, csv_update_row_partial_write, to make the row write fail halfway through. With the fix, all rows are still there, CHECK TABLE says OK, and a later UPDATE works fine. To make sure the test really catches the bug, I also ran it with the old order of chain_append() restored. The row went missing and CHECK TABLE reported the table as corrupt, same as in the Jira report.

  • csv.csv_update_large_row (--big-test): the exact 2 GB UPDATE from the report. It passes now; on my debug build it took about 5.5 minutes and needs a few GB of RAM and disk.
  • The rest of the csv suite also passes.

    Basing the PR against the correct MariaDB version


  • This is a new feature and the PR is based against the latest MariaDB development branch

  • This is a bug fix and the PR is based against the earliest branch in which the bug can be reproduced
  • Backward compatibility


    The CSV file format doesn't change. The only behaviour changes are that a failed UPDATE no longer loses the row, and rows over 2 GB can now be written.

    Diff: 315 lines (+236 / -79) across 3 files Reviewer: gkodinov Review duration: 3502m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 315 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.344
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6267"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.5% · Safe to merge
    21.5%
    Repository