Commit 9e952693 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Spec forking a project after source moved shard

This specs forking a project that was already the source of a pool
repository after the source project was moved to a different shard.

In this case the old pool repository will continue to exist, containing
all the deduplicated objects from the forks on the first shard. But
we'll create a new PoolRepository for the shart the source project was
moved to.

Then, new forks will be deduplicated using the new PoolRepository on
the new shard.
parent d91a7780
---
title: Fix forking a deduplicated project after it was moved to a different shard
merge_request: 21339
author:
type: fixed
......@@ -15,7 +15,10 @@ class UpdateIndexForPoolRepositories < ActiveRecord::Migration[5.2]
end
def down
remove_concurrent_index :pool_repositories, [:source_project_id, :shard_id], unique: true
# Not adding this index as a unique one, since while the new index existed
# we could have created multiple pool repositories for a project. In that
# case this rollback would fail.
add_concurrent_index :pool_repositories, :source_project_id
remove_concurrent_index :pool_repositories, [:source_project_id, :shard_id], unique: true
end
end
# frozen_string_literal: true
require 'spec_helper'
# This spec lives in `ee/` since moving shards is an EE-only feature.
describe Projects::ForkService do
include ProjectForksHelper
context 'when a project is already forked' do
it 'creates a new poolresository after the project is moved to a new shard' do
project = create(:project, :public, :repository)
fork_before_move = fork_project(project)
# Stub everything required to move a project to a Gitaly shard that does not exist
allow(Gitlab.config.repositories.storages).to receive(:keys).and_return(%w(default test_second_storage))
allow_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror).and_return(true)
Projects::UpdateRepositoryStorageService.new(project).execute('test_second_storage')
fork_after_move = fork_project(project)
pool_repository_before_move = PoolRepository.joins(:shard)
.where(source_project: project, shards: { name: 'default' }).first
pool_repository_after_move = PoolRepository.joins(:shard)
.where(source_project: project, shards: { name: 'test_second_storage' }).first
expect(fork_before_move.pool_repository).to eq(pool_repository_before_move)
expect(fork_after_move.pool_repository).to eq(pool_repository_after_move)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment