Repository navigation
Description
Description
mo_ctl('dn', 'flush', <target>) handles invalid targets with three distinct broken error paths, each failing hygiene in a different way. The handler (pkg/sql/plan/function/ctl/cmd_flush.go) parses the target as TableId or DbName.TableName[.AccountId], but none of its failure modes produce a proper user-facing error:
| target | result | problem |
|---|---|---|
'' (empty) |
ERROR 20101 (HY000): internal error: handleFlush: table id parse fail |
internal-error code for what is invalid input; message leaks the internal func name |
'a' / '!!!' (any single junk segment) |
same 20101 internal error | should be 20301 invalid input with usage hint |
'nonexistent_db.anything' (2 segments, db does not exist) |
ERROR (0, 'ExpectedEOB') — SQLSTATE-less, errno 0, message is a raw internal sentinel token |
StorageEngine.Database() returns the internal OkExpectedEOB code when the db is not visible; handleFlush propagates it to the client un-translated |
'a.b.c' (3 segments, bad account) |
ERROR 20101: internal error: handleFlush: invalid account id |
same internal-code-for-input problem |
The (0, 'ExpectedEOB') leak is the worst case: clients see errno 0 (which conventionally means success) plus a token from the internal error-code space, identical in shape to the previously fixed leaks in #30506 (temp-table DDL path) and #27463 — this is the same leak class resurfacing through the mo_ctl administrative path, which was not covered by those fixes.
For contrast, the sibling command mo_ctl('cn','reader', ...) was fixed in #31499 and now correctly answers ERROR 20301: invalid input: invalid reader ctl parameter "", expect cmd:cfg:tid1,tid2[:blk_cnt], e.g. ... — a clean invalid-input code with a usage hint. The flush path never received the same treatment.
Impact
- Monitoring/alerting keyed on
status='Failed' AND err_code=0misses these failures entirely; SIEM rules see a bogus errno-0 error. - The raw sentinel exposes an internal mechanism name to SQL clients (information disclosure / confusing UX for DBAs running documented admin commands).
- A DBA typo'ing the flush target gets an "internal error" instead of a usable message, since the valid usage (
DbName.TableName[.AccountId]/ numeric TableId) is only documented in source comments.
Expected behavior
- Empty/mal-formed target →
20301 invalid inputwith a usage hint, mirroring the reader handler. - Nonexistent database → normal
1049 Unknown database/1146style error, i.e.handleFlushmust translateOkExpectedEOBfromDatabase()the way DDL paths now do.
Reproduction (main @ c6683bd, 2026-10-29 build)
SELECT mo_ctl('dn', 'flush', ''); -- 20101 internal error: handleFlush: table id parse fail
SELECT mo_ctl('dn', 'flush', '!!!'); -- 20101 same
SELECT mo_ctl('dn', 'flush', 'nonexistent_db.x'); -- ERROR (0, 'ExpectedEOB')
SELECT mo_ctl('dn', 'flush', 'a.b.c'); -- 20101 handleFlush: invalid account id
-- control: existing db, existing table works fine:
SELECT mo_ctl('dn', 'flush', 'mc.t'); -- OK JSON
-- control: existing db, missing table is properly reported:
SELECT mo_ctl('dn', 'flush', 'mc.nosuch'); -- 1146 no such table mc.nosuchThe 1146 path proves proper translation already exists downstream (Relation() errors arrive correctly); only Database()'s EOB return and the input-parse failures bypass it.
Activity
fix(ctl): classify invalid flush targets and missing databases (#31792)
XuPeng-SH commentedon Oct 30, 2026
QA handoff for merged #31792 (
65a1a79461de7207f2fd0af40c6d1a3e76eba68e): this isolated QA run inspected the merged source and issue history, but did not execute current-head functional tests or live SQL because available headroom under the existing resource guard was insufficient. Please verify malformed flush target errors, missing database 1049/42000, preservation of other errors and connection reuse. PR author-reported results are separate evidence and are not results of this QA run.slyunnn commentedon Nov 2, 2026
Regression and extended verification for #31663 (2026-11-02)
Verification Environment
d24f446e1e94a58c329d422519f7aad621cdcd05—perf(sql): cost literal LIKE prefix ranges with analyzed distributions (#31940).git_version()at all endpoints confirmedd24f446e1e.2 CN / 1 TN / 1 Log service / Proxy. Proxylocalhost:6001, CN1localhost:16001, CN2localhost:16002were reachable and each executed all live flush/error/recovery cases.3.14with PyMySQL over MySQL text-query protocol. Error numbers and SQLSTATE were decoded from actual MySQL ERR packets. Existing BVT additionally ran through JDBC at the Proxy.What Was Covered
20301/HY000with the acceptedTableIdorDbName.TableName[.AccountId]usage; no internal-function error is exposed.1049/42000; an existing database's missing table retains1146/42S02. No errno0orExpectedEOBleaks.9successful form/endpoint combinations.36actual ERR-packet assertions, each followed on the same connection bySELECT 1, a valid flush and an exact full-row readback. All fixture databases removed.Findings
Related fix: PR #31792, merge
65a1a79461de7207f2fd0af40c6d1a3e76eba68e—fix(ctl): classify invalid flush targets and missing databases. Included in the tested main snapshot. Invalid input is classified explicitly, the missing-database sentinel is translated, and unrelated error classes remain intact.MOTR / BVT Coverage
pkg/sql/plan/function/ctlpackage passed:51top-level tests plus16subtests, no failures or skips, including all9flush-focused top-level tests.test/distributed/cases/function/ctl_flush_error_classification.sqlwas replayed twice against its checked-in expected result: each run15/15statements passed,0failures/skips/abnormal results.Final Conclusion
Fixed on the tested main snapshot. Large-data regression is not required: the faulty boundary is target parsing and error translation, not table cardinality or flush throughput.