Skip to content

PERF-CATALOG: a put-off upgrade keeps one copy per attempt that worked and none for one that did not (stacked on #2968) - #2958

Closed
nledford wants to merge 9 commits into
storytold:mainfrom
nledford:catalog-snapshot-scale-p4c
Closed

nledford wants to merge 9 commits into
storytold:mainfrom
nledford:catalog-snapshot-scale-p4c

Conversation

@nledford

@nledford nledford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #800. Stacked on #2968 (a draft: compact records, format 10, stacked on #2957, #2951, #2948 and #2867 which is approved): this PR's own commit is ae75897435, the one on top of #2968's head 0634842c6e. Chain to main: #2867, #2948, #2951, #2957, #2968, then this. It waits for them to land and is a draft until then: GitHub shows their commits in the diff until they do.

This part used to change the code that keeps the files of a library whose upgrade is put off at open. #2867's later commits (in #2948's base) now do that, in their own way (the files are kept once, as the library was at open, and told once the snapshot that upgrades it is written), so this part is now only the tests that make that state by hand. The title still names the old change.

Problem

A library whose upgrade is put off at open (it stays in its old format, and a later snapshot upgrades it, keeping its files first) is the state #2867's upgrade code has to get right: attempts that fail must not pile copies up beside the library, a snapshot request on a store with no background writer must not keep the files twice, and a snapshot that took effect and then failed (the folder sync after the rename, or a worker that died after its commit) must leave the upgrade done, with the files it kept as its way back.

#2867 tested that through a library in format 6. With #2968 a library in a format before 10 that can't be upgraded is refused at open, so no library in a format this build reads is put off yet, and those tests have no state to start from (they are not repeated in #2968). The next catalog format (format 11, the segments) is the first that can be put off, and its tests start from a format 10 library. Until then the state has to be made by hand.

Change

crates/catalog/src/tests_upgrade_attempts.rs, a child of journal (it sets behind and behind_at, which only an open does), and the line in journal.rs that names it. No other code changes. Ten tests, each from a library made to look as an open that put its upgrade off leaves it:

  • failed attempts keep one pair of files, named as the open would have named them, written once, and tell nothing yet;
  • a later attempt that works keeps the library as it was at open (not the log as it has grown since), upgrades it, and tells the files once;
  • a snapshot that took effect but was reported as failed (written synchronously, by the background worker, or by a worker nobody waited for) is tried again without keeping the new format over the way back, and tells the old files;
  • a snapshot already in this build's format is the upgrade done; one in some other format is refused and keeps nothing;
  • a worker that dies before, or after, its commit leaves the files for the next attempt;
  • a snapshot written but whose log can't be emptied is the upgrade done all the same;
  • a disk that can't be read when the files are to be kept keeps nothing and is tried again;
  • a background request on a store with no writer keeps the files once.

Not in this PR: anything that puts a library in that state (the next catalog format), and any change to the code that keeps the files.

How it was checked

  • cargo xtask ci passes on this branch, rebased on current main: not run locally for this draft (the hosted CI gate runs it once its parents have landed); at ae75897435 cargo fmt --all --check, cargo check --workspace --all-targets and clippy with -D warnings pass, cargo test -p lightcraft-catalog --lib passes (308 passed, 3 ignored) and cargo test -p lightcraft-engine --lib for the library and persistence tests passes (109 passed, 1 ignored)
  • A test that fails without this change: the tests are of code that is already in the base of this branch, so there is no old behavior to run them against; instead each rule was broken in a throwaway copy of journal.rs and the ten tests run. Keeping the files again on every try (kept_pending ignored) fails failed_attempts_keep_one_pair, a_worker_that_dies_keeps_the_files_for_the_next_attempt and a_background_request_without_a_writer_keeps_the_files_once; clearing behind without telling the files (upgraded_later replaced by behind = None after a written snapshot) fails six tests, among them an_upgrade_whose_log_cannot_be_emptied_is_done_and_tells and a_later_attempt_upgrades_and_tells_what_it_kept; treating an unreadable disk as an empty one fails a_disk_that_cannot_be_read_keeps_nothing_and_is_tried_again
  • User-visible change: ran the app and looked at the result: not applicable, nothing changes on screen

No catalog compatibility check is needed: no file is written or read differently (the format stays 10, and the state these tests make can't be reached by any format this build reads).

A reviewer with a clean context read the rebase of this part and the ones above and below it (two rounds): no data-loss finding; its findings on the tests (three test knobs with nothing using them, so three paths untested) were fixed with the three tests above.

Screenshots

None; nothing changes on screen.

Merging

Checklist

Opening a library in an older format rewrites it in this build's, and older
builds then refuse it: a one-way step. Journal::open now first keeps the
files the library was, byte for byte, as catalog.snap.v<format>-<seq> and
catalog.log.v<format>-<seq>, and reports their names (LoadReport::kept).
Put back under their own names they are the library as the older build
left it (docs/catalog-persistence.md, Going back to an older version).

A library whose files can't be kept is not upgraded (it opens as it is; the
next open tries again), and an upgrade that fails leaves no copy; kept files
stay whenever the upgrade may have been written. A library whose log was
damaged is an upgrade like any other: its snapshot is kept beside the
damaged log, and it is refused if that log can't be replaced. The person is
told once where the library as it was is kept. A library left in its old format
at open is upgraded by a later snapshot (compaction, or closing), which keeps its
files first and is not written when it can't. The browser build keeps none
(Store::keeps_replaced_formats).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@nledford
nledford force-pushed the catalog-snapshot-scale-p4c branch from e9663de to e258a98 Compare October 25, 2026 19:05
@nledford nledford changed the title PERF-CATALOG: a put-off upgrade keeps one copy per attempt that worked and none for one that did not (stacked on #2957) PERF-CATALOG: a put-off upgrade keeps one copy per attempt that worked and none for one that did not (stacked on #2968) Oct 25, 2026
@nledford

Copy link
Copy Markdown
Contributor Author

Rebased onto the new #2968 (the second half of the old #2957, now split), head e258a98366; no change of its own.

nledford and others added 8 commits October 26, 2026 00:41
A library left in an older format at open keeps its files when a later snapshot upgrades it. Those files are the library as it was at open (the snapshot, and the log up to its length then), under the names the open would have given them, so what is appended meanwhile in this build's ops is never in them. The snapshot hands the names on (Journal::take_kept) and the engine tells the person once, as the open does. Appends are not refused meanwhile (a library whose files can't be copied would save nothing): the module doc and the persistence doc say so.
…he later upgrade's tests and docs are exact

A library left in its old format whose snapshot is in this build's format already (a write that landed and reported a failure) no longer fails every snapshot until it is reopened: it is the upgrade done, with nothing to keep. Tests now cover the files kept at open's length and seq when changes were made before the first attempt, the snapshot that landed after its files were kept, no second copy on a retry, the background worker's result and telling once. The docs say what the kept files hold when a session already added changes in the old format, what going back loses, and that a snapshot at close or a library switch has no one to tell.
A develop setting a record leaves out reads as its default, so a default
that changed in the code would change every photo relying on it. catalog.snap
now states the defaults it was written with ("defaults"), and they cover the
log beside it. A build whose own defaults differ reads the library's settings
over the library's (stored::reading_over) and rewrites it with its own before
anything is appended (LoadReport::other_defaults); a library that only lacks
newer settings, or knows more, is read as it is. What a missing value reads as
in this build is pinned by a test (develop_defaults.json).

Every record is still written in full, and the format stays 9: older builds
ignore the extra header field. This is the reading half of the compact records
of the next change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lts fails

The sentence said the library's files still state its own defaults. That holds when catalog.snap could not be written; when it was written and only the log could not be emptied, they state this build's, and the log's records are skipped as stale.
…fixture

The catalog formats were a table in journal.rs's module docs that nothing read.
They are now one list in code, journal::FORMATS: each row has the format's number,
the build that wrote it first, what it adds, and whether it adds an op (NEW_OP) or
only fields (FIELDS). VERSION is the newest row this build has. A test holds that
the numbers run 1.. without a gap, that a row that adds an op names it, and that the
newest op's format is the newest row that adds one (what NEWEST_FIELDS held by hand).

Every format from 6 on has a fixture, a small library written by the build of that
format, which every later build must open as it was: fixtures v7 to v9 are new (v6
was there), written by their builds from the fixture library of tests_stored.rs.

Nothing is written or read differently: VERSION stays 9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…defaults

The writing half of compact records, for develop settings only and with no
caller yet: the settings of a photo, and those of its history steps, versions
and import look, stored as their difference from the defaults ({} for an
unedited photo). A value is left out only where that reads back the same
(worked out from the types on first use: not the rendering process, not single
fields of the crop rectangle), every difference is read back before it is
written, and a negative zero is kept. writing_full() stores settings whole while
a library's header lacks a setting this build has, and states_every_setting()
says when that is so.

Nothing writes this form yet: records stay as they are, and the format stays 9.
The next change names these functions from the ops, stores the photos with them and brings
catalog format 10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A photo's record in catalog.snap / catalog.log states only what was set:
unset fields of the photo and its metadata are left out, and develop settings
(the photo's, its history steps', versions' and import look's) are stored as
their difference from the defaults, with the stored form of the previous change.
A record of a photo with no metadata goes from 3.2 kB to 0.2 kB. Reading is
unchanged, so formats 1-9 load as they are and are rewritten on open; the public
JSON of a photo (catalog.query, Local fingerprints, preview-cache keys) is
unchanged.

Format 10 is the first that leaves values out, so a library that is in a format
before 10 (also one that states defaults), or states other ones than this
build's, and can't be upgraded, is not opened (it is left as it was, and the
error says why). A library in format 10 that lacks a setting this build has is
rewritten to state it before a compact record is appended; where that can't be
written, its records state develop settings whole until a snapshot is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s at open, and the tests make the state by hand

A library whose upgrade is put off at open (it stays in its old format, and a later
snapshot upgrades it, keeping its files first) keeps one pair of copies however many
attempts fail, writes them once, tells them once the snapshot that works is written,
and takes a snapshot that landed all the same as the upgrade done: that is what the
base of this branch does. No format this build reads and upgrades from puts a library
in that state yet (a format before 10 is refused when it can't be upgraded), so the
tests that had it from an old format's library make the state by hand, for the next
format that can be put off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nledford
nledford force-pushed the catalog-snapshot-scale-p4c branch from e258a98 to ae75897 Compare October 26, 2026 07:56
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 26, 2026
…mat 11's one-file store

Moved from storytold#2958 (ae75897, catalog-snapshot-scale-p4c), whose own change had become only these tests after storytold#2867. `tests_upgrade_attempts.rs` is the file as it was there, with the same `mod` line in `journal.rs`, and its opening comment no longer says that no format can be put off (a format 10 library can be on this build).

Ten tests that set up a put-off upgrade's state by hand (the library as it was at open, behind) and check that it keeps one pair of files however many attempts fail, writes them once, tells them once the snapshot that works is written, and takes a snapshot that landed all the same as the upgrade done. The store they use is one file, as the browser's is: they don't cover the segments of format 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nledford

Copy link
Copy Markdown
Contributor Author

Folded into #2983 (c29f21b): this PR's own change had become only tests_upgrade_attempts.rs after #2867, and #2983 covers the same upgrade path. #2978 now sits on #2968.

@nledford nledford closed this Oct 26, 2026
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 26, 2026
…mat 11's one-file store

Moved from storytold#2958 (ae75897, catalog-snapshot-scale-p4c), whose own change had become only these tests after storytold#2867. `tests_upgrade_attempts.rs` is the file as it was there, with the same `mod` line in `journal.rs`, and its opening comment no longer says that no format can be put off (a format 10 library can be on this build).

Ten tests that set up a put-off upgrade's state by hand (the library as it was at open, behind) and check that it keeps one pair of files however many attempts fail, writes them once, tells them once the snapshot that works is written, and takes a snapshot that landed all the same as the upgrade done. The store they use is one file, as the browser's is: they don't cover the segments of format 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 27, 2026
…mat 11's one-file store

Moved from storytold#2958 (ae75897, catalog-snapshot-scale-p4c), whose own change had become only these tests after storytold#2867. `tests_upgrade_attempts.rs` is the file as it was there, with the same `mod` line in `journal.rs`, and its opening comment no longer says that no format can be put off (a format 10 library can be on this build).

Ten tests that set up a put-off upgrade's state by hand (the library as it was at open, behind) and check that it keeps one pair of files however many attempts fail, writes them once, tells them once the snapshot that works is written, and takes a snapshot that landed all the same as the upgrade done. The store they use is one file, as the browser's is: they don't cover the segments of format 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 30, 2026
…mat 11's one-file store

Moved from storytold#2958 (ae75897, catalog-snapshot-scale-p4c), whose own change had become only these tests after storytold#2867. `tests_upgrade_attempts.rs` is the file as it was there, with the same `mod` line in `journal.rs`, and its opening comment no longer says that no format can be put off (a format 10 library can be on this build).

Ten tests that set up a put-off upgrade's state by hand (the library as it was at open, behind) and check that it keeps one pair of files however many attempts fail, writes them once, tells them once the snapshot that works is written, and takes a snapshot that landed all the same as the upgrade done. The store they use is one file, as the browser's is: they don't cover the segments of format 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 30, 2026
…mat 11's one-file store

Moved from storytold#2958 (ae75897, catalog-snapshot-scale-p4c), whose own change had become only these tests after storytold#2867. `tests_upgrade_attempts.rs` is the file as it was there, with the same `mod` line in `journal.rs`, and its opening comment no longer says that no format can be put off (a format 10 library can be on this build).

Ten tests that set up a put-off upgrade's state by hand (the library as it was at open, behind) and check that it keeps one pair of files however many attempts fail, writes them once, tells them once the snapshot that works is written, and takes a snapshot that landed all the same as the upgrade done. The store they use is one file, as the browser's is: they don't cover the segments of format 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 30, 2026
…mat 11's one-file store

Moved from storytold#2958 (ae75897, catalog-snapshot-scale-p4c), whose own change had become only these tests after storytold#2867. `tests_upgrade_attempts.rs` is the file as it was there, with the same `mod` line in `journal.rs`, and its opening comment no longer says that no format can be put off (a format 10 library can be on this build).

Ten tests that set up a put-off upgrade's state by hand (the library as it was at open, behind) and check that it keeps one pair of files however many attempts fail, writes them once, tells them once the snapshot that works is written, and takes a snapshot that landed all the same as the upgrade done. The store they use is one file, as the browser's is: they don't cover the segments of format 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant