Repository navigation
feat(backup): stream the dump and the restore, in the backend - #652
Merged
Merged
Conversation
The whole backup was built in the renderer: every CREATE and every INSERT concatenated into one JavaScript string, handed across IPC in a single call, and written to disk at the end. A ten-million-row table meant gigabytes held in the WebView before the file existed, and cancelling could not give the memory back (#358). Rows were read with LIMIT/OFFSET against the pool, which is quadratic, and with no ORDER BY and no shared session is free to return a row twice or not at all. `mas-core::backup` writes straight to the file as it reads, on one connection, streaming rows. Memory is bounded by the buffer. Checking the output found something worse than the memory: every value went through the grid's value type on the way out, which formats DATETIME as `%Y-%m-%d %H:%M:%S` and rounds through f64. Every backup was silently dropping the fractional seconds from DATETIME(6), and putting BIGINTs and DECIMALs through a float. The dump now formats each cell from the bytes the server printed over the text protocol, which is what mysqldump sees and the only form that round-trips. Also found: `SHOW CREATE VIEW` names the view — and every table in its body — with the database it came from, so restoring a dump into a second database recreated the view in the first one, or failed with "already exists" against the object it was copied from. New: a consistent snapshot by default (what `mysqldump --single-transaction` does), so a dump of a live database cannot contain a child row whose parent was written later; progress at row-batch boundaries with rows/sec and an estimate, rather than one report per table, so a single large table no longer looks identical to a hung one (#361); a warning list for what could not be read, in the file and in the summary; and a cancel that removes the partial file, because a partial dump that looks like a dump is how someone restores half a database a month later. The restore is the same shape. It used to read the whole file into the renderer, split it there, and send back one statement per call — each on whichever pooled connection it landed on, so `USE` and any session setting applied to a session the next statement might not get (#359). `mas-core::restore` reads in chunks, splits as it goes with a state machine that handles quotes, both comment forms and DELIMITER, and runs the statements on one connection. A file that ends inside a string, a comment or an unterminated stored program is now an error naming what was cut short, rather than a splitter waiting forever for a terminator that never comes (#360). On the transaction #359 asked for: it is there, and it makes a data-only file all or nothing, but it cannot make a dump with DDL atomic. MySQL commits before every CREATE, DROP and ALTER — verified on 8.0.46, where ROLLBACK after CREATE TABLE + INSERT left both the table and the row. So the summary reports `partiallyApplied` and the dialog says which of "the database is as it was" and "part of this already applied" is true, which is the thing the old dialog never said either way. Foreign-key and uniqueness checks are turned off for the restoring session and back on when it ends, so a file whose tables are in the wrong order loads — and no connection is left in the pool with them off. Docs: ARCHITECTURE 3.6 promised a mysqldump wrapper that detects the binary on PATH (#357). There is none and there should not be: requiring a binary the user may not have, at a version that may not match the server, is a worse guarantee than a native dump that formats from the server's own bytes. §5.11 now describes what is there, and §5.10's event table — nine rows, six of them for a streaming architecture that was never built — is down to the three events that exist. 19 Rust unit tests, 19 live-server integration tests (passing against MySQL 8.0.46 and MariaDB 11.8), 28 frontend tests. The TS generator and its 757 lines of tests are gone.
…back The round-trip test the audit asked for — dump a database, restore it elsewhere, compare — found this on its first run: the dump opened START TRANSACTION WITH CONSISTENT SNAPSHOT and never closed it, so the connection returned to the pool still reading the database as it was. The next caller to get that connection saw a stale schema, which surfaces later and somewhere else as "Table definition has changed, please retry transaction". Two tests: the round trip itself, which compares a checksum over every column of every row rather than a row count, so a value that came back subtly different fails there rather than looking identical; and a direct one that alters the table after a dump and reads the schema back on every pooled connection. Closes the backup audit's F7 and F9.
This was referenced Sep 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #358, #357, #359, #360, #361.
The dump moved to Rust (#358)
It was built in the renderer: every CREATE and every INSERT concatenated into one JavaScript string, handed across IPC in a single call, written to disk at the end. A ten-million-row table meant gigabytes held in the WebView before the file existed, and cancelling could not give the memory back. Rows were read with
LIMIT/OFFSETagainst the pool — quadratic, and with no ORDER BY and no shared session, free to return a row twice or not at all.mas-core::backupwrites straight to the file as it reads, streaming rows over one connection. Memory is bounded by a 256 KB buffer.What checking the output found
Every backup was losing data. Values went through the grid's value type on the way out, which formats DATETIME as
%Y-%m-%d %H:%M:%Sand rounds throughf64. SoDATETIME(6)lost its microseconds, and BIGINT and DECIMAL went through a float — in a backup. Cells are now formatted from the bytes the server printed over the text protocol: what mysqldump sees, and the only form that round-trips.Views restored into the wrong database.
SHOW CREATE VIEWnames the view, and every table in its body, with the database it came from. Restoring such a dump into a second database recreated the view in the first one — or failed with "already exists" against the object it was copied from.New in the dump
START TRANSACTION WITH CONSISTENT SNAPSHOTon the reading connection, whatmysqldump --single-transactiondoes. Without it a dump of a live database can contain a child row whose parent was written later and is not in the file. When the server refuses (MyISAM) the dump says so, in the file and in the summary.The restore, same shape (#359, #360)
It read the whole file into the renderer, split it there, and sent back one statement per call — each on whichever pooled connection it landed on, so the
USEthat opened the database was not guaranteed to apply to the next statement.mas-core::restorereads in chunks, splits as it goes (quotes,--/#//* */, backticks, DELIMITER), and runs on one connection. A file ending inside a string, a comment, or an unterminated stored program is an error naming what was cut short — #360's hang was the splitter waiting for a terminator that never came.On the transaction #359 asked for. It is there, and it makes a data-only file all-or-nothing. It cannot make a dump with DDL atomic, and no client can: MySQL commits before every CREATE, DROP and ALTER. Verified on 8.0.46 —
ROLLBACKafterCREATE TABLE+INSERTleft both the table and the row. So the acceptance criterion as written ("zero tables created") is not reachable. What the restore does instead is reportpartiallyApplied, and the dialog says which of "the database is as it was" and "part of this already applied — MySQL commits before every CREATE, DROP or ALTER" is true. The old dialog said neither.Foreign-key and uniqueness checks go off for the restoring session and back on when it ends, so a file whose tables are in the wrong order loads, and no pooled connection is left with them off (there is a test for exactly that).
Docs (#357)
ARCHITECTURE 3.6 promised a
mysqldumpwrapper that detects the binary on PATH. There is none, and there should not be: requiring a binary the user may not have, at a version that may not match the server, is a worse guarantee than a native dump that formats from the server's own bytes. §5.11 describes what exists; §5.10's event table — nine rows, six of them for a streaming architecture that was never built — is down to the three events that exist. FR-7.3.3/7.3.4 rewritten.Tests
NO_BACKSLASH_ESCAPESwith avictimtable present to prove it2669 unit, 344 browser, clippy and eslint clean.