Repository navigation
fix: drop unflushed INSERT header for oversized rows in SQL dump mode - #62
Conversation
- 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.)
|
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
left a comment
There was a problem hiding this comment.
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.
| bufPool := &sync.Pool{New: func() any { return &bytes.Buffer{} }} | ||
|
|
||
| old := os.Stdout | ||
| pr, pw, _ := os.Pipe() |
There was a problem hiding this comment.
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.
…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.
-net-buffer-length,showInsertbroke out of the row loop with the oversized row held in the carry buffer but nothing emitted. The next loop iteration wrote a freshINSERT INTO ... VALUESprefix into the still-dirty buffer, producing a statement with a duplicated header; the export reportedMODUMP SUCCESSyet the script is invalid SQL. The buffer is now reset before the carry-overcontinue.Test:
Test_showInsertOversizedRow(sqlmock rows, oversized single row, asserts exactly oneINSERT INTOheader) passes.Test_toCsvFields/Test_toCsvLinefail identically on clean main (pre-existing, unrelated).Closes matrixorigin/matrixone#30638