add level 5
This commit is contained in:
@@ -82,6 +82,9 @@ def main():
|
||||
check(orphan in report["fresh_unreferenced"] and not report["deleted"], "grace period ignored")
|
||||
report = reconcile("--apply", "--grace-seconds", "0")
|
||||
check(report["deleted"] == [orphan], "aged orphan was not deleted safely")
|
||||
report = reconcile("--apply", "--grace-seconds", "0")
|
||||
check(orphan not in report["deleted"] and orphan not in report["orphan_candidates"],
|
||||
"second repair run was not idempotent")
|
||||
check(client.call("GET", "/api/v1/attachments/" + protected["id"] + "/content", actor=bob)["bytes"] == image,
|
||||
"reconciler deleted a referenced object")
|
||||
|
||||
@@ -96,7 +99,9 @@ def main():
|
||||
s3_code("put", missing_key, image)
|
||||
check(client.call("GET", "/api/v1/attachments/" + missing["id"] + "/content", actor=bob)["bytes"] == image,
|
||||
"test object was not restored")
|
||||
print("PASS: dry-run, grace period, orphan deletion and missing-object reporting", flush=True)
|
||||
report = reconcile("--grace-seconds", "0")
|
||||
check(expected not in report["missing_objects"], "restored object remained missing on second scan")
|
||||
print("PASS: S3-side missing object, dry-run, grace period and idempotent orphan repair", flush=True)
|
||||
|
||||
# Inject a process-equivalent failure after PUT directly into the configured
|
||||
# replica. The public load balancer may correctly select the healthy peer,
|
||||
@@ -127,7 +132,7 @@ else:
|
||||
check(injected, "injected post-PUT failure did not create a detectable orphan")
|
||||
report = reconcile("--apply", "--grace-seconds", "0")
|
||||
check(set(injected).issubset(report["deleted"]), "reconciler did not clean injected orphan")
|
||||
print("PASS: post-PUT/pre-DB injected failure leaves no permanent orphan", flush=True)
|
||||
print("PASS: PostgreSQL-side post-PUT/pre-DB failure is repaired without deleting references", flush=True)
|
||||
finally:
|
||||
environment["UPLOAD_FAULT_AFTER_S3_PUT"] = "0"
|
||||
subprocess.run(["docker", "compose", "up", "-d", "--force-recreate", "--no-deps", "api-a"],
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Measure repeatable reconciler inventory cost for two controlled S3 sizes."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import statistics
|
||||
import subprocess
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import arguments, check, run
|
||||
|
||||
|
||||
def compose(*args, input=None) -> str:
|
||||
return subprocess.check_output(["docker", "compose", *args], cwd=ROOT, text=True, input=input)
|
||||
|
||||
|
||||
def reconcile() -> dict:
|
||||
output = compose("--profile", "maintenance", "run", "--rm", "--no-deps", "reconcile",
|
||||
"--grace-seconds", "3600")
|
||||
return json.loads(next(line for line in reversed(output.splitlines()) if line.startswith("{")))
|
||||
|
||||
|
||||
def mutate(action: str, keys: list[str]) -> None:
|
||||
code = """from src.storage.s3 import S3Settings, S3Store
|
||||
import json, sys
|
||||
s3 = S3Store(S3Settings.load())
|
||||
try:
|
||||
for key in json.load(sys.stdin):
|
||||
if sys.argv[1] == 'put':
|
||||
s3.client.put_object(Bucket=s3.settings.bucket, Key=key, Body=b'track-2-benchmark')
|
||||
else:
|
||||
s3.client.delete_object(Bucket=s3.settings.bucket, Key=key)
|
||||
finally:
|
||||
s3.client.close()
|
||||
"""
|
||||
compose("run", "--rm", "--no-deps", "s3-init", "/app/.venv/bin/python", "-c", code, action,
|
||||
input=json.dumps(keys))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
arguments(__doc__) # Keeps the common --base-url/--ca-file command interface.
|
||||
results = []
|
||||
for requested in (32, 128):
|
||||
prefix = f"originals/track2-benchmark-{uuid.uuid4().hex}-"
|
||||
keys = [prefix + str(index) for index in range(requested)]
|
||||
try:
|
||||
mutate("put", keys)
|
||||
reports = [reconcile() for _ in range(3)]
|
||||
for report in reports:
|
||||
check(set(keys).issubset(report["fresh_unreferenced"]),
|
||||
"benchmark objects were not included in the inventory")
|
||||
check(not set(keys) & set(report["orphan_candidates"]),
|
||||
"grace period classified fresh benchmark objects as deletable")
|
||||
seconds = [report["scan_metrics"]["total_seconds"] for report in reports]
|
||||
results.append({
|
||||
"added_unreferenced_objects": requested,
|
||||
"runs": 3,
|
||||
"s3_objects_scanned": reports[-1]["s3_objects"],
|
||||
"metadata_rows_scanned": reports[-1]["metadata_rows"],
|
||||
"s3_list_pages": reports[-1]["scan_metrics"]["s3_list_pages"],
|
||||
"seconds": seconds,
|
||||
"median_seconds": round(statistics.median(seconds), 6),
|
||||
})
|
||||
finally:
|
||||
mutate("delete", keys)
|
||||
print(json.dumps({"method": "three dry-run inventories per controlled size", "results": results},
|
||||
sort_keys=True))
|
||||
print("PASS: reconciler cost measured for 32 and 128 added S3 objects; fixtures removed")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
Reference in New Issue
Block a user