diff --git a/.env.example b/.env.example index c647996f..e3be7a4f 100644 --- a/.env.example +++ b/.env.example @@ -50,3 +50,11 @@ UPLOAD_SWEEP_INTERVAL_SECONDS=30 UPLOAD_SWEEP_BATCH=100 # Fixed glibc mmap threshold for the API: buffers above 128 KiB are returned to the system on free. MALLOC_MMAP_THRESHOLD_=131072 +# Solution-specific for lab4 track 2: limits of the one-off reconciler (profile reconcile), its S3 +# read timeout for listing pages, and optional CPU pinning of the measured services (empty = no pinning). +RECONCILE_CPUS=1 +RECONCILE_MEMORY=256m +RECONCILE_S3_READ_TIMEOUT_SECONDS=10 +RECONCILE_CPUSET= +S3_CPUSET= +PG_CPUSET= diff --git a/Makefile b/Makefile index 11e1ace3..9f083d12 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ RATE ?= 100 API_IMAGE ?= mtusi-messenger:lab4 FROM_REV ?= SCRIPTS_PY = scripts/probe.py scripts/limits.py scripts/lab4_scenarios.py scripts/lab4_seed.py \ - scripts/upload_memory.py + scripts/upload_memory.py scripts/reconcile_check.py scripts/reconcile_track.py SCENARIO ?= failover-upload PSQL = $(COMPOSE) exec -T postgres psql -U messenger -d messenger -X -q @@ -20,7 +20,8 @@ PSQL = $(COMPOSE) exec -T postgres psql -U messenger -d messenger -X -q secrets up down reset-data migrate ps logs restore lb-check failover-evidence stack-evidence \ persistence-evidence storage-evidence cache-evidence test-faults seed explain \ limits detection failover-each rolling-update level4 \ - scenario s3-check attachments-evidence upload-faults upload-memory + scenario s3-check attachments-evidence upload-faults upload-memory \ + reconcile reconcile-demo reconcile-cost help: @echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes" @@ -139,6 +140,15 @@ upload-faults: upload-memory: $(PYTHON) scripts/upload_memory.py --base-url "$(BASE_URL)" +reconcile: + $(COMPOSE) run --rm --no-deps reconciler $(ARGS) + +reconcile-demo: + $(PYTHON) scripts/reconcile_track.py demo --base-url "$(BASE_URL)" + +reconcile-cost: + $(PYTHON) scripts/reconcile_track.py cost $(ARGS) + failover-evidence: sh scripts/failover-evidence.sh "$(BASE_URL)" diff --git a/compose.yaml b/compose.yaml index 52721052..aa1a1714 100644 --- a/compose.yaml +++ b/compose.yaml @@ -152,6 +152,7 @@ services: secrets: [postgres_password] volumes: [pgdata:/var/lib/postgresql/data] shm_size: 256m + cpuset: ${PG_CPUSET:-} healthcheck: test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "messenger", "-d", "messenger"] interval: 2s @@ -205,6 +206,7 @@ services: RUSTFS_OBS_LOGGER_LEVEL: ${S3_LOG_LEVEL:-warn} secrets: [s3_root_user, s3_root_password] volumes: [s3data:/data] + cpuset: ${S3_CPUSET:-} read_only: true tmpfs: ["/tmp:size=64m"] cap_drop: [ALL] @@ -222,6 +224,32 @@ services: resources: limits: {cpus: "1", memory: "${S3_MEMORY:-512m}"} + reconciler: + <<: *app + pull_policy: never + profiles: [reconcile] + entrypoint: ["python", "-m", "messenger.attachments.entrypoints.reconcile"] + command: ["--dry-run"] + environment: + <<: *s3-env + DATABASE_URL_FILE: /run/secrets/database_url + S3_READ_TIMEOUT_SECONDS: ${RECONCILE_S3_READ_TIMEOUT_SECONDS:-10} + LOG_LEVEL: ${LOG_LEVEL:-INFO} + secrets: [database_url, s3_access_key_id, s3_secret_access_key] + healthcheck: + disable: true + restart: "no" + read_only: true + cpuset: ${RECONCILE_CPUSET:-} + depends_on: + postgres: + condition: service_healthy + s3: + condition: service_healthy + deploy: + resources: + limits: {cpus: "${RECONCILE_CPUS:-1}", memory: "${RECONCILE_MEMORY:-256m}"} + s3-init: <<: *s3-client entrypoint: ["/bin/sh", "/s3/init.sh"] diff --git a/openspec/changes/add-lab4-storage-reconciler/tasks.md b/openspec/changes/add-lab4-storage-reconciler/tasks.md index b9503843..04c9511c 100644 --- a/openspec/changes/add-lab4-storage-reconciler/tasks.md +++ b/openspec/changes/add-lab4-storage-reconciler/tasks.md @@ -20,9 +20,9 @@ ## 4. Стенд -- [ ] 4.1 `compose.yaml`: сервис `reconciler` (профиль `reconcile`), `cpuset` из переменных у `s3`, `postgres`, `reconciler`; `.env.example` -- [ ] 4.2 Цели `make reconcile ARGS=…`, `make reconcile-demo`, `make reconcile-cost` -- [ ] 4.3 Проверка группы: `docker compose config --quiet`, `make up`, `make reconcile` +- [x] 4.1 `compose.yaml`: сервис `reconciler` (профиль `reconcile`), `cpuset` из переменных у `s3`, `postgres`, `reconciler`; `.env.example` +- [x] 4.2 Цели `make reconcile ARGS=…`, `make reconcile-demo`, `make reconcile-cost` +- [x] 4.3 Проверка группы: `docker compose config --quiet`, `make up`, `make reconcile` ## 5. Обвязка трека diff --git a/scripts/limits.py b/scripts/limits.py index c487ef6f..d829cf21 100644 --- a/scripts/limits.py +++ b/scripts/limits.py @@ -22,6 +22,11 @@ POLICY = { "networks": ["backend"], }, "migrate": {"secrets": ["database_url"], "volumes": [], "networks": ["backend"]}, + "reconciler": { + "secrets": ["database_url", "s3_access_key_id", "s3_secret_access_key"], + "volumes": [], + "networks": ["backend"], + }, "postgres": {"secrets": ["postgres_password"], "volumes": ["pgdata"], "networks": ["backend"]}, "valkey": {"secrets": ["valkey.conf"], "volumes": ["valkeydata"], "networks": ["backend"]}, "k6": {"secrets": [], "volumes": [], "networks": ["edge"]}, @@ -120,6 +125,8 @@ def main(): "bench", "--profile", "tools", + "--profile", + "reconcile", "config", "--format", "json", @@ -134,7 +141,8 @@ def main(): problems.append("no running api replicas to inspect") lines = [ f"date: {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())}", - "$ docker compose --profile bench --profile tools config --format json (declared)", + "$ docker compose --profile bench --profile tools --profile reconcile config --format json" + " (declared)", *table(["service", "cpus/mem", "ports", "secrets", "volumes", "networks", "ro"], services), "", "$ docker inspect (running containers: hostname = X-Instance-Id, applied limits)",