[Bug][SonarQube] Migration 20230927145127 is not re-runnable: fails with "constraint _tool_sonarqube_file_metrics_pkey does not exist" after an interrupted run
Maintainer antworten meist innerhalb von 3 Tagen
Ein zugehöriger Pull Request wurde bereits gemerged.
- #9242 von @chenwei791129 — gemerged
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- go, mysql, postgresql
- Bereich
- backend, data-engineering, database
Rechercherichtung
Read backend/plugins/sonarqube/models/migrationscripts/20230927_modify_file_metrics_key_length.go and backend/core/migration/migrator.go to understand the migration steps and when history is recorded. The issue links open PR #9242, which may already be addressing the work. Done means rerunning after the primary key has been dropped succeeds on PostgreSQL and MySQL, with the expected primary key restored; the issue describes an e2e regression test for both cases.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Search before asking
- I had searched in the issues and found no similar issues.
What happened
Reported in apache/devlake-helm-chart#381 (DevLake v1.0.3-beta15, PostgreSQL 18, official Helm chart, external
DB_URL). DevLake panics at startup during migration:
modify _tool_sonarqube_file_metrics file_metrics_key from varchar(191) to varchar(500)
ERROR: constraint "_tool_sonarqube_file_metrics_pkey" of relation "_tool_sonarqube_file_metrics" does not exist (SQLSTATE 42704)
The failing statement is the first step of migration 20230927145127
(backend/plugins/sonarqube/models/migrationscripts/20230927_modify_file_metrics_key_length.go). Up() does:
- Drop the primary key without checking that it exists:
- MySQL:
ALTER TABLE _tool_sonarqube_file_metrics DROP PRIMARY KEY - otherwise (PostgreSQL):
ALTER TABLE _tool_sonarqube_file_metrics DROP CONSTRAINT _tool_sonarqube_file_metrics_pkey
- MySQL:
migrationhelper.ChangeColumnsType(rename / add / copy / drop column)ALTER TABLE _tool_sonarqube_file_metrics ADD PRIMARY KEY (connection_id, file_metrics_key)
migrator.Execute() (backend/core/migration/migrator.go) runs scripts one by one, not in a transaction, and
writes the _devlake_migration_history row only after Up() succeeds. If the process stops after step 1 but
before the history row is written, the next startup runs the script again. Step 1 then fails because the
primary key is already gone, and every later startup fails the same way:
1st start: DROP pkey OK ──▶ interrupted / failed ──▶ no history row
2nd start: script re-runs ──▶ DROP pkey fails: constraint does not exist ──▶ panic
MySQL is affected too. The helm-chart report is about PostgreSQL, but while investigating it I found
that the MySQL branch has the same problem. MySQL has no IF EXISTS form of DROP PRIMARY KEY, so after the
same kind of interruption the re-run fails with:
Error 1091 (42000): Can't DROP 'PRIMARY'; check that column/key exists
I confirmed this on MySQL 8 with the same simulated interruption (see below).
The second error in that report (migration 20260701000000 dropping
idx__tool_sonarqube_issue_code_blocks_component) was already fixed by #9012 (closes #9011, see also #9033),
included since v1.0.3-beta16. It is out of scope here.
What do you expect to happen
Migration 20230927145127 should be safe to re-run. If the primary key is already gone, it should skip the drop
and still end with PRIMARY KEY (connection_id, file_metrics_key), so DevLake can start.
How to reproduce
A truly fresh database does not trigger this. With PostgreSQL 18 and the official
apache/devlake:v1.0.3-beta15 image (all plugins, FORCE_MIGRATION=true), 20230927145127 succeeds and the
primary key exists. Only the already-fixed 20260701000000 error shows up.
To reproduce, simulate a run that was interrupted right after the drop:
-
Start DevLake once against PostgreSQL so that migration
20230927145127has run. -
Run:
ALTER TABLE _tool_sonarqube_file_metrics DROP CONSTRAINT _tool_sonarqube_file_metrics_pkey; DELETE FROM _devlake_migration_history WHERE script_version = 20230927145127; -
Restart DevLake with
FORCE_MIGRATION=true. -
Migration fails with the same
constraint "_tool_sonarqube_file_metrics_pkey" ... does not exist (SQLSTATE 42704)
error and the server panics.
On MySQL, use ALTER TABLE _tool_sonarqube_file_metrics DROP PRIMARY KEY; in step 2. Step 4 then fails with
Error 1091 (42000): Can't DROP 'PRIMARY'; check that column/key exists.
Anything else
Possible trigger in the Helm setup (a hypothesis, not confirmed)
- With
FORCE_MIGRATION,CreateAndRunApiServer(backend/server/api/api.go) runs
services.InitExecuteMigration()beforeRunApiServerstarts listening. - The chart's default lake
livenessProbeishttpGet /pingwithinitialDelaySeconds: 30,periodSeconds: 5,
failureThreshold: 5. A slow migration against a remote database can get the pod killed and restarted in the
middle of it. - The panic from the
20260701000000error also causes CrashLoop restarts.
Any interruption while this script is running leaves the table without a primary key.
Proposed fix (PR to follow)
Make the script idempotent on both databases by dropping the primary key only if it exists:
- PostgreSQL:
ALTER TABLE ... DROP CONSTRAINT IF EXISTS _tool_sonarqube_file_metrics_pkey - MySQL: check
information_schema.table_constraintsfor an existing primary key beforeDROP PRIMARY KEY
The normal path is unchanged. The PR adds an e2e regression test that covers the normal run and a re-run
without the primary key. It fails without the fix on both MySQL 8 and PostgreSQL 18, and passes with it.
The script has not changed since #6157 and #6196 (2023).
Version
v1.0.3-beta15 (the script is unchanged on main at ee0079ab3)
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
- Vorherrschende Sprache
- Go
- Sterne
- 3.2k
- Forks
- 824
- Ø Merge
- 2 T. 22 Std.
- Gemergte PRs (30 T.)
- 50
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus apache/devlake
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
apache/devlake#9246 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 3 Tagen
-
[Bug][Blueprint] Cron-triggered pipelines use a sanitized plan after PATCH /blueprints, gitextractor fails with masked credentialsEvtl. vergeben @Thanatos9404 hat das vor 1 Tag übernommen. Offen
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 56/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 3/5 Ein halber Tag Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 42/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 3 Tagen
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
praetorianer777/Dynamo#53 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
kind/engineering pulumi/pulumi-terraform Task Workflow Failure
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
pulumi/pulumi-terraform#1261 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Controllers integration tests fail when port 8080 is in useEvtl. vergeben @noahnut hat das heute übernommen. Offenarea/cluster-autoscaler kind/bug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
kubernetes-sigs/cluster-autoscaler#236 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag