Skip to content

Make source database operations crash-safe and skip unnecessary refreshes#17

Open
dinkelk wants to merge 1 commit into
masterfrom
fix/source-db-crash-safety
Open

Make source database operations crash-safe and skip unnecessary refreshes#17
dinkelk wants to merge 1 commit into
masterfrom
fix/source-db-crash-safety

Conversation

@dinkelk
Copy link
Copy Markdown
Owner

@dinkelk dinkelk commented Apr 8, 2026

Summary

Two hardening changes for the redo source database:

Commit 1: Skip unnecessary source database refresh for unchanged files

initializeSourceDatabase was called unconditionally for every source file on every build, even when nothing changed. This deleted and recreated the database directory each time — unnecessary work that also opened a corruption window. Now we compare the current stamp against the cached stamp and skip the refresh when they match.

Commit 2: Make initializeSourceDatabase crash-safe by writing source marker first

When initializeSourceDatabase does need to run, it now writes the source marker (y) before any destructive operations. Previously it deleted the database first, then wrote the marker — if killed between those steps (e.g. Ctrl+C), the marker was lost. Now the marker is always present after the first write, and stale target entries are cleaned up individually afterward.

@dinkelk dinkelk force-pushed the fix/source-db-crash-safety branch 4 times, most recently from ae30e85 to 92c9975 Compare April 8, 2026 16:05
When redo-ifchange encounters a source file from within a .do file, it
previously called initializeSourceDatabase unconditionally — even if the
file hadn't changed. That function deletes and recreates the entire
database directory, which opens a corruption window: if the process is
killed (e.g. Ctrl+C triggering SIGKILL via the process group handler)
between the delete and the markSource write, the database is left without
a source marker. This causes permanent "No rule to build" errors in
projects with a catch-all default.do.

Now we compare the current file stamp against the cached stamp first. If
they match, we skip the refresh entirely — the database is already in the
correct state. This eliminates the corruption window for the vast majority
of source files on incremental builds (only files that actually changed
need the refresh).

Includes tests verifying:
- Unchanged sources skip DB refresh (inode stability check)
- Changed sources still trigger refresh and dependent rebuilds
- New sources get properly initialized
@dinkelk dinkelk force-pushed the fix/source-db-crash-safety branch from 92c9975 to 7c7443f Compare April 8, 2026 16:18
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