Skip to content

fix: drop unflushed INSERT header for oversized rows in SQL dump mode - #62

Merged
XuPeng-SH merged 1 commit into
mainfrom
fix-e-insert-header-30638
Oct 22, 2026
Merged

XuPeng-SH merged 1 commit into
mainfrom
fix-e-insert-header-30638

Conversation

@aptend

@aptend aptend commented Oct 20, 2026

Copy link
Copy Markdown
Contributor
  • matrixone#30638 — in SQL dump mode, when one row exceeds -net-buffer-length, showInsert broke out of the row loop with the oversized row held in the carry buffer but nothing emitted. The next loop iteration wrote a fresh INSERT INTO ... VALUES prefix into the still-dirty buffer, producing a statement with a duplicated header; the export reported MODUMP SUCCESS yet the script is invalid SQL. The buffer is now reset before the carry-over continue.

Test: Test_showInsertOversizedRow (sqlmock rows, oversized single row, asserts exactly one INSERT INTO header) passes. Test_toCsvFields/Test_toCsvLine fail identically on clean main (pre-existing, unrelated).

Closes matrixorigin/matrixone#30638

- matrixone#30638: when a single row exceeds -net-buffer-length, the
  emit path looped back without resetting the statement buffer, so the
  oversized row was preceded by a duplicated 'INSERT INTO .. VALUES'
  header, making the successful backup unrestorable. Reset the buffer
  before the carry-over continue.
Tests: Test_showInsertOversizedRow.
(Test_toCsvFields/Test_toCsvLine failures pre-exist on main.)
@mergify

mergify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6d1f9f97c56b976abe9ba030d6c52b8b01d59718 against 324c33dbdc7075cd5d7beaafd1e15c76709dd442. No blocking findings.

The reset belongs at this existing buffer-ownership boundary: on the no-emission path, buf contains only the unflushed INSERT header, while curBuf still owns the pending row. Resetting buf restores the next-iteration invariant; the next iteration consumes the pending row unconditionally. This adds no state machine, allocation, row copy or new output path. The ordinary flush already resets the statement buffer through WriteTo.

Independent validation:

  • The committed oversized-row regression passes.
  • Nineteen additional cases pass using the actual MatrixOne SQL parser and comparison of decoded row IDs, order and every payload byte: below/exactly-at/above thresholds (including the default 1 MiB), empty/normal input, first/last/consecutive/mixed oversized rows, UTF-8 and escapes, LONGBLOB, hex BLOB, NULL/empty values, and buffer-pool reuse. The same baseline probes reproduce the duplicate header in 11 cases.
  • The pending-oversized-row path propagates an output write error. The committed regression, boundary probes and write-error probe also pass with -race.
  • Full go test ./... fails at the same two CSV tests on both head and clean base, confirming the reported baseline failures.

Source-iteration error injection still returns nil on both revisions, matching the existing separately tracked matrixorigin/matrixone#30574. This PR addresses the duplicate-header corruption; it does not close that query-cancellation issue. The validation above checks SQL parsing and decoded data, not a live database restore.

One non-blocking cleanup comment on the new test fixture is attached.

Comment thread cmd/mo-dump/main_test.go
bufPool := &sync.Pool{New: func() any { return &bytes.Buffer{} }}

old := os.Stdout
pr, pw, _ := os.Pipe()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: please close pr explicitly after reading it (or register its cleanup immediately). This fixture closes only pw, leaving the pipe's read descriptor to GC/process exit. Registering stdout restoration and both descriptor cleanups up front would keep the test self-contained without adding fixture complexity.

@XuPeng-SH
XuPeng-SH merged commit 0ed6f92 into main Oct 22, 2026
@XuPeng-SH
XuPeng-SH deleted the fix-e-insert-header-30638 branch October 22, 2026 06:50
aptend added a commit that referenced this pull request Oct 22, 2026
…trip-305xx

Resolve cmd/mo-dump/main.go conflicts against main's bufio-based CSV writer
(#57/#59) and the #30638 INSERT-header fix (#62), and
harden the #30587 sql_mode pin:

- imports: keep strconv/math for the float overflow/-0 CAST path (#30598);
  main's regexp/encoding-csv removals retained.
- toCsv tail: take main's r.Err()+w.Flush(), which already covers the #30628
  final-flush error; drop the csvWriter.Error() alternative.
- showLoad: keep plain-name CSV reference (#30481), sqlStringLiteral quoting
  of path/delimiter (#30590) and the explicit Close() error check (#30628).
- sql_mode pin (#30587): emit once at the top of the script instead of inside
  the per-database all-tables block. A multi-database dump previously
  overwrote @MODUMP_SAVED_SQL_MODE with the already-stripped mode, so the
  end-of-script restore restored the wrong value; -tbl dumps skipped the pin
  entirely.
- sql_mode strip: remove NO_BACKSLASH_ESCAPES from a comma-wrapped list via
  TRIM(BOTH ',' FROM REPLACE(CONCAT(',',mode,','),',NO_BACKSLASH_ESCAPES,',','))
  so it cannot leave an invalid empty token ('X,' / ',X' / 'X,,Y') at any
  position of the mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: mo-dump SQL repeats INSERT header for a row larger than net-buffer-length, making successful backup unrestorable

2 participants