Skip to content

[Bug]: parallel LOAD DATA plan probe scans bad CSV to EOF: one ERROR log per row, uncancellable minutes-long hang #31326

Closed

Description

@iamlinjunhong

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

26e3289

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, default sql_mode (STRICT_TRANS_TABLES on).

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 (boundaryContextReader checks ctx per Read, external.go:965-977) — the strict path lacks it.
  • After the probe exhausts the file, ReadFileOffset falls 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 1 for 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, continue on every illegal record); (2) an error-construction API that logs per call: probe-only parse failures go through types.ParseDecimal64 -> moerr.NewInvalidInputNoCtxf -> errutil.WithContextWithDepth -> ERROR report with stack (decimal.go:2141, errutil/context.go:52). MySQL-semantics note: MO treats len(fields) < len(cols) rows as "keep scanning" (external.go:1044 continue), 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 (mirroring boundaryContextReader, external.go:965-977); construct probe-time parse errors with moerr.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

  1. added
    kind/bug
    severity/s0
    on Oct 26, 2026
  2. iamlinjunhong commented on Oct 28, 2026

    @iamlinjunhong
    ContributorAuthor

    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.

  3. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    Contributor

    QA update: merged #31515 (9c8d405b1ee2303474aec513fc16cdf2375089a2, in main 3cf38889bca2d183e973e78b1288f8c704727542) 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.

  4. added
    ai-easy
    on Oct 29, 2026
  5. slyunnn commented on Oct 30, 2026

    @slyunnn

    Regression and extended verification for #31326 (2026-10-30)

    Verification Environment

    • origin/main commit d39d8a40343ccd40bf665036388df7a40ee867f8 — tae: flush eligible AObject prefixes before busy tails (tae: flush eligible AObject prefixes before busy tails #31723). mo-service was built from this commit with make build; binary SHA256 2c16af1e4dd7afb194211233be625af96ebaaba588d2ddd944cfaf3476cb43fe, tracked source diff empty.
    • Related fixes, both merged and ancestors of origin/main: fix(load): bound strict CSV boundary probes #31387 fix(load): bound strict CSV boundary probes (merge ee9b2d2a3a1a83b15e5658b69c822300539e415b) and fix(load): preserve safe parallel splits for long CSV records #31515 fix(load): preserve safe parallel splits for long CSV records (merge 9c8d405b1ee2303474aec513fc16cdf2375089a2).
    • Topology: 2 CN / 1 TN / 1 Log service / Proxy, fresh data directory. Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001, CN2 127.0.0.1:16002; all three accepted connections and reported 8.0.30-MatrixOne-v1.3.0.
    • Client protocol: MySQL text protocol through the mysql CLI, server-side LOAD DATA INFILE against the local ETL fileservice. The original statement was executed through Proxy 6001, then repeated directly on CN1 16001 and CN2 16002.
    • Input: probe_storm.csv, 295,639,040 bytes (281.9 MiB), 7,275,138 rows, SHA256 c7e49e8dc2a2360d563e76fb4150f863f30db36a2a66e7996f0a46acb98af4c1 — header plus 4 fields, misaligned column list (c1,c2,c3) for c3 DECIMAL(12,2), exactly the issue's reproducer.
    • Pre-fix baseline for comparison is the issue's own measurement: 505s wall, +1,455,103,534 bytes of mo-service log, 3,624,770 ERROR lines.

    What Was Covered

    • OK — Serial control on CN1 16001: parallel 'false' returned ERROR 20301 (HY000): invalid input: the data of row 1 contained is not equal to input columns in 0.037s, log growth 4,828 bytes, 0 matching beyond the range lines.
    • OK — Original repro through Proxy 6001: identical statement with parallel 'true' returned the same ERROR 20301 in 0.037s with 5,497 bytes of log growth and 0 beyond the range lines, versus 505s / +1.46GB / 3.6M ERROR lines reported pre-fix.
    • OK — Same statement executed directly on CN1 16001 (0.037s, ERROR 20301, 5,223 bytes) and CN2 16002 (0.038s, ERROR 20301, 5,403 bytes); no endpoint-specific difference.
    • OK — Statement variant without the explicit FIELDS/LINES tail clauses through Proxy 6001: 0.041s, ERROR 20301, 5,334 bytes, 0 matching lines.
    • OK — Plan split decision: for the all-illegal file the strict probe demotes immediately to a single range ([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 ]).
    • OK — Size boundary: 267,386,880 bytes (mcpu=1, probe loop not entered) failed in 0.042s; 272,629,760 bytes (multi-shard) failed in 0.041s; both returned ERROR 20301 with ~5.2–5.4KB log growth.
    • OK — Happy path on the same 281.9 MiB file with the column list matching the file: parallel 'true' loaded 7,275,138 rows in 2.522s across 2 shards, log_delta 16,479 bytes, and count(*) = 7275138, sum(c1) = 360118153, sum(c3) = 3628192219.53 matched an independent oracle computed from the CSV.
    • OK — Concurrent engine/endpoint parallelism: two parallel 'true' legal loads of the same file ran simultaneously through Proxy 6001 and CN2 16002; both committed 7,275,138 rows with rc=0 in 2.628s.
    • OK — Mid-file corruption boundary: a 271,292,751-byte file with 6.5M legal rows followed by 200k illegal rows kept the 2-shard split (offset 135646421), failed at the first illegal row with ERROR 20101 in 2.219s with 24,869 bytes of log growth and 2 matching lines, i.e. bounded probing, not a tail scan.
    • OK — Non-strict control (set sql_mode='', Proxy 6001): failed in 0.038s with ERROR 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.
    • OK — Post-statement health: Proxy 6001, CN1 16001, CN2 16002 all still served queries after every run; table row counts were 0 for the failed all-illegal loads.
    • Not covered — Probe-phase cancellation. After the fix the probe returns in ~40ms, so there is no window to cancel it; killing the client (SIGKILL at 0.8s) during a legal LOAD DATA did not abort the server-side load (it completed and inserted 7,275,138 rows). The ctx.Err() checks in getTailSizeStrictAttempt were only inspected in source, not exercised behaviorally.
    • Not covered — statement_info durations: recording was disabled in this deployment (select count(*) from system.statement_info returned 0), so timings here are client-side wall clock plus log deltas.
    • Not covered — TKE / nightly-scale large-data regression (see below).

    Findings

    • The reported failure mode is gone at d39d8a4034: the strict boundary probe no longer scans to EOF, no per-row ERROR log storm is produced (0 beyond the range lines across all parallel runs), and the misaligned-column load fails in ~40ms instead of ~400–500s.
    • The fix is endpoint- and path-independent: Proxy, CN1 and CN2 all fail fast with the same ERROR 20301, and both the issue's exact statement and the no-tail variant behave the same.
    • Bounded probing is visible in the split decision: an all-illegal candidate region demotes the plan to one range, which also collapses fanout to a single reader. That is the documented trade-off of the bounded budget (fix(load): bound strict CSV boundary probes #31387, fix(load): preserve safe parallel splits for long CSV records #31515), not a new defect.
    • Mid-file corruption is handled within the budget: the plan keeps 2 shards, the statement fails at the first illegal record (ERROR 20101), and log growth stays in tens of KB rather than GB.
    • The non-strict path reports ERROR 20101 instead of ERROR 20301; this is a pre-existing strict/non-strict error-code difference and is unrelated to the probe hang.
    • Statement atomicity after a failed parallel load was consistent with the serial path in the runs above: the all-illegal loads left 0 rows, 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 256MiB shard threshold with mcpu > 1; below that size the plan uses mcpu=1, never enters getTailSizeStrict, and the storm cannot be reproduced. Daily small-data BVT/SQL suites cannot reach this path without a ~256MiB fixture 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-regression case, 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 N scheduling was not used because no MOTR case was added.

    Final Conclusion

    Fixed. At origin/main d39d8a4034 (including #31387 and #31515) the parallel LOAD DATA plan probe no longer scans a bad CSV to EOF: the original repro now fails in ~40ms with the same row-1 ERROR 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions