fix: address track2-reconcile-cost verify findings
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -123,8 +123,12 @@
|
||||
вместо pause s3 — объекты пробы мимо API (botocore в одноразовом
|
||||
контейнере api его ключами), reconcile --max-objects-per-second
|
||||
1, docker stop через 2 с после «Started cleaner» во время паузы
|
||||
предела скорости — остановка не дольше секунды; объекты
|
||||
удаляются в finally
|
||||
предела скорости — остановка не дольше секунды, listed_objects
|
||||
итога — ключи страницы; объекты удаляются в finally.
|
||||
--pace --apply (verify W1): объекты пробы без строки
|
||||
(<id>/original), через grace 18 с + 1 — reconcile --apply с тем
|
||||
же пределом, docker stop во время паузы после DELETE: удалённых
|
||||
объектов столько же, сколько записей «Fixed» и fixed итога
|
||||
s3-idle [--rounds 3] [--downloads 10] [--puts 12] [--size-mib 4]
|
||||
[--pause-ms 0.5] только стенд с LB: спеки object-storage
|
||||
«Вызов после простоя» и attachments «Загрузка после простоя
|
||||
@@ -3658,13 +3662,23 @@ RS_PACE_RATE = "1"
|
||||
RS_PACE_AFTER_START_S = 2.0
|
||||
# остановка во время паузы — не позже секунды после сигнала
|
||||
RS_PACE_STOP_LIMIT_S = 1.0
|
||||
# режим --pace --apply (verify W1 change track2-reconcile-cost): объекты
|
||||
# пробы — без строки (<id>/original), и сверка с --apply их удаляет. Grace
|
||||
# прохода — наименьший, который примет уборщик (граница живой загрузки
|
||||
# 17 с), объекты старше него через секунду. При пределе 1 объект/с: список
|
||||
# — 8 с, перепроверка — HEAD на объект (ещё 8 с), затем DELETE раз в
|
||||
# секунду, и после каждого — пауза ~1 с. docker stop — посреди удалений
|
||||
RS_PACE_APPLY_GRACE_S = 18
|
||||
RS_PACE_APPLY_AFTER_START_S = 19.5
|
||||
# объекты пробы — botocore в одноразовом контейнере сервиса api его
|
||||
# ключами из окружения (как put-object hook стенда отказов); в argv и
|
||||
# вывод ключи не попадают
|
||||
# вывод ключи доступа не попадают. argv: действие (put, delete, count) и
|
||||
# хвосты ключей под <база>/attachments/
|
||||
RS_PACE_OBJECTS_PY = r"""
|
||||
import os, sys
|
||||
import botocore.session
|
||||
from botocore.config import Config
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
s3 = botocore.session.get_session().create_client(
|
||||
"s3",
|
||||
@@ -3675,14 +3689,22 @@ s3 = botocore.session.get_session().create_client(
|
||||
config=Config(s3={"addressing_style": "path"}),
|
||||
)
|
||||
bucket = os.environ["S3__BUCKET"]
|
||||
prefix = os.environ["DATABASE__NAME"] + "/attachments/pace-signal-"
|
||||
for i in range(int(sys.argv[2])):
|
||||
key = f"{prefix}{i}"
|
||||
if sys.argv[1] == "put":
|
||||
prefix = os.environ["DATABASE__NAME"] + "/attachments/"
|
||||
action, tails = sys.argv[1], sys.argv[2:]
|
||||
present = 0
|
||||
for tail in tails:
|
||||
key = prefix + tail
|
||||
if action == "put":
|
||||
s3.put_object(Bucket=bucket, Key=key, Body=b"pace", ContentType="image/png")
|
||||
else:
|
||||
elif action == "delete":
|
||||
s3.delete_object(Bucket=bucket, Key=key)
|
||||
print(f"{sys.argv[1]} {sys.argv[2]} objects")
|
||||
else:
|
||||
try:
|
||||
s3.head_object(Bucket=bucket, Key=key)
|
||||
present += 1
|
||||
except ClientError:
|
||||
pass
|
||||
print(f"present {present}" if action == "count" else f"{action} {len(tails)} objects")
|
||||
"""
|
||||
|
||||
|
||||
@@ -3696,9 +3718,10 @@ def rfc3339_ns(text: str) -> int:
|
||||
return seconds * 10**9 + int((digits + "0" * 9)[:9])
|
||||
|
||||
|
||||
def rs_pace_objects(action: str) -> None:
|
||||
"""`put` или `delete` объектов пробы режима `--pace`."""
|
||||
compose(
|
||||
def rs_pace_objects(action: str, tails: list[str]) -> str:
|
||||
"""`put`, `delete` или `count` объектов пробы режима `--pace`; вывод
|
||||
скрипта (у `count` — `present N`)."""
|
||||
return compose(
|
||||
"run",
|
||||
"--rm",
|
||||
"--no-deps",
|
||||
@@ -3708,12 +3731,12 @@ def rs_pace_objects(action: str) -> None:
|
||||
"api",
|
||||
"-",
|
||||
action,
|
||||
str(RS_PACE_OBJECTS),
|
||||
*tails,
|
||||
stdin=RS_PACE_OBJECTS_PY,
|
||||
)
|
||||
|
||||
|
||||
def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
def cmd_reconcile_signal(*, pace: bool = False, apply: bool = False) -> int:
|
||||
"""Спек `graceful-shutdown`, разовый проход сверки, прерванный сигналом,
|
||||
— код 1: на стенде проекта compose из окружения (`COMPOSE_PROJECT_NAME`
|
||||
и др., рабочий `mtusi-lab4` — отказ, код 2) `docker compose pause s3`,
|
||||
@@ -3721,9 +3744,15 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
«Started cleaner» — `docker stop`; S3 размораживается в `finally`.
|
||||
`pace` — вместо замороженного S3 пауза предела скорости: объекты пробы,
|
||||
`reconcile --max-objects-per-second 1` (dry-run), `docker stop` через
|
||||
2 с после «Started cleaner», остановка не дольше секунды; объекты
|
||||
удаляются в `finally`. Таблица и записи процесса без секретов; код 1
|
||||
при расхождении."""
|
||||
2 с после «Started cleaner», остановка не дольше секунды, итог называет
|
||||
ключи страницы (`listed_objects`); объекты удаляются в `finally`.
|
||||
`pace` и `apply` (verify W1) — объекты пробы без строки, через grace
|
||||
`reconcile --apply` с тем же пределом и `docker stop` посреди удалений:
|
||||
каждое удалённое — запись «Fixed» и счёт `fixed`. Таблица и записи
|
||||
процесса без секретов; код 1 при расхождении."""
|
||||
if apply and not pace:
|
||||
print("reconcile-signal: --apply is a variant of --pace")
|
||||
return 2
|
||||
try:
|
||||
config = json.loads(compose("config", "--format", "json"))
|
||||
except (RuntimeError, ValueError) as e:
|
||||
@@ -3750,12 +3779,29 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
after_signal = -1.0
|
||||
exit_code = ""
|
||||
logs = ""
|
||||
left = -1
|
||||
tails: list[str] = []
|
||||
run_env: list[str] = []
|
||||
if pace:
|
||||
rs_pace_objects("put")
|
||||
if apply:
|
||||
tails = [
|
||||
f"{uuid.uuid4()}/original" for _ in range(RS_PACE_OBJECTS)
|
||||
]
|
||||
else:
|
||||
tails = [f"pace-signal-{i}" for i in range(RS_PACE_OBJECTS)]
|
||||
rs_pace_objects("put", tails)
|
||||
print(f"{project}: {RS_PACE_OBJECTS} probe objects put")
|
||||
args = ["reconcile", "--max-objects-per-second", RS_PACE_RATE]
|
||||
after_start, limit = RS_PACE_AFTER_START_S, RS_PACE_STOP_LIMIT_S
|
||||
waiting = "the rate limit pause"
|
||||
if apply:
|
||||
args.append("--apply")
|
||||
grace = RS_PACE_APPLY_GRACE_S
|
||||
run_env = ["-e", f"CLEANER__PENDING_GRACE_SECONDS={grace}"]
|
||||
after_start = RS_PACE_APPLY_AFTER_START_S
|
||||
waiting = "the rate limit pause after a DELETE"
|
||||
print(f"waiting {grace + 1} s: probe objects older than grace")
|
||||
time.sleep(grace + 1)
|
||||
else:
|
||||
compose("pause", "s3")
|
||||
print(f"{project}: s3 paused")
|
||||
@@ -3763,7 +3809,16 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
after_start, limit = RS_AFTER_START_S, float(RS_STOP_LIMIT_S)
|
||||
waiting = "paused S3"
|
||||
try:
|
||||
compose("run", "-d", "--no-deps", "--name", name, "cleaner", *args)
|
||||
compose(
|
||||
"run",
|
||||
"-d",
|
||||
"--no-deps",
|
||||
"--name",
|
||||
name,
|
||||
*run_env,
|
||||
"cleaner",
|
||||
*args,
|
||||
)
|
||||
deadline = time.monotonic() + RS_START_TIMEOUT_S
|
||||
while time.monotonic() < deadline:
|
||||
logs = docker_logs(name)
|
||||
@@ -3821,7 +3876,13 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
finally:
|
||||
subprocess.run(["docker", "rm", "-f", name], capture_output=True)
|
||||
if pace:
|
||||
rs_pace_objects("delete")
|
||||
if apply:
|
||||
lines = rs_pace_objects("count", tails).strip().splitlines()
|
||||
counted = lines[-1].split() if lines else []
|
||||
if counted[:1] == ["present"]:
|
||||
left = int(counted[1])
|
||||
print(f"{project}: probe objects left after the pass: {left}")
|
||||
rs_pace_objects("delete", tails)
|
||||
print(f"{project}: probe objects deleted")
|
||||
else:
|
||||
compose("unpause", "s3")
|
||||
@@ -3832,9 +3893,11 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
with contextlib.suppress(json.JSONDecodeError):
|
||||
records.append(json.loads(line))
|
||||
shown = ("event", "level", "mode", "operation", "error_type")
|
||||
shown += ("reconcile_max_objects_per_second", "listed_objects")
|
||||
shown += ("storage_objects", "max_objects_per_second")
|
||||
shown += ("duration_ms", "interrupted_by", "exit_code", "timestamp")
|
||||
shown += ("reconcile_max_objects_per_second", "reconcile_apply")
|
||||
shown += ("kind", "action", "object_key", "listed_objects", "found")
|
||||
shown += ("fixed", "storage_objects", "s3_requests")
|
||||
shown += ("max_objects_per_second", "duration_ms", "interrupted_by")
|
||||
shown += ("exit_code", "timestamp")
|
||||
print("== records of the one-off reconcile")
|
||||
for record in records:
|
||||
print(
|
||||
@@ -3847,6 +3910,8 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
stopped = [
|
||||
item for item in records if item.get("event") == "Stopped cleaner"
|
||||
]
|
||||
# удалённые до сигнала объекты пробы: каждый — запись «Fixed» и fixed
|
||||
deleted = RS_PACE_OBJECTS - left if left >= 0 else -1
|
||||
print(
|
||||
f"docker stop took {took:.1f} s, container exited "
|
||||
f"{after_signal:.2f} s after the kill event, exit code "
|
||||
@@ -3867,7 +3932,7 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
),
|
||||
(
|
||||
"Fixed storage discrepancy records",
|
||||
"0",
|
||||
str(deleted) if apply else "0",
|
||||
str(len(rc_events(records, RC_FIXED))),
|
||||
),
|
||||
(
|
||||
@@ -3895,16 +3960,47 @@ def cmd_reconcile_signal(*, pace: bool = False) -> int:
|
||||
"-" if rate is None else f"{float(rate):g}",
|
||||
),
|
||||
)
|
||||
return report_reconcile(
|
||||
rows,
|
||||
passed=(
|
||||
# ключи страницы, после которой пришёл сигнал, — в итоге (verify W1)
|
||||
rows.append(
|
||||
(
|
||||
"Finished reconcile pass listed_objects",
|
||||
str(RS_PACE_OBJECTS),
|
||||
str(finished.get("listed_objects")),
|
||||
),
|
||||
)
|
||||
if apply:
|
||||
fixed = finished.get("fixed")
|
||||
rows += [
|
||||
(
|
||||
"probe objects deleted before the signal",
|
||||
">0",
|
||||
">0" if deleted > 0 else str(deleted),
|
||||
),
|
||||
(
|
||||
"Finished reconcile pass fixed orphan_object",
|
||||
str(deleted),
|
||||
str(
|
||||
fixed.get("orphan_object", 0)
|
||||
if isinstance(fixed, dict)
|
||||
else "-",
|
||||
),
|
||||
),
|
||||
]
|
||||
if apply:
|
||||
passed = (
|
||||
"one-off reconcile --apply stopped by SIGTERM during the rate "
|
||||
"limit pause: exit 1 within a second, every deleted object fixed"
|
||||
)
|
||||
elif pace:
|
||||
passed = (
|
||||
"one-off reconcile stopped by SIGTERM during the rate limit "
|
||||
"pause: exit 1 within a second"
|
||||
if pace
|
||||
else "one-off reconcile stopped by SIGTERM: exit 1, nothing "
|
||||
"changed"
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
passed = (
|
||||
"one-off reconcile stopped by SIGTERM: exit 1, nothing changed"
|
||||
)
|
||||
return report_reconcile(rows, passed=passed)
|
||||
|
||||
|
||||
def docker_logs(name: str) -> str:
|
||||
@@ -5143,6 +5239,7 @@ def main() -> int:
|
||||
stress.add_argument("--clients", type=int, default=4)
|
||||
signal_cmd = sub.add_parser("reconcile-signal")
|
||||
signal_cmd.add_argument("--pace", action="store_true")
|
||||
signal_cmd.add_argument("--apply", action="store_true")
|
||||
idle_s3 = sub.add_parser("s3-idle")
|
||||
idle_s3.add_argument("--rounds", type=int, default=3)
|
||||
idle_s3.add_argument("--downloads", type=int, default=10)
|
||||
@@ -5256,7 +5353,7 @@ def main() -> int:
|
||||
clients=args.clients,
|
||||
)
|
||||
if args.cmd == "reconcile-signal":
|
||||
return cmd_reconcile_signal(pace=args.pace)
|
||||
return cmd_reconcile_signal(pace=args.pace, apply=args.apply)
|
||||
if args.cmd == "s3-idle":
|
||||
return cmd_s3_idle(
|
||||
port,
|
||||
|
||||
Reference in New Issue
Block a user