Skip to content

Add DeleteMigrateSharedVulnerabilityScanners migration

What does this MR do and why?

!89127 (merged) introduced the MigrateSharedVulnerabilityScanners background migration which suffers from a long runtime due to a bug.

Because the migration has accumulated ~12283 job rows, deleting the migration row from batched_background_migrations will also delete all 12k rows from batched_background_migration_jobs due to ON CASCADE DELETE.

This MR adds a Post Deployment Migration which (1) deletes the job rows from batched_background_migration_jobs in batches, and (2) deletes the migration row from batched_background_migrations.

Database queries

(cold caches)

SELECT
	"batched_background_migration_jobs"."id"
FROM
	"batched_background_migration_jobs"
	INNER JOIN "batched_background_migrations" "batched_background_migration" ON "batched_background_migration"."id" = "batched_background_migration_jobs"."batched_background_migration_id"
WHERE
	"batched_background_migration"."job_class_name" = 'MigrateSharedVulnerabilityScanners'
ORDER BY
	"batched_background_migration_jobs"."id" ASC
LIMIT 500;

postgres.ai


DELETE FROM "batched_background_migration_jobs"
WHERE "batched_background_migration_jobs"."id" IN(
		SELECT
			"batched_background_migration_jobs"."id" FROM "batched_background_migration_jobs"
			INNER JOIN "batched_background_migrations" "batched_background_migration" ON "batched_background_migration"."id" = "batched_background_migration_jobs"."batched_background_migration_id"
		WHERE
			"batched_background_migration"."job_class_name" = 'MigrateSharedVulnerabilityScanners'
			AND "batched_background_migration_jobs"."id" >= 1000
			AND "batched_background_migration_jobs"."id" < 1500);

postgres.ai


DELETE FROM "batched_background_migrations"
WHERE "batched_background_migrations"."job_class_name" = 'MigrateSharedVulnerabilityScanners'
	AND "batched_background_migrations"."table_name" = 'vulnerability_occurrences'
	AND "batched_background_migrations"."column_name" = 'id'
	AND(job_arguments = '[]'::jsonb)
	AND "batched_background_migrations"."gitlab_schema" = 'gitlab_main';
  • with associated rows in batched_background_migration_jobs: postgres.ai (5.405 s)
  • without associated rows: postgres.ai (24.990 ms)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Dominic Bauer

Merge request reports