"""Compile pinned, unmodified LMDB; exercise only fresh temporary databases.""" import argparse import hashlib import json import platform import subprocess import tempfile from datetime import datetime, timezone from pathlib import Path COMMIT = "3a29a24777c82a0165de813ae696a5068b5add30" HASHES = { "mdb.c": "2fd45dcef13f94ecc6650da19f341af38cceb53b9d3b88e854f621cc319dc1b1", "midl.c": "91110543f2e84c516188c1e3960b1f504e1c60a4766027a782349c000276ca93", "lmdb.h": "ea935082e5d5ea7ba685ee599c617f28353060710b0369d220a55f64bb07f1c2", "midl.h": "cef8236dc7dce9b5346d212d31e8330f9158bacabe270b14ab1e99745db118c6", "LICENSE": "310fe25c858a9515fc8c8d7d1f24a67c9496f84a91e0a0e41ea9975b1371e569", } def validate(rows): assert len(rows) == 24 for size in (1048576, 2097152): for format_ in ("plain", "compact"): groups = {} for sink in ("completed", "blocked"): group = [r for r in rows if (r["map_bytes"], r["format"], r["sink"]) == (size, format_, sink)] assert len(group) == 3 and group[0] == group[1] == group[2] row = groups[sink] = group[0] assert row["copy_rc"] == 0 and row["dead_readers_cleared"] == 0 assert row["source_bytes_verified"] and row["backup_bytes_verified"] assert row["map_unchanged"] and row["post_copy_committed"] == 64 assert row["prefix_bytes"] == 3 * row["page_bytes"] assert row["backup_bytes"] > row["prefix_bytes"] + row["pipe_capacity_bytes"] assert row["initial_extent_bytes"] <= row["during_extent_bytes"] <= row["after_extent_bytes"] <= size if sink == "blocked": assert row["failure_rc"] == row["retry_rc"] == -30792 assert 0 < row["committed"] < 256 else: assert row["committed"] == 256 and row["failure_rc"] == row["retry_rc"] == 0 assert groups["blocked"]["during_extent_bytes"] > groups["completed"]["during_extent_bytes"] assert groups["blocked"]["backup_bytes"] == groups["completed"]["backup_bytes"] plain = next(r for r in rows if r["map_bytes"] == size and r["format"] == "plain") compact = next(r for r in rows if r["map_bytes"] == size and r["format"] == "compact") assert compact["backup_bytes"] < plain["backup_bytes"] def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--lmdb", required=True, type=Path) parser.add_argument("--output", required=True, type=Path) args = parser.parse_args() src = args.lmdb.resolve() / "libraries/liblmdb" for name, expected in HASHES.items(): assert hashlib.sha256((src / name).read_bytes()).hexdigest() == expected, name probe = Path(__file__).resolve().with_name("probe.c") rows = [] with tempfile.TemporaryDirectory(prefix="hesela-copy-build-") as build: binary = Path(build) / "probe" command = ["cc", "-std=c11", "-O2", "-pthread", "-I", str(src), str(probe), str(src / "mdb.c"), str(src / "midl.c"), "-o", str(binary)] subprocess.run(command, check=True, capture_output=True, timeout=90) for _ in range(3): for size in (1048576, 2097152): for format_ in ("plain", "compact"): for sink in ("completed", "blocked"): with tempfile.TemporaryDirectory(prefix="hesela-copy-db-") as work: run = subprocess.run([str(binary), format_, sink, str(size)], cwd=work, text=True, capture_output=True, check=True, timeout=30) rows.append(json.loads(run.stdout)) validate(rows) report = { "schemaVersion": 1, "generatedAt": datetime.now(timezone.utc).isoformat(), "evidenceType": "controlled-synthetic-runtime-observation", "sourceCommit": COMMIT, "lmdbVersion": "0.9.33", "sourceHashes": HASHES, "sourceLicense": "OpenLDAP Public License 2.8; upstream source not redistributed", "sourceUrl": "https://github.com/LMDB/lmdb/tree/" + COMMIT, "probeSha256": hashlib.sha256(probe.read_bytes()).hexdigest(), "runnerSha256": hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), "environment": {"system": platform.system(), "release": platform.release(), "machine": platform.machine(), "python": platform.python_version(), "compiler": subprocess.check_output(["cc", "--version"], text=True).splitlines()[0], "temporaryDirectory": tempfile.gettempdir()}, "method": {"keys": 8, "valueBytes": 16384, "warmupOverwrites": 64, "attemptedOverwrites": 256, "postCopyOverwrites": 64, "repetitions": 3, "copyFlags": ["0", "MDB_CP_COMPACT"], "environmentFlags": [], "synchronization": "Read three pages from bounded pipe before writes; blocked treatment stops draining until write exhaustion; control drains and joins first.", "extentDefinition": "(me_last_pgno + 1) * page_size, not live bytes or physical allocation", "seed": "none; deterministic payloads"}, "limits": ["Pinned Linux C API, concurrent copy and writer, synthetic fixed-live-size workload.", "Pipe backpressure models a stalled sink, not measured network throughput.", "Backup reopened and every value checked; no crash, power loss, fsync or durable restore test.", "No source resize or in-place compaction. Counts depend on geometry and workload.", "Repetitions check repeatability, not statistical confidence or incident rates."], "cases": rows, } args.output.write_text(json.dumps(report, indent=2) + "\n") print(json.dumps({"validated": True, "cases": len(rows), "rows": rows[:8]})) if __name__ == "__main__": main()