Tie the track tooling to keys, sets and a clean series

reconcile-inject.sh wrote an orphan under a key whose uuid differed
from the id it printed, so the demo could only compare counts; it now
uses one uuid for both, and the dry-run check compares the found and
the injected sets per class. The heal step returns the original bytes
under one quarantined key and random bytes of the same length under
another, and checks that only the first leaves the quarantine. The
load phase sums rechecked over its passes, and a new step stops a pass
hanging on a paused S3 with docker stop and checks exit code 143 within
seconds and a free lock afterwards.

reconcile_track.py cost clears the run files of the previous series and
measures 1k, 10k, 30k and 100k with --deep everywhere. The scenarios
record date, commit and docker inspect of the replicas or of S3 at the
moment they are down. make load-evidence and make clean-clone-evidence
rerun the message load and the clean clone block with raw output, and
make upload-memory passes ARGS to reproduce the run directories.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
This commit is contained in:
Artyom
2026-10-30 09:01:39 +03:00
co-authored by Claude Opus 5.5
parent 3de1dcdc84
commit f1ee385a1b
8 changed files with 241 additions and 34 deletions
+72 -17
View File
@@ -174,9 +174,11 @@ def faults(c, check, pre):
dry = reconcile("--dry-run", "--deep", *FLAGS)
save("dry-run.json", dry)
after_dry = oracle("--grace", str(GRACE), "--deep")
named = {k: sorted(s.rsplit("/", 1)[-1] for s in dry["samples"].get(k, [])) for k in injected}
check(
"dry-run находит каждый внедрённый класс",
pick(dry["found"], expected) == expected,
"dry-run находит каждый внедрённый класс, и найдено ровно внедрённое",
pick(dry["found"], expected) == expected
and named == {name: sorted(ids) for name, ids in injected.items()},
expected=expected,
found=dry["found"],
)
@@ -241,23 +243,30 @@ def faults(c, check, pre):
meta["status"] == 200 and blocked["status"] == 404 and intact["bytes"] == FIXTURE,
)
bucket = os.environ.get("S3_BUCKET", "messenger-attachments")
compose(
"run",
"--rm",
"--no-deps",
"-T",
"s3-cli",
"pipe",
f"root/{bucket}/attachments/{linked[0]}",
stdin=FIXTURE,
)
for attachment, data in ((linked[0], FIXTURE), (linked[1], os.urandom(len(FIXTURE)))):
compose(
"run",
"--rm",
"--no-deps",
"-T",
"s3-cli",
"pipe",
f"root/{bucket}/attachments/{attachment}",
stdin=data,
)
healed = reconcile("--apply", *FLAGS)
save("healed.json", healed)
restored = c.call("GET", f"/api/v1/attachments/{linked[0]}/content", 200, actor=bob)
foreign = c.call("GET", f"/api/v1/attachments/{linked[1]}/content", 404, actor=bob)
check(
"восстановленный объект выходит из карантина",
healed["fixed"]["healed"] == 1 and restored["bytes"] == FIXTURE,
"вернули те же байты — карантин снят; другие байты той же длины — остался",
healed["fixed"]["healed"] == 1
and healed["samples"].get("healed") == [linked[0]]
and linked[1] in healed["samples"].get("quarantined", [])
and restored["bytes"] == FIXTURE
and foreign["status"] == 404,
fixed=healed["fixed"],
s3_get=healed["cost"]["requests"]["s3_get"],
)
return {"injected": injected, "targets": targets, "linked": linked}
@@ -294,6 +303,44 @@ def single(check):
)
def interrupt(check):
name = f"lab4-reconcile-sigterm-{os.getpid()}"
compose("pause", "s3")
try:
cmd = ["docker", "compose", "run", "--rm", "--no-deps", "-T", "--name", name, "reconciler"]
runner = subprocess.Popen(
[*cmd, "--apply", *FLAGS],
cwd=ROOT,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
time.sleep(4)
state = must(["docker", "inspect", "-f", "{{.State.Status}} {{.HostConfig.Init}}", name])
started = time.monotonic()
must(["docker", "stop", name])
stopped = round(time.monotonic() - started, 2)
code = runner.wait(timeout=60)
finally:
compose("unpause", "s3")
compose("up", "-d", "--wait", "--no-deps", "s3")
after = reconcile("--dry-run", *FLAGS)
status, init = state.split()
report = {
"s3": "paused",
"state_before_stop": status,
"init": init,
"stop_seconds": stopped,
"exit_code": code,
"next_pass_skipped": after["skipped"],
}
save("sigterm.json", report)
check(
"SIGTERM: идущий проход останавливается за секунды, блокировка освобождена",
status == "running" and code == 143 and stopped < 5 and not after["skipped"],
**report,
)
def outage(check):
before = oracle("--grace", str(GRACE))
compose("stop", "s3")
@@ -388,6 +435,10 @@ def under_load(c, check, base, seconds, threads):
for status, _ in results:
statuses[str(status)] = statuses.get(str(status), 0) + 1
fixed = {name: sum(r["fixed"][name] for r in runs) for name in FIXABLE}
rechecked = {}
for r in runs:
for name, count in r["rechecked"].items():
rechecked[name] = rechecked.get(name, 0) + count
seen = {name: sum(r["found"][name] for r in runs) for name in ("orphan_fresh", "pending_fresh")}
summary = {
"seconds": seconds,
@@ -399,6 +450,7 @@ def under_load(c, check, base, seconds, threads):
"run_seconds": [r["cost"]["seconds"] for r in runs],
"fixed_total": fixed,
"fresh_seen_total": seen,
"rechecked_total": rechecked,
"errors": sum(r["errors"] for r in runs),
"skipped": sum(1 for r in runs if r["skipped"]),
"injected_before_load": {"orphan": len(orphans), "pending_stale": len(intents)},
@@ -439,6 +491,7 @@ def demo(args):
result = {"started_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "commit": head()}
result["faults"] = faults(c, check, pre)
single(check)
interrupt(check)
outage(check)
under_load(c, check, args.base_url, args.load_seconds, args.load_threads)
result.update(seconds=round(time.monotonic() - started, 1), checks=check.items, ok=check.ok)
@@ -642,7 +695,9 @@ def table(rows):
def cost(args):
out = OUT / "cost"
out.mkdir(parents=True, exist_ok=True)
(out / "disturbed").mkdir(parents=True, exist_ok=True)
for stale in [*out.glob("n*-*.json"), *(out / "disturbed").glob("*.json")]:
stale.unlink()
rows = int(psql("SELECT count(*) FROM attachments"))
if rows > args.sizes[0]:
raise SystemExit(f"на стенде уже {rows} вложений: make reset-data && make up && make test")
@@ -701,9 +756,9 @@ def main():
d.add_argument("--load-seconds", type=int, default=75)
d.add_argument("--load-threads", type=int, default=3)
k = sub.add_parser("cost", help="cost of a pass for N objects, repeated")
k.add_argument("--sizes", type=int, nargs="+", default=[1000, 10000, 30000])
k.add_argument("--sizes", type=int, nargs="+", default=[1000, 10000, 30000, 100000])
k.add_argument("--repeats", type=int, default=3)
k.add_argument("--deep-max", type=int, default=30000)
k.add_argument("--deep-max", type=int, default=100000)
k.add_argument("--page-compare", type=int, default=10000)
k.add_argument("--settle", type=float, default=10)
k.add_argument("--s3-memory", default="3g")