Class DatabaseRepair
Turns an IntegrityReport into a reviewable RepairPlan, and applies one.
public static class DatabaseRepair
- Inheritance
-
DatabaseRepair
- Inherited Members
Remarks
The expensive, subtle part of repair — regenerating derived state from primary data in the correct order without trusting anything stale — is already built and rule-governed inside the engine's recovery net. What was missing was invocability, ordering control, and reporting: the net runs only at open, only on the crash path, cannot be asked to run, and reports into log lines. This type gives it a front door, a plan, and a receipt.
What repair will never do. Edit bytes inside a primary page (guessing at damaged content manufactures plausible data, which is strictly worse than a hole because it is undetectable afterwards). Splice a page from a backup into a live database (that produces a page consistent with an older generation of its neighbours, converting detectable corruption into undetectable corruption). Trust a derived structure to reconstruct primary data (an index is not a backup of the rows). Or delete user data to satisfy a derived constraint.
Properties
SupportedFormatRevision
The single on-disk format revision this build understands. Repair requires an exact match; scanning does not.
public static int SupportedFormatRevision { get; }
Property Value
Methods
Apply(string, RepairPlan, bool, bool, bool, Action<string>)
Applies a plan. The only mutating operation in the feature.
public static RepairOutcome Apply(string bundlePath, RepairPlan plan, bool allowLoss = false, bool backupFirst = true, bool dryRun = false, Action<string> regenerateDerived = null)
Parameters
bundlePathstringPath to the bundle to repair. Must not be open in another process.
planRepairPlanThe plan to apply.
allowLossboolConsent to lossy steps. Without it, every Excise step is skipped.
backupFirstboolCopy the bundle beside itself before the first mutation. Cheap insurance; on by default.
dryRunboolLog every step and execute none.
regenerateDerivedAction<string>Callback that opens and cleanly closes the database so the engine's rebuild net runs. Supplied by the caller because the repair module must not take a dependency on engine construction.
nullskips those steps.
Returns
Exceptions
- ArgumentNullException
bundlePathorplanisnull.- InvalidOperationException
The database changed since the plan was produced.
DescribeRevisionRefusal(int)
Why repair must refuse a database at this on-disk format revision, or null when it may proceed.
public static string DescribeRevisionRefusal(int found)
Parameters
foundintThe revision recorded in the database.
Returns
Remarks
Any mismatch, not merely a newer one (05-repair.md §7, OQ-7). Pre-alpha carries no compatibility
obligation, so this build knows exactly one revision and older and newer are equally un-understood. The asymmetry
people expect — "older is surely safe to read" — is the dangerous one: a revision bump is free to re-mean bytes an
older revision left unused, so an older page does not fail to decode, it decodes to a confident lie.
The verb matters. IntegrityScanner still scans and reports a mismatch as a finding — diagnosis
degrades, because refusing to diagnose is the opposite of what a scanner is for. Only mutation refuses, and it
refuses without an override: a --force here would be a switch whose only function is to let someone corrupt
a database this build cannot interpret, on a day they are already having a bad one.
Fingerprint(IntegrityReport)
A stable identity for "this database, in this state". Deliberately coarse: it must change when the database changes, and must not change merely because a scan ran twice.
public static string Fingerprint(IntegrityReport report)
Parameters
reportIntegrityReportThe report to fingerprint.
Returns
Plan(IntegrityReport)
Derives a repair plan from a report. Read-only: produces a description, changes nothing.
public static RepairPlan Plan(IntegrityReport report)
Parameters
reportIntegrityReportThe report to plan against.
Returns
Exceptions
- ArgumentNullException
reportisnull.