From 07f9c891dd14ff5a9af50288c6bd341599bb7a6f Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 16 Nov 2026 02:36:13 +0000 Subject: [PATCH 1/2] test(log): a seal whose manifest was not logged cannot be retried log_run stores the run file with create_new before it appends the manifest naming it. When that append fails, or a crash comes between the two, the run file stays, and every later seal of the same entry range finds it and refuses with "a run for that entry range is already stored": the log cannot be sealed again until someone deletes the file by hand. The test fails the put of the bundle carrying the manifest, reopens the store and expects the second seal to log the run. --- crates/rfc9162-log/tests/store.rs | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/crates/rfc9162-log/tests/store.rs b/crates/rfc9162-log/tests/store.rs index 5251e39..ec8afc8 100644 --- a/crates/rfc9162-log/tests/store.rs +++ b/crates/rfc9162-log/tests/store.rs @@ -452,3 +452,59 @@ fn recovery_counts_the_paths_moved_aside() { "{moved:?}" ); } + +/// A memory store whose next put of an entry bundle fails once armed. +#[derive(Clone)] +struct Flaky { + inner: MemoryStore, + armed: Arc, +} + +impl TileStore for Flaky { + fn get(&self, path: &str) -> std::io::Result>> { + self.inner.get(path) + } + fn put(&self, path: &str, bytes: &[u8]) -> std::io::Result<()> { + if path.starts_with("tile/entries/") + && self.armed.swap(false, std::sync::atomic::Ordering::SeqCst) + { + return Err(std::io::Error::other("injected put failure")); + } + self.inner.put(path, bytes) + } + fn create_new(&self, path: &str, bytes: &[u8]) -> std::io::Result { + self.inner.create_new(path, bytes) + } + fn delete(&self, path: &str) -> std::io::Result { + self.inner.delete(path) + } + fn rename(&self, from: &str, to: &str) -> std::io::Result<()> { + self.inner.rename(from, to) + } + fn list(&self, prefix: &str) -> std::io::Result> { + self.inner.list(prefix) + } +} + +#[test] +fn a_seal_whose_manifest_was_not_logged_is_retried() { + let flaky = Flaky { + inner: MemoryStore::new(), + armed: Arc::default(), + }; + let mut store = Store::open(flaky.clone(), fields()).expect("open"); + for i in 0..5 { + store.append(&entry(i)).expect("append"); + } + // The run file is stored, the bundle carrying its manifest is not. + flaky.armed.store(true, std::sync::atomic::Ordering::SeqCst); + assert!(matches!(store.seal(), Err(Error::Store(_)))); + drop(store); + + let mut store = Store::open(flaky.clone(), fields()).expect("reopen"); + let run = store.seal().expect("seal again"); + assert_eq!(run.entries, 0..=4); + assert_eq!(run.manifest_index, Some(5)); + let hits = store.find(b"module=m3").expect("find"); + assert_eq!(hits[0].run.as_ref().map(|r| r.index), Some(5)); +} From 48ea992096d845efca0afe7959387348b7476149 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 16 Nov 2026 02:36:31 +0000 Subject: [PATCH 2/2] fix(log): retry a run whose manifest was not logged When create_new finds a run file at the path, log_run now reads it and goes on to append the manifest if the bytes are the run it encoded. A run file is part of the log only through a manifest that binds its hash, so the leftover of a failed or interrupted seal or compaction is that same run. Other bytes for the range are still refused, as another run. --- changelog.d/+run-retry.bugfix.md | 2 ++ crates/rfc9162-log/src/store.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelog.d/+run-retry.bugfix.md diff --git a/changelog.d/+run-retry.bugfix.md b/changelog.d/+run-retry.bugfix.md new file mode 100644 index 0000000..89279c3 --- /dev/null +++ b/changelog.d/+run-retry.bugfix.md @@ -0,0 +1,2 @@ +`rfc9162-log`: A seal or compaction retried after its manifest append failed, or after a crash between storing the run file and logging the manifest, logs the run. +It found its own run file and refused every retry with "a run for that entry range is already stored"; a run file with other bytes for the range is still refused. diff --git a/crates/rfc9162-log/src/store.rs b/crates/rfc9162-log/src/store.rs index 63a0283..b534fb8 100644 --- a/crates/rfc9162-log/src/store.rs +++ b/crates/rfc9162-log/src/store.rs @@ -1100,8 +1100,14 @@ impl Store { ) -> Result { let bytes = Run::encode_blocks(&entries, &pairs)?; let path = run_path(&entries); - if !self.manifest_store().create_new(&path, &bytes)? { - return Err(Error::Tree("a run for that entry range is already stored")); + let store = self.manifest_store(); + // A seal or compaction whose manifest append failed, or was cut short + // by a crash, left its run file behind: the same bytes are that run, + // which only the manifest makes part of the log. + if !store.create_new(&path, &bytes)? && store.get(&path)?.as_deref() != Some(&bytes[..]) { + return Err(Error::Tree( + "another run for that entry range is already stored", + )); } let (key_lo, key_hi) = match (pairs.first(), pairs.last()) { (Some(first), Some(last)) => (first.0.clone(), last.0.clone()),