Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues. (searched "load data parallel strict", "load data parallel lines terminated", "load data parallel wrong count", "load data parallel lost rows" — no match)
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters: Apple M-series laptop (standalone)
- OS type: darwin (macOS, arm64)
- Others: single-process mo-service launched via `./mo-service -launch`, MySQL client 9.7.1Actual Behavior
LOAD DATA ... PARALLEL 'true' STRICT 'false' on a CSV whose records are delimited by a multi-byte LINES TERMINATED BY '||' and whose field data contains embedded \n bytes silently imports corrupted rows and loses source records.
With a 587,202,702-byte file containing 2,691,438 records (each record i,<filler with an embedded \n>,v<i>||), GetExternParallelSize picks 4 workers, so 3 interior byte-offset split points are computed. All 3 land mid-record because the split logic (getTailSizeNoStrict) advances to the next raw \n instead of the configured line terminator. Each record crossed by a split point is turned into two garbage rows (a truncated tail row from worker 1 and a mis-aligned head row from worker 2), while the original record is never stored.
Observed (4 runs, identical every time):
| load variant | rows | sum(length(b)) | count(distinct a) | rows with c NULL |
|---|---|---|---|---|
| serial (reference) | 2691438 | 538287600 | 2691438 | 0 |
PARALLEL 'true' (default STRICT option) |
2691438 | 538287600 | 2691438 | 0 |
PARALLEL 'true' STRICT 'false', sql_mode='' |
2691441 | 538287326 | 2691439 | 6 |
PARALLEL 'true' STRICT 'false', default (strict) sql_mode |
aborted: ERROR 20301: invalid input: the data of row 1 contained is not equal to input columns |
Anomaly probes on the corrupted table returned bad_a = 3 rows where column a is not numeric (it contains filler fragments), bad_c = 6 rows with c NULL or not matching v[0-9]+.
No error or warning is produced in the sql_mode='' case — the corruption is completely silent. With the default (strict) sql_mode the same statement is rejected, so a file that loads perfectly in serial mode fails or corrupts depending only on sql_mode.
Expected Behavior
The file is fully valid per the statement's FIELDS/LINES options: every record is terminated by ||, the \n bytes are data inside field b. Both MySQL 8.0 semantics and MatrixOne's own serial/STRICT 'true' parallel paths load it exactly:
- serial: 2691438 rows, sum(length(b)) = 538287600, 0 NULLs
PARALLEL 'true'with default STRICT option: identical to serial
Therefore PARALLEL 'true' STRICT 'false' must produce the same 2691438 rows. In no case should a worker start parsing mid-record: split points must be advanced to a record boundary of the configured line terminator, not to the next raw \n.
Steps to Reproduce
- Generate the input (needs to be > 512MiB so
GetExternParallelSizeselects >= 4 workers; each record embeds a real\ninside field b):
filler_a = b"y" * 100
filler_b = b"y" * 99
with open("big_term3.csv", "wb") as f:
i, total, buf = 0, 0, []
while total < 560 * 1024 * 1024:
rec = f"{i},".encode() + filler_a + b"\n" + filler_b + f",v{i}||".encode()
buf.append(rec); total += len(rec); i += 1
if len(buf) > 10000:
f.write(b"".join(buf)); buf = []
if buf:
f.write(b"".join(buf))
# -> 2691438 records, 587202702 bytes- Run (server-side paths; use an absolute path for the file):
CREATE DATABASE IF NOT EXISTS loadtest;
USE loadtest;
-- reference: serial
CREATE TABLE t3s (a varchar(50), b varchar(300), c varchar(50));
LOAD DATA INFILE '/abs/path/big_term3.csv' INTO TABLE t3s FIELDS TERMINATED BY ',' LINES TERMINATED BY '||';
SELECT count(*), sum(length(b)), count(distinct a), count(*)-count(c) FROM t3s;
-- 2691438 538287600 2691438 0
-- control: parallel, default STRICT option -> correct
CREATE TABLE t3c (a varchar(50), b varchar(300), c varchar(50));
LOAD DATA INFILE '/abs/path/big_term3.csv' INTO TABLE t3c FIELDS TERMINATED BY ',' LINES TERMINATED BY '||' PARALLEL 'true';
SELECT count(*), sum(length(b)), count(distinct a), count(*)-count(c) FROM t3c;
-- 2691438 538287600 2691438 0
-- bug: parallel + STRICT 'false'
SET sql_mode='';
CREATE TABLE t3p1 (a varchar(50), b varchar(300), c varchar(50));
LOAD DATA INFILE '/abs/path/big_term3.csv' INTO TABLE t3p1 FIELDS TERMINATED BY ',' LINES TERMINATED BY '||' PARALLEL 'true' STRICT 'false';
SELECT count(*), sum(length(b)), count(distinct a), count(*)-count(c) FROM t3p1;
-- 2691441 538287326 2691439 6 <-- 3 extra garbage rows, 6 c-NULL rows, data silently wrong
SELECT count(*) FROM t3p1 WHERE a NOT REGEXP '^[0-9]+$';
-- 3
SET sql_mode = default;
-- same statement under default (strict) sql_mode: rejected outright
CREATE TABLE t3p2 (a varchar(50), b varchar(300), c varchar(50));
LOAD DATA INFILE '/abs/path/big_term3.csv' INTO TABLE t3p2 FIELDS TERMINATED BY ',' LINES TERMINATED BY '||' PARALLEL 'true' STRICT 'false';
-- ERROR 20301 (HY000): invalid input: the data of row 1 contained is not equal to input columnsReproduced 4/4 times with identical corrupted numbers (deterministic, since offsets are computed from file size once).
Additional information
Root cause: the parallel byte-offset split path used when the statement's STRICT option is 'false' advances each interior boundary to the next raw \n:
pkg/sql/colexec/external/external.go,ReadFileOffset(line 665): for each of themcpu-1interior boundaries computesoffsets[i-1]+batchSizeand opens the file at that raw byte position.pkg/sql/colexec/external/external.go,getTailSize(line 724): dispatches onparam.Strict; when false,getTailSizeNoStrict(line 732) returnsbufio.Reader.ReadString('\n')length — it ignoresparam.Tail.Fields/Linesentirely (LINES TERMINATED BY '||'in this repro) and also cannot handle quoted multi-line fields in general.- When the configured line terminator is not
\nand records contain\nas data, every boundary lands mid-record; worker 1 ends on a truncated record and each subsequent worker starts mid-record, so the boundary-crossed record is replaced by two fragment rows (seebad_a/c-NULL probes). Under strict sql_mode the fragment rows failcheckLineValidRestrictiveand abort the whole statement instead.
The STRICT 'true' path (getTailSizeStrict) does the right thing: it re-parses with the real CSV configuration until a legal record boundary and moves splits there, which is why the same file is loaded bit-exact under PARALLEL 'true' with the default STRICT option. getTailSizeNoStrict should apply the same (or equivalent terminator-aware) scan; the raw ReadString('\n') shortcut is only sound when LINES TERMINATED BY is exactly \n and no field embeds a newline.
Note STRICT/PARALLEL 'true' are both accepted grammar options of MatrixOne's extended LOAD DATA syntax (strict_opt/parallel_opt in pkg/sql/parsers/dialect/mysql/mysql_sql.y), so the combination is first-class syntax, not an unused corner.
Scale notes: GetExternParallelSize = fileSize / (128*1024*1024) workers (capped by CPU count), and applyLoadParallelAdmission requires the file to be >= 128MiB, so the repro file must be > 512MiB for 4 workers / 3 interior boundaries; any embedded \n inside a field data then triggers the issue.
Found by Loom bug hunt (module: custom-a9872c7d6e; tests: unit, white-box, end-to-end)
Activity
fix(load): honor line terminators in parallel file splits (#30364)
test(external): bind file access policy in boundary fixtures (#30439)
XuPeng-SH commentedon Oct 17, 2026
补充独立转测证据:main
aa4b6eddfdad54d11be6fd75a5675eb9801f6690使用 272,175,894 字节的真实本地 CSV(17,000 条记录、每条 16,000 字节含 LF 的字段、记录分隔符 ||),跨过 256 MiB 规模边界。串行、严格并行、非严格并行空 sql_mode、非严格并行默认 sql_mode 四种 LOAD 实际全部通过。每种模式均断言:17,000 行、17,000 个不同 ID、payload 总字节 272,000,000、错误/NULL 尾字段数 0、ID 总和 144,508,500。分隔符/probe 所有权定向 UT 也通过。继续保留当前测试负责人 Ariznawlll,供目标版本验收。
Ariznawlll commentedon Oct 19, 2026
测试版本
def799e1260dd547cae2e0e54323ea20ec1b7685;修复 PR #30364 已 MERGED,merge commit7387b96afd3f996379e2ff48faeace9e1790fc35已确认是该 main 的祖先。原问题验证
严格按 issue 的生成方式创建
587,202,702字节、2,691,438条记录的 CSV;每条记录的字段内含真实换行,记录分隔符为||。这是原报告的完整规模,而非低于并行分割阈值的小样本。修复前的非严格并行路径在此规模曾得到2,691,441行、6个 NULL 尾字段;本轮在上述 main 上没有复现该错值。Happy Path 覆盖
同一原始文件分别执行串行参考、
PARALLEL 'true'严格参考,以及PARALLEL 'true' STRICT 'false'的空sql_mode和默认sql_mode。直接产品验证共 8 次导入(串行 1、严格并行 1、非严格两种模式各 3);每次实际值均为:count(*)=2691438、sum(length(b))=538287600、count(distinct a)=2691438、count(*)-count(c)=0。Unhappy Path 覆盖
每次导入还查询了非数字 ID、尾字段为 NULL 或不匹配
^v[0-9]+$的行数,实际均为0;默认严格sql_mode下原先会因跨 worker 错切而报ERROR 20301,本轮 3/3 正常导入。每个变体完成后删除表,退出时删除测试数据库;MOTR 场景还在finally清理数据库,并以临时目录管理输入文件。未声称覆盖外部网络故障或分布式多 CN 拓扑,这两项不属于原复现门槛。白盒验证
核对修复 PR #30364 的合入状态及 merge commit 已进入上述官方 main,并以实际超过 560 MiB 的输入触发原
GetExternParallelSize4 worker 路径。没有用降低阈值、减少数据量或产品错值生成预期结果。回归测试
已在 MOTR 汇总 PR #247 新增 opt-in 大数据场景
script/14_issue_regression/issue_30341_parallel_lines_full_scale.py及配对的script/14_issue_regression/out/issue_30341_parallel_lines_full_scale.out,PR head69c23699c72195276809b4386ca3e65385247bf9。场景须显式设置MOTR_BIG_DATA_TESTS=1和MOTR_LOAD_DATA_LOCAL_SERVICE=1,未具备同机文件可见性时明确 skip,不记为通过。定向运行--repeat 3:3/3 PASS、0 fail、0 skip;每轮独立生成原规模输入并完成 8 种导入/校验,合计 24 次导入。PR 尚未合入;完整 suite 与集成 CI 尚未执行,离线检查在提交时仍运行中,将继续跟踪。测试证据
587202702字节 /2691438条记录;正确 oracle 为(2691438,538287600,2691438,0);所有非数字 ID、NULL/畸形尾字段探针均为0。20.2s/轮,总计约60.6s。def799e1260dd547cae2e0e54323ea20ec1b7685;修复 PR fix(load): honor line terminators in parallel file splits #30364 merge commit7387b96afd3f996379e2ff48faeace9e1790fc35;MOTR PR select without from clause is not supported #247 head69c23699c72195276809b4386ca3e65385247bf9。测试结论
测试通过。