Skip to content

Don't delete project if the repository is moving to a different shard

What does this MR do and why?

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/430064

Problem

There is a chance of race conditions when we try to delete the project and move the project's repository to another shard.

Solution

Raise an error if any active repository storage move processes are detected.

Database

  1. project.repository_storage_moves.in_progress.exists?
SELECT
    1 AS one
FROM
    "project_repository_storage_moves"
WHERE
    "project_repository_storage_moves"."project_id" = 278964
    AND "project_repository_storage_moves"."state" IN (2, 3)
LIMIT 1

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23607/commands/75864

  1. ::ProjectSnippet.by_project(project).with_repository_storage_moves.merge(::Snippets::RepositoryStorageMove.in_progress).exists?
SELECT
    1 AS one
FROM
    "snippets"
    INNER JOIN "snippet_repository_storage_moves" ON "snippet_repository_storage_moves"."snippet_id" = "snippets"."id"
WHERE
    "snippets"."type" = 'ProjectSnippet'
    AND "snippets"."project_id" = 278964
    AND "snippet_repository_storage_moves"."state" IN (2, 3)
LIMIT 1

https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23607/commands/75865

How to set up and validate locally

  1. Create a new non-empty project
  2. Open Rails console and a create a repository storage move record (it's possible to do it properly via API, but that will trigger a job that will modify the state)
Projects::RepositoryStorageMove.new(project: Project.last, source_storage_name: 'default', state: 2).save!
  1. Try to delete the project
  2. After Sidekiq worker processes it

image

Project.last.delete_error
=> "Failed to remove project. There is an active project repository storage moves process."

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 Vasilii Iakliushin

Merge request reports