fix(history): make restore_page and restore_graph atomic

Both run inside Graph::transaction so a failure halfway rolls every change
back. Adds a fault-injection hook and a regression test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-10-21 14:38:46 +02:00
1 parent 3266ddda3a
commit 2b52144311
3 files changed
+145 -51

No files matched your search

+8
View File
@@ -79,6 +79,7 @@ pub struct History {
opts: HistoryOptions,
/// `(last seen graph seq, time we saw it change)` for idle detection.
observed: Option<(i64, i64)>,
pub(crate) fault: std::cell::Cell<Option<usize>>,
}
impl History {
@@ -95,9 +96,16 @@ impl History {
dir,
opts,
observed: None,
fault: Default::default(),
})
}
/// Test hook: make the next restore fail after `n` block writes/deletes.
#[doc(hidden)]
pub fn inject_restore_fault(&self, n: Option<usize>) {
self.fault.set(n);
}
pub fn dir(&self) -> &Path {
&self.dir
}