feat: complete transfer and eviction execution

This commit is contained in:
2026-07-23 09:14:40 +00:00
parent 884aed9921
commit b6de490b7e
17 changed files with 1445 additions and 81 deletions
+12 -26
View File
@@ -9,8 +9,6 @@ import sys
import time
import urllib.parse
import urllib.request
import uuid
from datetime import datetime, timezone
CONTROL = "http://127.0.0.1:18081/test/v1"
@@ -103,30 +101,18 @@ def main() -> int:
60,
f"{args.cache_client}/{args.archive_client} route",
)
job_id = str(uuid.uuid4())
now = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
definition = {
"jobId": job_id,
"idempotencyKey": str(uuid.uuid4()),
"operation": (
"JOB_OPERATION_ARCHIVE"
if args.operation == "archive"
else "JOB_OPERATION_UNARCHIVE"
),
"resourceId": {"infoHashV1Hex": INFO_HASH},
"resourceDisplayName": "fixture.bin",
"createdAt": now,
"transfer": {
"sourceClientId": args.source_client,
"targetClientId": args.target_client,
"routeId": route["route_id"],
"requestedFiles": {"ranges": [{"first": 0, "last": 0}]},
"transferDeltaFiles": {"ranges": [{"first": 0, "last": 0}]},
"requestedLogicalBytes": str(LOGICAL_BYTES),
"transferDeltaLogicalBytes": str(LOGICAL_BYTES),
},
}
created = post_json(f"{CONTROL}/jobs", definition)
preview = post_json(f"{CONTROL}/jobs/preview", {
"operation": args.operation,
"source_client_id": args.source_client,
"target_client_id": args.target_client,
"resource_id": {"info_hash_v1_hex": INFO_HASH},
})
definition = preview["definition"]
job_id = definition["job_id"]
created = post_json(f"{CONTROL}/jobs", {
"preview_revision": preview["preview_revision"],
"definition": definition,
})
if created["job_id"] != job_id:
raise RuntimeError("control returned the wrong job")
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env python3
"""Drive a covered cache eviction through the bot-free HTTP adapter."""
from __future__ import annotations
import json
import sys
import time
import urllib.request
CONTROL = "http://127.0.0.1:18081/test/v1"
INFO_HASH = "330be0cb7c2201135a2de63b28e77993745ff688"
def get_json(url: str):
with urllib.request.urlopen(url, timeout=35) as response:
return json.load(response)
def post_json(url: str, value: object):
request = urllib.request.Request(
url,
data=json.dumps(value, separators=(",", ":")).encode(),
method="POST",
headers={"Content-Type": "application/json"},
)
with urllib.request.urlopen(request, timeout=35) as response:
return json.load(response)
def main() -> int:
preview = post_json(f"{CONTROL}/jobs/preview", {
"operation": "evict_cache",
"cache_client_id": "cache-1",
"resource_id": {"info_hash_v1_hex": INFO_HASH},
})
definition = preview["definition"]
job_id = definition["job_id"]
post_json(f"{CONTROL}/jobs", {
"preview_revision": preview["preview_revision"],
"definition": definition,
})
deadline = time.monotonic() + 180
while time.monotonic() < deadline:
job = get_json(f"{CONTROL}/jobs/{job_id}")
if job["state"] == "JOB_STATE_SUCCEEDED" and job["committed"]:
print(json.dumps({
"job_id": job_id,
"state": job["state"],
"committed": job["committed"],
}, sort_keys=True))
return 0
if job["state"] in {"JOB_STATE_FAILED", "JOB_STATE_CANCELLED"}:
raise RuntimeError(f"eviction did not succeed: {job}")
time.sleep(0.5)
raise RuntimeError("timed out waiting for cache eviction")
if __name__ == "__main__":
try:
raise SystemExit(main())
except Exception as exc:
print(f"eviction happy-path failed: {exc}", file=sys.stderr)
raise