Skip to content

[PHP] Restart interrupted db-apply from the beginning - #595

Closed
adamziel wants to merge 1 commit into
codex/file-db-pull-durable-resumefrom
codex/db-apply-confirmed-replay
Closed

[PHP] Restart interrupted db-apply from the beginning#595
adamziel wants to merge 1 commit into
codex/file-db-pull-durable-resumefrom
codex/db-apply-confirmed-replay

Conversation

@adamziel

@adamziel adamziel commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

A stopped db-apply now starts an unchanged, complete db.sql from the beginning on a new target connection.

Background

The old code continued after its saved statement number. That statement number did not say which MySQL changes were committed. The new connection also skipped the dump header which sets SQL mode, foreign-key checks, unique checks, and autocommit.

This change

Before the first target query, database-apply.json stores the SHA-256 of db.sql, the target database, URL replacements, table prefix, and host-specific plugin removals. A later process starts again only when those values still match. If they do not, the error explains that the target may have changed and tells the user to restore or reset it before aborting the apply.

Every restart opens a new connection and reads db.sql from the beginning, so the header runs again. MySQL applies also hold a lock in the target database. A new process waits if the old target session is still running a query.

Completion is saved before normal command state. If the process stops between those two writes, the next process repairs the command state without applying SQL again.

This is PR 3 of 5: #590#591#595#582#607.

Testing

The focused tests cover orderly stops, process death, changed SQL, changed targets and options, connection failure, the final state-write failure, and a target session which remains alive after the PHP process dies. The MySQL E2E also checks that SQL mode and foreign-key settings run on the new connection.

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Pull pipeline performance — large-directory

Site: large-directory · 2,000+ plus targeted file-transfer scenarios files · 10,000 posts · 25,000 postmeta · PHP 8.5.9

Stage PR trunk Δ Status Details
playground-sqlite-db-pull 9.68 s 9.61 s ⚪ +78 ms (+0.8%) condition=db-pull in PHP.wasm
runtime=php.wasm 8.3
wp_mysql_parser=enabled
mode=lexer
native_lexer=verified
native_token_stream=WP_MySQL_Native_Token_Stream
native_token_count=18
native_parser=selected
trunk: condition=db-pull in PHP.wasm
runtime=php.wasm 8.3
wp_mysql_parser=enabled
mode=lexer
native_lexer=verified
native_token_stream=WP_MySQL_Native_Token_Stream
native_token_count=18
native_parser=selected
playground-sqlite-db-apply 3.72 s 3.73 s ⚪ -18 ms (-0.5%) condition=db-apply to SQLite in PHP.wasm
runtime=php.wasm 8.3
wp_mysql_parser=enabled
mode=parser
native_lexer=verified
native_token_stream=WP_MySQL_Native_Token_Stream
native_token_count=18
native_parser=verified
native_ast=WP_MySQL_Native_Parser_Node
sqlite_driver_parser=verified
trunk: condition=db-apply to SQLite in PHP.wasm
runtime=php.wasm 8.3
wp_mysql_parser=enabled
mode=parser
native_lexer=verified
native_token_stream=WP_MySQL_Native_Token_Stream
native_token_count=18
native_parser=verified
native_ast=WP_MySQL_Native_Parser_Node
sqlite_driver_parser=verified
Total 13.40 s 13.34 s ⚪ +59 ms (+0.4%)

Numbers carry runner noise; treat single-run deltas as directional, not authoritative.

📈 Trunk performance history — commit-by-commit timeline.

@adamziel
adamziel force-pushed the codex/db-apply-confirmed-replay branch 2 times, most recently from b80107d to 0973ff7 Compare August 14, 2026 02:10
@adamziel
adamziel force-pushed the codex/file-db-pull-durable-resume branch 3 times, most recently from c9e724a to 710ae4e Compare August 14, 2026 12:45
@adamziel
adamziel force-pushed the codex/db-apply-confirmed-replay branch from 0973ff7 to e562106 Compare August 14, 2026 12:48
@adamziel
adamziel force-pushed the codex/file-db-pull-durable-resume branch from 710ae4e to 64c7cde Compare August 14, 2026 12:52
@adamziel
adamziel force-pushed the codex/db-apply-confirmed-replay branch from e562106 to 2b6e97c Compare August 14, 2026 12:53
@adamziel adamziel changed the title [PHP] Replay interrupted db-apply from confirmed replacement dumps [PHP] Restart interrupted db-apply from the beginning Aug 14, 2026
@adamziel
adamziel force-pushed the codex/file-db-pull-durable-resume branch from 64c7cde to a73c0b4 Compare August 14, 2026 12:58
@adamziel

Copy link
Copy Markdown
Collaborator Author

Closing this draft. It is being replaced by a smaller target-database checkpoint stack.

@adamziel adamziel closed this Aug 14, 2026
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.

1 participant