Commit b1907694 authored by Gabriel Mazetto's avatar Gabriel Mazetto
Browse files

Moved renaming operations to storage layer abstraction

When project storage_version is `2` means attachments are using
hashed storage.
parent e06d9be97e56
......@@ -26,7 +26,10 @@ class Project < ActiveRecord::Base
NUMBER_OF_PERMITTED_BOARDS = 1
UNKNOWN_IMPORT_URL = 'http://unknown.git'.freeze
LATEST_STORAGE_VERSION = 1
# Hashed Storage versions handle rolling out new storage to project and dependents models
# 1: repository
# 2: attachments
LATEST_STORAGE_VERSION = 2
cache_markdown_field :description, pipeline: :description
......@@ -1384,7 +1387,7 @@ def rename_repo
if storage.rename_repo
Gitlab::AppLogger.info "Project was renamed: #{full_path_was} -> #{new_full_path}"
rename_repo_notify!
after_rename_repo
storage.after_rename_repo
else
Rails.logger.error "Repository could not be renamed: #{full_path_was} -> #{new_full_path}"
......@@ -1404,13 +1407,6 @@ def rename_repo_notify!
reload_repository!
end
def after_rename_repo
path_before_change = previous_changes['path'].first
Gitlab::UploadsTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
Gitlab::PagesTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
end
def running_or_pending_build_count(force: false)
Rails.cache.fetch(['projects', id, 'running_or_pending_build_count'], force: force) do
builds.running_or_pending.count(:all)
......
......@@ -32,6 +32,19 @@ def rename_repo
true
end
def after_rename_repo
path_before_change = project.previous_changes['path'].first
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless project.storage_version >= 2
Gitlab::UploadsTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
end
Gitlab::PagesTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
end
private
# Generates the hash for the project path and name on disk
......
......@@ -47,5 +47,12 @@ def rename_repo
false
end
def after_rename_repo
path_before_change = project.previous_changes['path'].first
Gitlab::UploadsTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
Gitlab::PagesTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
end
end
end
......@@ -2452,6 +2452,7 @@ def enable_lfs
context 'legacy storage' do
let(:project) { create(:project, :repository) }
let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_storage) { project.send(:storage) }
before do
allow(project).to receive(:gitlab_shell).and_return(gitlab_shell)
......@@ -2546,6 +2547,30 @@ def enable_lfs
it { expect { subject }.to raise_error(StandardError) }
end
context 'gitlab pages' do
before do
expect(project_storage).to receive(:rename_repo) { true }
end
it 'moves pages folder to new location' do
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project)
project.rename_repo
end
end
context 'attachments' do
before do
expect(project_storage).to receive(:rename_repo) { true }
end
it 'moves uploads folder to new location' do
expect_any_instance_of(Gitlab::UploadsTransfer).to receive(:rename_project)
project.rename_repo
end
end
end
describe '#pages_path' do
......@@ -2649,10 +2674,6 @@ def enable_lfs
.to receive(:execute_hooks_for)
.with(project, :rename)
expect_any_instance_of(Gitlab::UploadsTransfer)
.to receive(:rename_project)
.with('foo', project.path, project.namespace.full_path)
expect(project).to receive(:expire_caches_before_rename)
expect(project).to receive(:expires_full_path_cache)
......@@ -2673,6 +2694,32 @@ def enable_lfs
it { expect { subject }.to raise_error(StandardError) }
end
context 'gitlab pages' do
it 'moves pages folder to new location' do
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project)
project.rename_repo
end
end
context 'attachments' do
it 'keeps uploads folder location unchanged' do
expect_any_instance_of(Gitlab::UploadsTransfer).not_to receive(:rename_project)
project.rename_repo
end
context 'when not rolled out' do
let(:project) { create(:project, :repository, storage_version: 1) }
it 'moves pages folder to new location' do
expect_any_instance_of(Gitlab::UploadsTransfer).to receive(:rename_project)
project.rename_repo
end
end
end
end
describe '#pages_path' do
......
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