Table of Contents

Class DatabaseRepair

Namespace
Typhon.Engine
Assembly
Typhon.Engine.dll

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

int

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

bundlePath string

Path to the bundle to repair. Must not be open in another process.

plan RepairPlan

The plan to apply.

allowLoss bool

Consent to lossy steps. Without it, every Excise step is skipped.

backupFirst bool

Copy the bundle beside itself before the first mutation. Cheap insurance; on by default.

dryRun bool

Log every step and execute none.

regenerateDerived Action<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. null skips those steps.

Returns

RepairOutcome

Exceptions

ArgumentNullException

bundlePath or plan is null.

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

found int

The revision recorded in the database.

Returns

string

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

report IntegrityReport

The report to fingerprint.

Returns

string

Plan(IntegrityReport)

Derives a repair plan from a report. Read-only: produces a description, changes nothing.

public static RepairPlan Plan(IntegrityReport report)

Parameters

report IntegrityReport

The report to plan against.

Returns

RepairPlan

Exceptions

ArgumentNullException

report is null.