Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Checked in particular: #30511 (parallel LOAD boundary probe slowness on COS) — different root cause: that probe found its boundary and the cost was the QCloudSDK Close() draining the unread remote response; this bug is the strict probe loop itself CSV-parsing the whole tail locally and emitting a moerr ERROR log per row, on a local file with no object store involved. #30341 (STRICT 'false' corrupts rows with non-'\n' LINES TERMINATED BY) and #30329 (CSV reader loses records) are split-correctness issues. #30411 is about duplicate primary keys. None covers the plan-time legality scan storm below.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters: Apple M-series 10-core CPU, 16GB RAM
- OS type: macOS 15 (darwin, arm64)
- Others: single-node all-in-one
mo-service(launch config: 1 CN + 1 DN + logservice). Input is a plain local uncompressed CSV, 300MiB, 7,275,139 data rows, 4 comma-separated fields with 1 header line, defaultsql_mode(STRICT_TRANS_TABLESon).
Actual Behavior
Planning a LOAD DATA ... PARALLEL 'true' whose file-size admits 2+ byte-offset shards makes the planner find split boundaries with a strict-mode legality probe (ReadFileOffset -> getTailSizeStrict, pkg/sql/colexec/external/external.go:1010). The probe loop has no upper bound on how many records it may scan and no context-cancellation check. When every record from the probe point on fails isLegalLine (here: the column list (c1,c2,c3) maps the file's 3rd field, st... strings, onto c3 DECIMAL(12,2), and 4 fields != 3 columns), it parses record after record until EOF. Every failing row constructs a moerr.InvalidInput via types.ParseDecimal64 (pkg/container/types/decimal.go:2141) whose reporting hook (errutil.WithContextWithDepth -> GetReportErrorFunc(), pkg/util/errutil/context.go:52) writes a leveled ERROR log line with captured stack — roughly one ERROR log line per scanned row.
Measured on the 300MiB repro (probe starts near the file's mid-point, ~3.6M rows in its tail):
- A natural-completion run (client left connected): 505s wall clock (
statement_info: status=Failed, duration=505,336,214,583ns), +1,455,103,534 bytes (1.46GB) of mo-service log, 3,624,770 ERROR storm lines — almost exactly one ERROR line per record from the probe start to EOF. The error finally returned to the client is the same row-1 error the non-parallel load returns in 47ms (ERROR 20301 (HY000): invalid input: the data of row 1 contained is not equal to input columns, ~10,700x slower), and the table stays empty (rollback). - mo-service log grows at a steady ~2.9-4.3MB/s — all
"level":"ERROR"lines like{..."caller":"types/decimal.go:2141",..."msg":"error: invalid input: st00000000000003650370 beyond the range, can't be converted to Decimal64(12,2)."}. - The statement is stalled inside query planning that whole time (
compileExternScanParallelReadWrite->ReadFileOffset, and the "compileExternScanParallelReadWrite" INFO log only prints when the probe finally returns). - The probe loop never checks
ctx.Err(): killing the mysql client at ~130s did not stop the storm — logs kept growing +471MB over the following 120s, and the server kept burning CPU until the probe hit EOF minutes later (that killed-client run recorded duration=394,607,268,000ns, error "context canceled"). The non-strict boundary scanner already has the right pattern (boundaryContextReaderchecks ctx per Read, external.go:965-977) — the strict path lacks it. - After the probe exhausts the file,
ReadFileOffsetfalls back to a single range ([offset:N, offset:-1], mcpu collapses to 1 shard) and the real scan fails in milliseconds at row 1 — so the entire multi-minute/GB-log cost bought nothing: no row was ever insertable. - The same file loads fine (2 shards, 2.1s) when the column list matches the file, and single-shard sizes (<256MiB, mcpu=1) never enter the probe loop, which is why this escapes typical small-fixture tests.
Expected Behavior
- The load should fail fast with the row-1 error, like the serial path (47ms) and like MySQL 8.0.46, which reports
Incorrect decimal value: 'st00000000000000000000' for column 'c3' at row 1for the same file and statement in 47ms. - A plan-time probe must be bounded: a small capped scan window (or immediate demotion to the non-strict boundary scan / single range) instead of scanning to EOF.
- Probe-time parse failures are expected control-flow events, not service errors: they must not emit a per-row ERROR log with stack capture (MO already has
moerr.NoReportContext()documented exactly for "errors that are expected in retry loops or high-frequency paths"). - Killing the client must cancel the planning probe.
Steps to Reproduce
# 1) 300MiB CSV, header + 4 fields: id, c1, <st-padded-string>, decimal-looking text
python3 - <<'EOF'
p = "/tmp/probe_storm.csv"
with open(p, "w") as f:
f.write("id,c1,c2,c3\n")
for i in range(7_275_138):
f.write(f"{i},{i%100},st{i:020d},{(i%100000)/100:.2f}\n")
EOF
# ls -lh -> ~300MiB (must be >= 256MiB so the plan admits 2 shards, else the
# probe loop body never runs and the bug cannot trigger)
# 2) Table + control: the same input without PARALLEL fails at row 1 in ~50ms
mysql <mo-host:port> -e "use <db>;
create table tc3a (c1 int, c2 varchar(64), c3 decimal(12,2));
load data infile '/tmp/probe_storm.csv' into table tc3a
fields terminated by ',' lines terminated by '\n' ignore 1 lines
(c1,c2,c3) parallel 'false';"
# -> ERROR 20301 (HY000): invalid input: the data of row 1 contained is not equal to input columns
# 3) The bug: identical statement with PARALLEL 'true'
S=$(date +%s); B=$(wc -c < <mo-service-log>); N=$(grep -c 'beyond the range' <mo-service-log>)
mysql <mo-host:port> -e "use <db>;
load data infile '/tmp/probe_storm.csv' into table tc3a
fields terminated by ',' lines terminated by '\n' ignore 1 lines
(c1,c2,c3) parallel 'true';"
E=$(date +%s); A=$(wc -c < <mo-service-log>); M=$(grep -c 'beyond the range' <mo-service-log>)
echo "wall=$((E-S))s log_delta=$((A-B))B storm_lines=$((M-N))"Observed (300MiB, 10-core arm64): wall ~400-500s, log_delta ~1.3GB, storm_lines ~3.6M; tail -f the mo-service log shows thousands of "level":"ERROR"...beyond the range, can't be converted to Decimal64(12,2). lines per second for minutes; the plan only completes (compileExternScanParallelReadWrite INFO log finally printed) when the probe reaches EOF and falls back to one range [offset:N, offset:-1]. Table stays empty (statement rolls back). select status, duration, error from statement_info where statement like '%tc3a%' order by request_at desc limit 1 shows the duration above.
Additional information
- Root cause is two-fold, both plan-time: (1) an unbounded, cancellation-blind scan loop in
getTailSizeStrict(external.go:1010:for { csvReader.Read; ...; isLegalLine(...) }— no cap, no ctx check,continueon every illegal record); (2) an error-construction API that logs per call: probe-only parse failures go throughtypes.ParseDecimal64->moerr.NewInvalidInputNoCtxf->errutil.WithContextWithDepth-> ERROR report with stack (decimal.go:2141, errutil/context.go:52). MySQL-semantics note: MO treatslen(fields) < len(cols)rows as "keep scanning" (external.go:1044continue), so any file whose rows never satisfy the column-map keeps the probe spinning to EOF. - Fix directions: cap the strict probe (bytes/rows scanned, e.g. fall back to the existing non-strict boundary scan or a single range past the cap); check
ctx.Err()each iteration (mirroringboundaryContextReader, external.go:965-977); construct probe-time parse errors withmoerr.NoReportContext()(error.go:1954) or a non-logging comparison so per-row legality tests don't write ERROR logs; optionally fail fast: in strict mode the row-level check (checkLineValidRestrictive, external.go:1382) would reject row 1 anyway, so probing can stop at the first illegal record instead of skipping it. - Non-strict control (same server/file,
set sql_mode=''): the non-strict boundary scan returns in <1s with ~43KB of log growth, and the load then fails at shard 2's first row — confirming the storm is specific to the strict legality probe. A statement variant without the explicit FIELDS/LINES tail clauses also bypasses the storm in this build (probe returns instantly), so the exact statement text in Step 3 above matters for reproduction. - Operational impact: one bad file can add ~4.3GB/hour of ERROR logs per planning probe and pin a CPU core for minutes before the statement fails; the response to the user is a generic row-1 error, so the operator sees a "fast-fail" error but the server melts; log flooding at ERROR level also drowns real errors. For 2 shards there is 1 probe; a 21.7GB COS file plans ~9 probes sequentially, so a file-wide-illegal CSV multiplies the tail scan (and log volume) accordingly.
- Related (distinct root causes, checked): [Bug]: Parallel COS LOAD boundary probes drain file tails on Close after #30364 (1.8s -> 561s) #30511 COS Close-drain during probes; [Bug]: parallel LOAD DATA with STRICT 'false' silently imports corrupted rows when LINES TERMINATED BY is not '\n' #30341 non-strict split with custom LINES TERMINATED BY; [Bug]: CSV readers lose records or ignore enclosure and line-terminator semantics #30329 CSV record semantics; [Bug]: LOAD DATA inserts duplicate primary keys without error #30411 duplicate PKs in parallel LOAD.
Full reproduction, exactly as Loom ran it
#!/bin/bash
# MatrixOne parallel LOAD DATA plan-probe scan storm - minimal reproduction.
# Adjust MO (mysql client + mo-service port), DATA, LOG (mo-service log path).
set -u
MO=(mysql -h 127.0.0.1 -P <mo-mysql-port> -uroot -p<pass>)
DATA=/tmp/probe_storm.csv
LOG=<mo-service.log>
# 1) >=256MiB CSV (below 256MiB the plan computes mcpu=1 and the probe loop
# body never executes): header + 4 fields; every data row is illegal for the
# target below (string in decimal position + field count != column count).
python3 - "$DATA" <<'EOF'
import sys
p = sys.argv[1]
with open(p, "w") as f:
f.write("id,c1,c2,c3\n")
for i in range(7_275_138):
f.write(f"{i},{i%100},st{i:020d},{(i%100000)/100:.2f}\n")
EOF
ls -lh "$DATA" # ~300MiB
# 2) target table
"${MO[@]}" -e "drop database if exists probe; create database probe;"
"${MO[@]}" -e "use probe; create table tc3a (c1 int, c2 varchar(64), c3 decimal(12,2));"
# 3) serial control: same file, same misaligned column list, no parallelism
# -> row-1 error within ~50ms, no log growth
"${MO[@]}" -e "use probe; load data infile '$DATA' into table tc3a fields terminated by ',' lines terminated by '\\n' ignore 1 lines (c1,c2,c3) parallel 'false';"
# ERROR 20301 (HY000): invalid input: the data of row 1 contained is not equal to input columns
# 4) the bug: identical statement with parallel 'true'
S=$(date +%s); LB=$(wc -c < "$LOG"); LN=$(grep -c 'beyond the range' "$LOG")
"${MO[@]}" -e "use probe; load data infile '$DATA' into table tc3a fields terminated by ',' lines terminated by '\\n' ignore 1 lines (c1,c2,c3) parallel 'true';"
EC=$?; E=$(date +%s); LA=$(wc -c < "$LOG"); LC=$(grep -c 'beyond the range' "$LOG")
echo "exit=$EC wall=$((E-S))s log_delta_bytes=$((LA-LB)) storm_lines=$((LC-LN))"
# While step 4 hangs, in another terminal:
# tail -f "$LOG" # thousands per second of:
# {"level":"ERROR",..."caller":"types/decimal.go:2141",..."msg":"error: invalid input: st0000000000000365.... beyond the range, can't be converted to Decimal64(12,2)."}
# The compile log that prints after the probe gives the fallback: a single
# range like [offset:N offset:-1] (mcpu collapses to 1 shard).
# 5) post-mortem: nothing was inserted; statement_info carries the duration
"${MO[@]}" -e "use probe; select count(*) from tc3a;"
"${MO[@]}" -e "use system; select status, duration, error from statement_info where statement like '%tc3a%' order by request_at desc limit 1;"
# Expected (single-node, 10-core arm64, 300MiB step-4): exit=1,
# wall ~400-500s, log_delta ~1.3GB, storm_lines ~3.6M, count(*)=0,
# duration ~4e11ns, error = row-1 error (or context canceled if the client was killed).Found by Loom bug hunt (module: custom-82082add71; tests: white-box, black-box, concurrency; severity: S0)
Activity
iamlinjunhong commentedon Oct 28, 2026
Human-confirmed change risks after #31387
Reviewed merge commit:
ee9b2d2.The following code-review concerns were confirmed for follow-up by the user. They are not a claim that the original issue still reproduces, or that a local benchmark was run. Evidence is quoted in its original language.
performance
external.go:1043/:1087及:774:大合法CSV若探测位置到下一安全候选的距离超过256KiB,会放弃边界并合并整个剩余尾部;首次探测失败可使多reader退为一个有效reader,显著降低长记录文件的潜在导入吞吐。这是PR已说明、issue允许的有界性取舍,未做性能对比。
This issue is being returned to Loom's candidate list for follow-up. The PR remains merged.
fix(load): preserve safe parallel splits for long CSV records (#31515)
XuPeng-SH commentedon Oct 28, 2026
QA update: merged #31515 (
9c8d405b1ee2303474aec513fc16cdf2375089a2, in main3cf38889bca2d183e973e78b1288f8c704727542) changes the previous 256 KiB split-probe limit and adds bounded probing and exact prefix validation. The earlier developer follow-up is #31326 (comment). The new implementation still has a hard probe budget and can reduce fanout for distant boundaries or many short records; no controlled throughput comparison was run here. I have not run the component, cancellation, or live CSV tests at this SHA due to the isolated resource guard. Please confirm whether the earlier performance follow-up is fully resolved; the existing developer assignment is retained.slyunnn commentedon Oct 30, 2026
Regression and extended verification for #31326 (2026-10-30)
Verification Environment
origin/maincommitd39d8a40343ccd40bf665036388df7a40ee867f8— tae: flush eligible AObject prefixes before busy tails (tae: flush eligible AObject prefixes before busy tails #31723).mo-servicewas built from this commit withmake build; binarySHA2562c16af1e4dd7afb194211233be625af96ebaaba588d2ddd944cfaf3476cb43fe, tracked source diff empty.origin/main: fix(load): bound strict CSV boundary probes #31387 fix(load): bound strict CSV boundary probes (mergeee9b2d2a3a1a83b15e5658b69c822300539e415b) and fix(load): preserve safe parallel splits for long CSV records #31515 fix(load): preserve safe parallel splits for long CSV records (merge9c8d405b1ee2303474aec513fc16cdf2375089a2).2 CN/1 TN/1 Log service/Proxy, fresh data directory. Proxy127.0.0.1:6001, CN1127.0.0.1:16001, CN2127.0.0.1:16002; all three accepted connections and reported8.0.30-MatrixOne-v1.3.0.mysqlCLI, server-sideLOAD DATA INFILEagainst the local ETL fileservice. The original statement was executed through Proxy6001, then repeated directly on CN116001and CN216002.probe_storm.csv,295,639,040bytes (281.9 MiB),7,275,138rows,SHA256c7e49e8dc2a2360d563e76fb4150f863f30db36a2a66e7996f0a46acb98af4c1— header plus 4 fields, misaligned column list(c1,c2,c3)forc3 DECIMAL(12,2), exactly the issue's reproducer.505swall,+1,455,103,534bytes ofmo-servicelog,3,624,770ERROR lines.What Was Covered
16001:parallel 'false'returnedERROR 20301 (HY000): invalid input: the data of row 1 contained is not equal to input columnsin0.037s, log growth4,828bytes,0matchingbeyond the rangelines.6001: identical statement withparallel 'true'returned the sameERROR 20301in0.037swith5,497bytes of log growth and0beyond the rangelines, versus505s/+1.46GB/3.6MERROR lines reported pre-fix.16001(0.037s,ERROR 20301,5,223bytes) and CN216002(0.038s,ERROR 20301,5,403bytes); no endpoint-specific difference.FIELDS/LINEStail clauses through Proxy6001:0.041s,ERROR 20301,5,334bytes,0matching lines.[offset:12 offset:-1 ], and[offset:0 offset:-1 ]for the CN2 run) instead of scanning to EOF; the legal file keeps two ranges ([offset:12 offset:147819580 offset:147819580 offset:-1 ]).267,386,880bytes (mcpu=1, probe loop not entered) failed in0.042s;272,629,760bytes (multi-shard) failed in0.041s; both returnedERROR 20301with ~5.2–5.4KBlog growth.parallel 'true'loaded7,275,138rows in2.522sacross 2 shards,log_delta16,479bytes, andcount(*) = 7275138,sum(c1) = 360118153,sum(c3) = 3628192219.53matched an independent oracle computed from the CSV.parallel 'true'legal loads of the same file ran simultaneously through Proxy6001and CN216002; both committed7,275,138rows withrc=0in2.628s.271,292,751-byte file with6.5Mlegal rows followed by200killegal rows kept the 2-shard split (offset 135646421), failed at the first illegal row withERROR 20101in2.219swith24,869bytes of log growth and2matching lines, i.e. bounded probing, not a tail scan.set sql_mode='', Proxy6001): failed in0.038swithERROR 20101 (HY000): internal error: the input value 'st00000000000000000000' is invalid Decimal64 type for column 2; different error code from the strict path, no probe storm.6001, CN116001, CN216002all still served queries after every run; table row counts were0for the failed all-illegal loads.40ms, so there is no window to cancel it; killing the client (SIGKILLat0.8s) during a legalLOAD DATAdid not abort the server-side load (it completed and inserted7,275,138rows). Thectx.Err()checks ingetTailSizeStrictAttemptwere only inspected in source, not exercised behaviorally.statement_infodurations: recording was disabled in this deployment (select count(*) from system.statement_inforeturned0), so timings here are client-side wall clock plus log deltas.Findings
d39d8a4034: the strict boundary probe no longer scans to EOF, no per-row ERROR log storm is produced (0beyond the rangelines across all parallel runs), and the misaligned-column load fails in~40msinstead of~400–500s.ERROR 20301, and both the issue's exact statement and the no-tail variant behave the same.ERROR 20101), and log growth stays in tens of KB rather than GB.ERROR 20101instead ofERROR 20301; this is a pre-existing strict/non-strict error-code difference and is unrelated to the probe hang.0rows, and the mid-file failure did not add rows to the pre-populated target.MOTR / BVT Coverage
No MOTR case was added and no recording/replay was performed. The bug requires a file at or above the
256MiBshard threshold withmcpu > 1; below that size the plan usesmcpu=1, never entersgetTailSizeStrict, and the storm cannot be reproduced. Daily small-data BVT/SQL suites cannot reach this path without a ~256MiBfixture and a 2-shard plan, which does not belong in the daily MOTR run.Large-data judgment: yes, a size-dependent regression guard is warranted, because the defect depends on file size, shard count and log volume. This run covers that boundary locally at 281.9 MiB with both the illegal and the legal file, and with a below/above-threshold pair. No
mo-nightly-regressioncase, workflow run or TKE execution was added for this issue, so CI-level large-data coverage remains open.Parallel execution note: engine parallelism was exercised by the 2-range plan (
mcpu 2) on a single CN per statement, plus two simultaneous loads on different endpoints; MOTR-j Nscheduling was not used because no MOTR case was added.Final Conclusion
Fixed. At
origin/maind39d8a4034(including #31387 and #31515) the parallelLOAD DATAplan probe no longer scans a bad CSV to EOF: the original repro now fails in~40mswith the same row-1ERROR 20301, produces no per-row ERROR log storm, and does not hang for minutes. Happy-path parallel loads, the 256MiB boundary, mid-file corruption, and concurrent loads across Proxy/CN1/CN2 all behaved correctly with results verified against an independent oracle. Residual items are the documented fanout demotion for distant boundaries, unverified probe-phase cancellation, and the absence of a TKE/nightly large-data case.