Repository navigation
Catalog: the snapshot in segments of about 2 MB and at most 4096 photos (format 11, stacked on #800) - #814
Catalog: the snapshot in segments of about 2 MB and at most 4096 photos (format 11, stacked on #800)#814nledford wants to merge 36 commits into
Conversation
552d2c9 to
4735051
Compare
4735051 to
79f1837
Compare
79f1837 to
2b55366
Compare
|
Rebased onto the updated #800 and renumbered: segments are now format 9 (compact records are 8, 7 is left for #752). Changes here beyond the renumbering: segment files are read over the defaults the library states (on every reader thread), a library that states other defaults has every segment rewritten, the format 9 fixture is a library in segments, and the way back to an older version now says to move the |
2b55366 to
cc031a1
Compare
|
Rebased onto current Local verification: |
cc031a1 to
336e510
Compare
|
A note for whoever merges this and #776 (smart albums kept off loops): each builds on its own, but the two together don't compile. I found it by merging all of my open PRs onto a local branch.
// crates/catalog/src/lib.rs, Catalog::without_photos
let Catalog { photos: _, albums, /* … */ folder_records, revision, loops: _ } = self;
Catalog {
// …
revision: *revision,
// (worked out from the albums when asked for: not saved)
loops: LoopsMemo::default(),
}The memo is |
1cf479a to
d9b9c44
Compare
…put off is tested Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sweep of segment sizes (docs/catalog-persistence.md, "Segment size") shows that what a save of a few changes rewrites follows the size of a segment, and for edited photos so does its time, while opening is the same from about 2000 photos per segment up. Halving the sizes (they were 8192 photos and 4 MB) halves what scattered changes rewrite and what a backup after them copies; a save that touches every segment is about 1.4 times as slow where records are small. A setting, not part of the format: existing segments are cut to the new size as they are next rewritten. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…library that kept only one Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…al photos per segment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… What's New states the close thresholds On POSIX FsStore::sync returned Ok when syncing segments/ or the library folder failed, so catalog.snap could name segments whose entries were not durable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EINVAL, ENOTSUP and EBADF from fsync on a folder (network and FUSE file systems) mean "can't be synced here", as on Windows; only real I/O errors fail Store::sync and write_atomic_with. A write_atomic whose rename took effect no longer returns Err for a folder sync, so Err means nothing was written (callers' state stays right). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… own Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
604d743 to
e46aed5
Compare
Stacked on #800 (compact records, format 10). Folds #846 (segment size and the checked folder sync), which is closed as folded.
Replaced by smaller parts, each a draft stacked on the one before: #2867 (upgrades keep what they replace), #2948, #2951, #2957, #2968 (compact records, catalog format 10), #2958, then the segments: #2978, #2983 (format 11), #2984, #2985. The compaction-by-snapshot-size rule that this PR holds is not in those parts.
Why this is stacked: it edits the snapshot code that #800 adds and
maindoes not have: theFORMATStable that format 11 is a row of,Policy::due's snapshot-size parameter,snapshot_bytes, and theReadingOver/reading_oversettings reader instored.rs. Format 11 is the point of this PR and is built on format 10, so it can't be rebuilt offmainwithout #800's compact records and compaction policy. It is the bottom of the backup chain, and every PR above it needs format 11 (the segment files). Merge order: #800, then #814, then #841, #856, #870, #1004, #1025, #1034, #1043 / #1054, #1075, #1303. The chain is being unchained from the bottom: #800's parts and then #814's segment slices are being cut as PRs offmain. When #800 lands, this PR is rebased ontomainand the first line and the title lose "stacked on".Problem
The snapshot is one file, so every compaction rewrites every photo however few changed, and opening reads it on one thread. On a library of 1,000,000 JPEGs, a compaction after 1,000 changes took 570 ms and an open 1,767 ms (see Measurements).
Change
See What below: the snapshot's photos move into segment files in the library folder (catalog format 11); a compaction writes only the segments whose photos changed, and opening reads the segments on several threads.
Not in this PR: the browser build, which keeps its photos in one
catalog.snap; the two problems listed under Notes, left unchanged.How it was checked
cargo test -p lightcraft-catalog282 passed,cargo test -p lightcraft-engine854 passed,cargo fmt --checkand clippy (the full list is under Tests below).What
The snapshot's photos move out of
catalog.snapinto segment files (segments/<first id>-<seq>.jsonin the library folder, each a run of photos in id order, plain JSON).catalog.snapkeeps everything else and lists the segments with their size, CRC-32 and photo count. Catalog format 10 → 11.crates/catalog/src/segments.rs,docs/catalog-persistence.md.Arcs) and compares pointers. Changing a photo copies it, so a segment is rewritten exactly when one of its photos was changed, added or removed, whatever did it.catalog.snapreplaced atomically, then the files it no longer lists removed.catalog.snapis replaced. If they differ, the one file stays.Store::segmented()false: the browser build, whose storage holds a fixed set of files) keep the photos incatalog.snap.Storegainsremove,list,segmented,write_new_with,sync, all with defaults.Measurements
persist_bench, Apple M1 Max; before = #800 (one file, format 10 as it is numbered now). "One place" = 1000 changes to the first 1000 photos; "all over" = a change to every 50th photo (touches every segment).Where it costs more: rewriting every segment at once is slower than one file where records are small (1.5× for JPEG libraries: each file is made durable on its own); and a bulk import of small records takes up to 1.6× as long in this catalog-only benchmark (smaller but more frequent compactions). Memory is unchanged: the catalog is still held whole in memory.
Safety
catalog.snapis refused, not opened as a new library. Segment files beside an older one-filecatalog.snapare left alone for that session.catalog.snapcontent (path-like names, duplicates, wrong order or ranges, huge numbers) isCorruptwith nothing read or modified.Tests
tests_segments.rs(30 tests): layout, only-changed-segments (also after reopening), crash before every single write of a compaction, background compaction, parallel writes with one failing writer, damaged / missing / hostile inputs, the one-file fixture of Catalog: the log is compacted by the snapshot's size, not every 2000 records #800 (format 9 now, written by that build) upgraded, the split that doesn't read back, stores without segments and back, and a randomized model test (adds, gaps, removals, edits, foreground and background snapshots, reopening).tests_background.rs) now runs on the segmented layout; the one-file policy tests run on a store without segments.cargo test -p lightcraft-catalog282 passed (main'stests_repairamong them),cargo test -p lightcraft-engine854 passed;cargo fmt --check;cargo clippy -p lightcraft-catalog -p lightcraft-engine -p lightcraft-web --all-targets -D warnings;cargo xtask parity,layers,assets. Not run on the rebase: the whole ofcargo xtask ci(the wasm build and the UI crate's tests).Three independent adversarial reviews (the third on the changes made after the first two: 20,000 randomized cases with injected failures, which found that a log-only library could be refused after an unfinished first snapshot; fixed, with a test). The first two ran over 740,000 simulated crash points (a copy of the files before every store mutation, sync and background, with and without injected failures, and from a one-file library) with no failure, and could not break the changed-segment detection. They found that cleaning up at open could delete good data in three situations (missing
catalog.snap, an older snapshot restored over a newer folder, a second program opening an unlocked library mid-save), a thread-spawn panic path, and tests that didn't prove what they claimed (shown by mutation testing); all fixed here, and the mutations that slipped through are now caught.Notes
catalog.snapalone no longer holds the photos.main; Catalog: the log is compacted by the snapshot's size, not every 2000 records #800 is 9 and this is 10.seq/ photo id atu64::MAXin a hostile file overflows in debug builds; a NaN in develop settings makes a snapshot unreadable.🤖 Generated with Claude Code
Merging
unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: no new crate and nounsafe. Segment files that no snapshot lists are deleted, and only on request by an opener that holds the library lock (see Safety); the catalog's reader and writer threads are new.sync_folder_checked) are the last 8 commits of this branch.maintook catalog format 9 for the preview-only recheck (LR-IMP-FORMATS: recheck stale preview-only raws when a library opens (#662) #974,Photo.preview_checked), so compact records (Catalog: the log is compacted by the snapshot's size, not every 2000 records #800) are format 10 and segments (this PR) format 11; the fixtures arefixtures/v11-*, and the one-file fixture the upgrade tests read isv10.crates/catalog/src/stored.rs(StoredPhotofields); whichever lands second takes this from the integration build:Photo.left_in_fileis added to the stored form'sStoredPhotofields.Store::write_new_withand the segment writers incrates/catalog/src/(the hooks this PR also has a copy of); measured 26 Oct by a test merge of the two heads: conflicts incrates/catalog/src/lib.rs,segments.rs,store.rs,tests_segments.rsanddocs/whats-new.md. The default ofStore::write_new_within Catalog: the store can write files that a later write names, list its files and sync folders it can #2871 refuses (Unsupported), so every store that wraps or stands in for another (the test stores, and any store the restore code adds) must forwardwrite_new_withandsyncto its inner store. Take Catalog: the store can write files that a later write names, list its files and sync folders it can #2871's hooks and drop this PR's copy. Whichever lands second resolves it.Checklist
Summary by CodeRabbit
New Features
Documentation