8000 fix: skip checkpoint on Drop when handle made no writes (issue #226) by adityamukho · Pull Request #228 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

fix: skip checkpoint on Drop when handle made no writes (issue #226) - #228

Merged
adityamukho merged 8 commits into
mainfrom
fix/drop-readonly-handle
May 3, 2026
Merged

adityamukho merged 8 commits into
mainfrom
fix/drop-readonly-handle

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • Adds an early-return guard in do_checkpoint: skips force_dirty() + save() when wal_entry_count == 0 && !pfs.is_dirty(), preventing read-only handles from writing to the file on Drop
  • Comments explain that file locking (.graph.lock) already covers the multi-process case; the guard closes same-process double-opens and lock-bypass edge cases
  • Also fixes a latent bug in PersistentFactStorage::new: the old page_count > 1 load condition skipped migration for empty v5 files; replaced with !is_new_backend || page_count > 1 using the pre-existing StorageBackend::is_new() method

Test Plan

  • test_readonly_handle_drop_does_not_modify_file — new regression test: opens a file-backed DB, writes + checkpoints, opens a second read-only handle, drops it, asserts file size is unchanged
  • Full suite: 802 tests passing (up from 795 baseline)

Closes #226

🤖 Generated with Claude Code

adityamukho and others added 8 commits May 3, 2026 13:43
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Inner::drop() called do_checkpoint() unconditionally, which called
force_dirty() + save() even for read-only handles — growing the file
by 4 KB and invalidating other open handles.

Add an early-return guard in do_checkpoint: skip when wal_entry_count
is zero and pfs is not dirty. force_dirty() is still called when the
guard passes, preserving the crash-recovery path where WAL entries are
replayed into memory on open (wal_entry_count > 0, dirty == false).

File locking already prevents multi-process exposure in the common
case; this guard closes same-process double-opens and lock-bypass
edge cases.

Also fix PersistentFactStorage::new to use !is_new || page_count > 1
instead of page_count > 1 for the load condition. The old condition
skipped load() for v5 files with only a header page (page_count == 1),
so migrate_v5_to_v6 never ran for empty legacy databases. The new
condition ensures FileBackend always loads existing files (is_new=false)
while MemoryBackend (is_new always true) retains the page_count check.
@codecov
codecov Bot commented May 3, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit 8ef81f4 into main May 3, 2026
36 checks passed
@adityamukho
adityamukho deleted the fix/drop-readonly-handle branch May 3, 2026 09:11
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.

[vulcan] minigraf_bug: MiniGrafDb::drop() writes to the graph file uncond

1 participant

0