cache_encryption_sweep
Encrypts every plaintext SQLite store at startup, when cache encryption is on.
The sweep finds the stores from their known roots, resolves the cache key once, records its key id beside the caches, and migrates each plaintext store to SQLCipher in turn. A store that can't be migrated stays plaintext and working, and is tried again at the next start.
Nothing is migrated without a usable key, or with a key whose id doesn't match
the one recorded. An uploaded-MRN store still in the diskcache format is
converted by opening it, which imports it into an encrypted strings.sqlite.
The sweep never raises. It reports a cache_encryption_migration event for each
store migrated, skipped or failed, and one cache_encryption_sweep event
however it ends. A caller whose telemetry isn't set up yet holds the events
(report=False) and sends them with report_sweep once it is. A process with
no telemetry of its own (the orchestrator) saves them with save_sweep_report
for the next process that has it to send with report_saved_sweep.
Module
Functions
report_saved_sweep
def report_saved_sweep(cache_dir: Path | None = None) ‑> bool:Sends the events a sweep in another process saved, if any, then deletes them.
The report is claimed by renaming it, so of several processes only one sends it. A report that can't be read is deleted. Never raises.
Arguments
cache_dir: Where the report was left; the configured cache dir by default.
Returns Whether a saved report was sent.
report_sweep
def report_sweep(summary: SweepSummary) ‑> None:Sends a sweep's events: one per store in its results, then its own.
Never raises.
run_cache_encryption_sweep
def run_cache_encryption_sweep( *, pod_names: Sequence[str] | None = None, project_db_dirs: Sequence[Path] = (), report: bool = True, on_encrypting: Callable[[], None] | None = None,) ‑> SweepSummary:Encrypts every plaintext store, when cache encryption is on.
With encryption off or unset, it looks at no store. The process's own key
check (check_cache_key_at_startup) is left to the caller.
Arguments
pod_names: Only these pods' background caches;Nonefor every pod's.project_db_dirs: The directories holding project databases.report: Whether to send the sweep's events now. Without, pass the summary toreport_sweeporsave_sweep_reportlater.on_encrypting: Called once before the first store is encrypted, and only if there is one to encrypt.
Returns What the sweep did. This never raises.
save_sweep_report
def save_sweep_report(summary: SweepSummary, cache_dir: Path | None = None) ‑> None:Leaves a sweep's events in the cache dir for another process to send.
For a process with no telemetry of its own. A report not yet sent is replaced. Never raises.
Arguments
summary: The sweep's summary, fromreport=False.cache_dir: Where to leave it; the configured cache dir by default.
Classes
SweepSummary
class SweepSummary( enabled: bool | None, opted_out: bool, key_reason: str | None = None, migrated: int = 0, already_encrypted: int = 0, skipped_low_disk: int = 0, failed: int = 0, total_bytes: int = 0, duration_seconds: float = 0.0, results: list[tuple[StoreType, MigrationResult]] = [],):What one sweep did.
Attributes
enabled:BITFOUNT_CACHE_ENCRYPTION_ENABLEDas set, orNonewhen it is unset and the release default applies.opted_out: Whether the site turned encryption off.key_reason: Why nothing was migrated for want of a usable key, as a short code;Noneotherwise.migrated: Stores migrated.already_encrypted: Stores found already encrypted.skipped_low_disk: Stores skipped for lack of disk space.failed: Stores that couldn't be migrated.total_bytes: The migrated stores' total size before migrating.duration_seconds: How long the sweep took.results: Each store migrated, skipped for low disk, or failed, with what happened to it; the stores reported one by one.
Variables
-
already_encrypted : int
-
duration_seconds : float
-
enabled : bool | None
-
failed : int
-
key_reason : str | None
-
migrated : int
-
opted_out : bool
-
results : list[tuple[StoreType, MigrationResult]]
-
skipped_low_disk : int
-
total_bytes : int