"""Exact synthetic RAID6 placement model, not a device failure-rate estimator. Four members, four one-symbol stripes, member 0 unavailable throughout. Each of the three survivors has exactly one known erasure. All other symbols are correct and version-consistent. No repair occurs between observations. """ import argparse from collections import Counter from fractions import Fraction import hashlib from itertools import permutations, product import json from pathlib import Path STRIPES = 4 SURVIVORS = 3 PARITY = 2 MISSING_MEMBERS = 1 def vector(values, name): if not isinstance(values, (list, tuple)) or len(values) != SURVIVORS: raise ValueError(f"{name} must contain three positions") if any(type(value) is not int or not 0 <= value < STRIPES for value in values): raise ValueError(f"{name} entries must be integers from zero through three") return tuple(values) def stripe_erasures(positions, offsets=(0, 0, 0)): """Offset d maps local position p to stripe (p - d) modulo four.""" positions = vector(positions, "positions") offsets = vector(offsets, "offsets") extra = Counter((position - offset) % STRIPES for position, offset in zip(positions, offsets)) return tuple(MISSING_MEMBERS + extra[stripe] for stripe in range(STRIPES)) def failure_stripes(positions, offsets=(0, 0, 0)): return tuple(stripe for stripe, erasures in enumerate(stripe_erasures(positions, offsets)) if erasures > PARITY) def laws(): return { "aligned": [(u, u, u) for u in range(STRIPES)], "independent": list(product(range(STRIPES), repeat=SURVIVORS)), "separated": list(permutations(range(STRIPES), SURVIVORS)), "offset_aligned": [ (u, (u + 1) % STRIPES, (u + 2) % STRIPES) for u in range(STRIPES) ], } def exact(value): return {"numerator": value.numerator, "denominator": value.denominator} def summarize(name, law_name, offsets): observations = laws()[law_name] failures = [failure_stripes(row, offsets) for row in observations] fail_count = sum(bool(failed) for failed in failures) lost_stripes = sum(len(failed) for failed in failures) marginals = [ [exact(Fraction(sum(row[disk] == position for row in observations), len(observations))) for position in range(STRIPES)] for disk in range(SURVIVORS) ] return { "id": name, "law": law_name, "local_to_stripe_offsets": list(offsets), "equally_weighted_states": len(observations), "states_with_unrecoverable_stripe": fail_count, "probability_any_unrecoverable_stripe": exact(Fraction(fail_count, len(observations))), "expected_unrecoverable_stripe_fraction": exact( Fraction(lost_stripes, len(observations) * STRIPES)), "per_survivor_local_position_marginals": marginals, "observations": [ {"local_positions": list(row), "unrecoverable_stripes": list(failed)} for row, failed in zip(observations, failures) ], } def results(): cases = [ ("aligned_standard", "aligned", (0, 0, 0)), ("independent_standard", "independent", (0, 0, 0)), ("separated_standard", "separated", (0, 0, 0)), ("aligned_offset", "aligned", (0, 1, 2)), ("offset_aligned_offset", "offset_aligned", (0, 1, 2)), ] return { "schema_version": 1, "evidence_type": "exact_synthetic_enumeration", "assumptions": { "members": 4, "stripes": STRIPES, "symbols_per_member_per_stripe": 1, "parity_equivalents": PARITY, "missing_member": 0, "known_erasures_per_survivor": 1, "remaining_symbols_correct_and_consistent": True, "repair_during_window": False, "empirical_calibration": False, "addresses_are_model_indices_not_physical_sectors": True, }, "cases": [summarize(*case) for case in cases], "limits": [ "Counts of missing symbols, not bit errors or datasheet UBER.", "One fixed degraded observation window; no time-to-failure or annual probability.", "Known erasures, not unidentified corruption or Byzantine behavior.", "No controller, filesystem, scrub, rebuild-progress or hardware experiment.", "No data-loss probability inferred for real arrays; full-stripe recovery only.", "Cyclic offsets are an abstract bijection, not a supported RAID reconfiguration.", ], "source_context": [ {"title": "An Analysis of Data Corruption in the Storage Stack", "year": 2008, "locator": "sections 2.2, 4.3.2, 6.1.1 and 6.2", "url": "https://static.usenix.org/events/fast08/tech/full_papers/bairavasundaram/bairavasundaram_html/index.html", "accessed": "2026-10-24"}, {"title": "Understanding latent sector errors and how to protect against them", "year": 2010, "locator": "sections 2-4", "url": "https://www.usenix.org/legacy/events/fast10/tech/full_papers/schroeder.pdf", "accessed": "2026-10-24"}, {"title": "The mathematics of RAID-6", "revision": "2011-12-20", "locator": "sections 2 and 4", "url": "https://mirrors.edge.kernel.org/pub/linux/kernel/people/hpa/raid6.pdf", "accessed": "2026-10-24"}, ], "model_sha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true") parser.add_argument("--output", type=Path, default=Path(__file__).with_name("results.json")) args = parser.parse_args() encoded = json.dumps(results(), indent=2, sort_keys=True) + "\n" if args.check: if not args.output.exists() or args.output.read_text() != encoded: raise SystemExit("results differ: regenerate with model.py") print("Exact results and model hash match.") else: args.output.write_text(encoded) print(f"Generated {len(results()['cases'])} exact model cases.") if __name__ == "__main__": main()