mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-28 01:09:49 +01:00
catalog: a snapshot that landed despite an error tells its kept files at once; persistence doc says which writes wait (CodeRabbit on #2867)
This commit is contained in:
1 parent
39fd014463
commit
8b05bc2b5e
3 files changed
+17
-3
No files matched your search
@@ -836,6 +836,15 @@ impl Journal {
|
||||
}
|
||||
}
|
||||
|
||||
/// A snapshot reported a failure: one that landed all the same (a share that dropped its answer) and is in this
|
||||
/// build's format did the upgrade, so the files kept for it are the way back now, to be told without waiting for
|
||||
/// a later snapshot that succeeds.
|
||||
fn upgraded_despite_error(&mut self) {
|
||||
if self.behind.is_some() && self.on_disk_version() == Some(Some(VERSION)) {
|
||||
self.upgraded_later();
|
||||
}
|
||||
}
|
||||
|
||||
/// The files a snapshot kept when it upgraded a library that was left in an older format at
|
||||
/// open (see `behind`), once, after it was written: [`LoadReport::kept`] has only what the
|
||||
/// open kept. Empty when there are none.
|
||||
@@ -915,6 +924,7 @@ impl Journal {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
// nothing lost (the log is whole); don't retry on every append
|
||||
self.upgraded_despite_error();
|
||||
self.stats.failed_snapshots += 1;
|
||||
self.retry_at_records = self.log_records + self.policy.max_records;
|
||||
return Err(io(e));
|
||||
@@ -1006,6 +1016,7 @@ impl Journal {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
// the log still holds every record: nothing lost, retry later
|
||||
self.upgraded_despite_error();
|
||||
self.stats.failed_snapshots += 1;
|
||||
self.retry_at_records = self.log_records + self.policy.max_records;
|
||||
log::error!("catalog: background snapshot failed: {e}");
|
||||
|
||||
@@ -672,8 +672,9 @@ fn a_snapshot_that_landed_after_its_files_were_kept_is_tried_again() {
|
||||
LAND.store(1, std::sync::atomic::Ordering::SeqCst);
|
||||
assert!(j.snapshot(&c).is_err(), "landed, and said it did not");
|
||||
assert_eq!(snapshot_version(&m), u64::from(VERSION), "it did land");
|
||||
j.snapshot(&c).unwrap();
|
||||
// the upgrade landed: its way back is told now, not only after a later snapshot succeeds
|
||||
assert_eq!(j.take_kept(), ["catalog.snap.v6-8", "catalog.log.v6-8"]);
|
||||
j.snapshot(&c).unwrap();
|
||||
assert_eq!((m.get("catalog.snap.v6-8"), m.get("catalog.log.v6-8")), (Some(snap), Some(log)), "the old library, not the snapshot that landed");
|
||||
assert!(j.take_kept().is_empty(), "told once");
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
The catalog is two files in the library folder (`crates/catalog/src/journal.rs`): `catalog.snap`, a JSON snapshot of
|
||||
the whole catalog, and `catalog.log`, one JSON line per change made since. Every change is handed to the log before
|
||||
its command returns; natively the log's own thread writes and fsyncs it right after, so a command never waits for the drive (a
|
||||
write that fails is held and retried, and switching the library or quitting waits for it). Now and then the log is
|
||||
its command returns; natively the log's own thread writes and fsyncs it right after, so appending a change never waits for the
|
||||
drive (a write that fails is held and retried, and switching the library or quitting waits for it). `library.compact` does
|
||||
wait: it writes and syncs its snapshot before it returns, and the first snapshot after a deferred upgrade copies the files
|
||||
it keeps on the caller's thread. Now and then the log is
|
||||
compacted into a new snapshot. This page covers what happens to a library's files when a newer version opens it.
|
||||
|
||||
## Going back to an older version
|
||||
|
||||
Reference in new issue
Block a user