s365b.core.generation¶
Catalog generation: never reclaim space the catalog does not know about.
Retention deletes repository data that no catalog entry refers to. That is only safe if the catalog database knows everything in the repository. It does not after a database loss (a new server connected to an existing repository) or after restoring an older database dump: data written since looks unreferenced, and reclaiming it would delete those backups.
So each repository has a generation, a counter kept twice: in the database
(repository.generation) and in the repository (generation/). Every
catalog commit that may point at newly written content raises the
database’s number in the same transaction, then writes it to the
repository. A dump taken before that commit therefore holds a lower number
than the repository: restored, it is recognised as behind, and retention
keeps every pack (it still prunes catalog entries, which only touches the
database). Content written but never committed (a crash between flushing
and committing) is referenced by no database at all, so reclaiming it is
safe.
The repository keeps one file per number written, and reading takes the highest: two writers finishing out of order cannot lower it.
One gap remains: if the process dies between a commit and writing the repository’s number, and a dump from just before that commit is restored, the difference goes unnoticed. What it exposes is only the content that one lost commit stored (possibly several items): the restored database refers to none of it, so it can be reclaimed. The next backup reads those items again from the state saved before, but only as they are at the source then: a version since changed or deleted there is not recovered. Writing the number before the commit would close the gap but open a worse one: a commit that then fails would leave the repository ahead, and retention stopped until a newer dump is restored, which does not exist.
Backups do not raise the number while the repository is ahead: that would hide the mismatch.
Attributes¶
Functions¶
|
Raise the database's generation within a catalog commit. |
|
Whether the repository holds data newer than this database knows. |
|
Mark a repository connected to a new database as holding unknown data. |
Module Contents¶
- async s365b.core.generation.bump(s: sqlalchemy.ext.asyncio.AsyncSession, repository_fk: int, on_disk: int) int | None[source]¶
Raise the database’s generation within a catalog commit.
Call it last in the transaction (it holds the repository’s row until the commit), then write the result with
Repository.write_generation()once the transaction has committed.- Parameters:
s – The session of the catalog commit.
repository_fk – Repository row ID.
on_disk – The repository’s generation, read before the transaction.
- Returns:
The new generation, or
Noneif the repository is ahead of this database and was left alone.
- async s365b.core.generation.catalog_behind(db: s365b.db.session.Database, repository_fk: int, repo: s365b.storage.Repository) int | None[source]¶
Whether the repository holds data newer than this database knows.
- Parameters:
db – Database.
repository_fk – Repository row ID.
repo – The open repository.
- Returns:
The repository’s generation if it is ahead of the database, else
None.
- async s365b.core.generation.mark_connected(repo: s365b.storage.Repository) None[source]¶
Mark a repository connected to a new database as holding unknown data.
A repository from before generations has none; if it holds data, it is given generation 1, so that this database (generation 0) is behind.
- Parameters:
repo – The repository just connected.