MDEV-42539 UPDATE of a CSV row to over 2 GB fails with Errcode 14, and the row is lost #6267
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
gkodinov
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 anint, andwrite_row()/update_row()keep it in anintbefore passing it tomysql_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()callschain_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 andrnd_end()leaves it out of the new data file. If the write fails halfway, part of the new row is also left in the.CSNfile, and the remaining rows get appended right after it.What I changed:
encode_quote()now returnssize_t, and the buffer size is calculated insize_t. If it fails (it returns 0), both callers now returnHA_ERR_OUT_OF_MEMinstead 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 totemp_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
csvsuite: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 ofchain_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
csvsuite also passes.Basing the PR against the correct MariaDB version
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.