From 2478df52a5760509d2f57fe8169f2cdc8ccd952f Mon Sep 17 00:00:00 2001 From: Lucas Abel <22837557+uael@users.noreply.github.com> Date: Thu, 6 Feb 2025 16:46:32 +0100 Subject: [PATCH] backend: un-queue zombies left by missing row in `v2_job_runtime` (#5232) --- ...e99740fec9c0f01b077026c0be08e87b9ba65fde5608.json | 12 ++++++++++++ .../20250201145632_v2_fix_no_runtime.up.sql | 8 -------- ...l => 20250201145633_v2_fix_no_runtime_2.down.sql} | 0 .../20250201145633_v2_fix_no_runtime_2.up.sql | 12 ++++++++++++ backend/windmill-api/src/db.rs | 8 ++++++++ 5 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 backend/.sqlx/query-67f671d3feb0c7beedd2e99740fec9c0f01b077026c0be08e87b9ba65fde5608.json delete mode 100644 backend/migrations/20250201145632_v2_fix_no_runtime.up.sql rename backend/migrations/{20250201145632_v2_fix_no_runtime.down.sql => 20250201145633_v2_fix_no_runtime_2.down.sql} (100%) create mode 100644 backend/migrations/20250201145633_v2_fix_no_runtime_2.up.sql diff --git a/backend/.sqlx/query-67f671d3feb0c7beedd2e99740fec9c0f01b077026c0be08e87b9ba65fde5608.json b/backend/.sqlx/query-67f671d3feb0c7beedd2e99740fec9c0f01b077026c0be08e87b9ba65fde5608.json new file mode 100644 index 0000000000..eb0c2c8f3c --- /dev/null +++ b/backend/.sqlx/query-67f671d3feb0c7beedd2e99740fec9c0f01b077026c0be08e87b9ba65fde5608.json @@ -0,0 +1,12 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM _sqlx_migrations WHERE version=20250201145632", + "describe": { + "columns": [], + "parameters": { + "Left": [] + }, + "nullable": [] + }, + "hash": "67f671d3feb0c7beedd2e99740fec9c0f01b077026c0be08e87b9ba65fde5608" +} diff --git a/backend/migrations/20250201145632_v2_fix_no_runtime.up.sql b/backend/migrations/20250201145632_v2_fix_no_runtime.up.sql deleted file mode 100644 index 422e3071f2..0000000000 --- a/backend/migrations/20250201145632_v2_fix_no_runtime.up.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Add up migration script here --- Migrate `v2_job_queue` moved columns to `v2_job_runtime`: -INSERT INTO v2_job_runtime (id, ping, memory_peak) -SELECT id, __last_ping, __mem_peak -FROM v2_job_queue - -- Locked ones will sync within triggers - FOR UPDATE SKIP LOCKED -ON CONFLICT (id) DO NOTHING; diff --git a/backend/migrations/20250201145632_v2_fix_no_runtime.down.sql b/backend/migrations/20250201145633_v2_fix_no_runtime_2.down.sql similarity index 100% rename from backend/migrations/20250201145632_v2_fix_no_runtime.down.sql rename to backend/migrations/20250201145633_v2_fix_no_runtime_2.down.sql diff --git a/backend/migrations/20250201145633_v2_fix_no_runtime_2.up.sql b/backend/migrations/20250201145633_v2_fix_no_runtime_2.up.sql new file mode 100644 index 0000000000..f18ad51d1c --- /dev/null +++ b/backend/migrations/20250201145633_v2_fix_no_runtime_2.up.sql @@ -0,0 +1,12 @@ +-- Add up migration script here +UPDATE v2_job_queue SET + running = false, + started_at = NULL +WHERE running = true AND NOT EXISTS (SELECT 1 FROM v2_job_runtime WHERE id = v2_job_queue.id); + +INSERT INTO v2_job_runtime (id, ping, memory_peak) +SELECT id, __last_ping, __mem_peak +FROM v2_job_queue + -- Locked ones will sync within triggers + FOR UPDATE SKIP LOCKED +ON CONFLICT (id) DO NOTHING; diff --git a/backend/windmill-api/src/db.rs b/backend/windmill-api/src/db.rs index d6af3baf84..08777df53a 100644 --- a/backend/windmill-api/src/db.rs +++ b/backend/windmill-api/src/db.rs @@ -180,6 +180,14 @@ pub async fn migrate(db: &DB) -> Result<(), Error> { tracing::info!("Could not remove sqlx migration with version=20250131115248: {err:#}"); } + // Remove the migration `v2_fix_no_runtime` in favor of `v2_fix_no_runtime_2`. + if let Err(err) = sqlx::query!("DELETE FROM _sqlx_migrations WHERE version=20250201145632") + .execute(db) + .await + { + tracing::info!("Could not remove sqlx migration with version=20250201145632: {err:#}"); + } + match sqlx::migrate!("../migrations") .run_direct(&mut custom_migrator) .await