提交 fe158ad1 编写于 作者: J John Cai

Call RenameRepository instead of RenameNamespace

call RenameRepository RPC instead of RenameNamespace in gitlab_shell.
This is a step towards deprecating all RenameNamespace calls.
上级 95d16dc0
...@@ -428,7 +428,7 @@ group :ed25519 do ...@@ -428,7 +428,7 @@ group :ed25519 do
end end
# Gitaly GRPC protocol definitions # Gitaly GRPC protocol definitions
gem 'gitaly', '~> 1.58.0' gem 'gitaly', '~> 1.63.0'
gem 'grpc', '~> 1.19.0' gem 'grpc', '~> 1.19.0'
......
...@@ -332,7 +332,7 @@ GEM ...@@ -332,7 +332,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
git (1.5.0) git (1.5.0)
gitaly (1.58.0) gitaly (1.63.0)
grpc (~> 1.0) grpc (~> 1.0)
github-markup (1.7.0) github-markup (1.7.0)
gitlab-labkit (0.5.2) gitlab-labkit (0.5.2)
...@@ -1126,7 +1126,7 @@ DEPENDENCIES ...@@ -1126,7 +1126,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly (~> 1.58.0) gitaly (~> 1.63.0)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
gitlab-labkit (~> 0.5) gitlab-labkit (~> 0.5)
gitlab-markup (~> 1.7.0) gitlab-markup (~> 1.7.0)
......
...@@ -54,25 +54,19 @@ module Storage ...@@ -54,25 +54,19 @@ module Storage
private private
def move_repositories def move_repositories
# Move the namespace directory in all storages used by member projects all_projects.each do |project|
repository_storages.each do |repository_storage| next unless project.legacy_storage?
# Ensure old directory exists before moving it
gitlab_shell.add_namespace(repository_storage, full_path_before_last_save)
# Ensure new directory exists before moving it (if there's a parent) unless gitlab_shell.mv_repository(project.repository_storage, full_repo_path_before_last_save(project), project.disk_path )
gitlab_shell.add_namespace(repository_storage, parent.full_path) if parent
unless gitlab_shell.mv_namespace(repository_storage, full_path_before_last_save, full_path)
Rails.logger.error "Exception moving path #{repository_storage} from #{full_path_before_last_save} to #{full_path}" # rubocop:disable Gitlab/RailsLogger
# if we cannot move namespace directory we should rollback
# db changes in order to prevent out of sync between db and fs
raise Gitlab::UpdatePathError.new('namespace directory cannot be moved') raise Gitlab::UpdatePathError.new('namespace directory cannot be moved')
end end
end end
end end
def full_repo_path_before_last_save(project)
project.disk_path.gsub(full_path, full_path_before_last_save)
end
def old_repository_storages def old_repository_storages
@old_repository_storage_paths ||= repository_storages @old_repository_storage_paths ||= repository_storages
end end
......
...@@ -38,7 +38,7 @@ module Storage ...@@ -38,7 +38,7 @@ module Storage
# However we cannot allow rollback since we moved repository # However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions # So we basically we mute exceptions in next actions
begin begin
gitlab_shell.mv_repository(repository_storage, "#{old_full_path}.wiki", "#{new_full_path}.wiki") gitlab_shell.mv_wiki(repository_storage, old_full_path, new_full_path) if project.wiki.exists?
return true return true
rescue => e rescue => e
Rails.logger.error "Exception renaming #{old_full_path} -> #{new_full_path}: #{e}" # rubocop:disable Gitlab/RailsLogger Rails.logger.error "Exception renaming #{old_full_path} -> #{new_full_path}: #{e}" # rubocop:disable Gitlab/RailsLogger
......
...@@ -29,20 +29,12 @@ module Projects ...@@ -29,20 +29,12 @@ module Projects
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def move_repository(from_name, to_name) def move_repository(from_name, to_name)
from_exists = gitlab_shell.exists?(project.repository_storage, "#{from_name}.git") from_exists = gitlab_shell.exists?(project.repository_storage, "#{from_name}.git")
to_exists = gitlab_shell.exists?(project.repository_storage, "#{to_name}.git")
# If we don't find the repository on either original or target we should log that as it could be an issue if the # If we don't find the repository on either original or target we should log that as it could be an issue if the
# project was not originally empty. # project was not originally empty.
if !from_exists && !to_exists
logger.warn "Can't find a repository on either source or target paths for #{project.full_path} (ID=#{project.id}) ..."
# We return true so we still reflect the change in the database. # Repository have been moved already.
# Next time the repository is (re)created it will be under the new storage layout return true unless from_exists
return true
elsif !from_exists
# Repository have been moved already.
return true
end
gitlab_shell.mv_repository(project.repository_storage, from_name, to_name) gitlab_shell.mv_repository(project.repository_storage, from_name, to_name)
end end
......
...@@ -8,7 +8,6 @@ module Projects ...@@ -8,7 +8,6 @@ module Projects
@old_storage_version = project.storage_version @old_storage_version = project.storage_version
project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository]
project.ensure_storage_path_exists
@new_disk_path = project.disk_path @new_disk_path = project.disk_path
......
---
title: Call RenameRepository instead of RenameNamespace
merge_request: 32684
author:
type: deprecated
...@@ -131,6 +131,12 @@ module Gitlab ...@@ -131,6 +131,12 @@ module Gitlab
end end
end end
def rename(new_relative_path)
wrapped_gitaly_errors do
gitaly_repository_client.rename(new_relative_path)
end
end
def expire_has_local_branches_cache def expire_has_local_branches_cache
clear_memoization(:has_local_branches) clear_memoization(:has_local_branches)
end end
......
...@@ -346,6 +346,12 @@ module Gitlab ...@@ -346,6 +346,12 @@ module Gitlab
GitalyClient.call(@storage, :object_pool_service, :disconnect_git_alternates, request) GitalyClient.call(@storage, :object_pool_service, :disconnect_git_alternates, request)
end end
def rename(relative_path)
request = Gitaly::RenameRepositoryRequest.new(repository: @gitaly_repo, relative_path: relative_path)
GitalyClient.call(@storage, :repository_service, :rename_repository, request, timeout: GitalyClient.fast_timeout)
end
private private
def search_results_from_response(gitaly_response) def search_results_from_response(gitaly_response)
......
...@@ -117,16 +117,26 @@ module Gitlab ...@@ -117,16 +117,26 @@ module Gitlab
# mv_namespace. Given the underlying implementation is a move action, # mv_namespace. Given the underlying implementation is a move action,
# indescriminate of what the folders might be. # indescriminate of what the folders might be.
# #
# storage - project's storage path # storage - project's storage name
# path - project disk path # path - project disk path
# new_path - new project disk path # new_path - new project disk path
# #
# Ex. # Ex.
# mv_repository("/path/to/storage", "gitlab/gitlab-ci", "randx/gitlab-ci-new") # mv_repository("default", "gitlab/gitlab-ci", "randx/gitlab-ci-new")
def mv_repository(storage, path, new_path) def mv_repository(storage, path, new_path)
return false if path.empty? || new_path.empty? return false if path.empty? || new_path.empty?
!!mv_directory(storage, "#{path}.git", "#{new_path}.git") Gitlab::Git::Repository.new(storage, "#{path}.git", nil, nil).rename("#{new_path}.git")
rescue => e
Gitlab::Sentry.track_acceptable_exception(e, extra: { path: path, new_path: new_path, storage: storage })
false
end
def mv_wiki(storage, path, new_path)
return false if path.empty? || new_path.empty?
Gitlab::Git::Repository.new(storage, "#{path}.wiki.git", nil, nil).rename("#{new_path}.wiki.git")
end end
# Fork repository to new path # Fork repository to new path
......
...@@ -21,6 +21,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -21,6 +21,8 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
it 'searches using nested paths' do it 'searches using nested paths' do
namespace = create(:namespace, path: 'hello') namespace = create(:namespace, path: 'hello')
project = create(:project, :legacy_storage, path: 'THE-path', namespace: namespace) project = create(:project, :legacy_storage, path: 'THE-path', namespace: namespace)
project.create_repository
project.create_wiki
result_ids = described_class.new(['Hello/the-path'], migration) result_ids = described_class.new(['Hello/the-path'], migration)
.projects_for_paths.map(&:id) .projects_for_paths.map(&:id)
...@@ -30,6 +32,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -30,6 +32,9 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
it 'includes the correct projects' do it 'includes the correct projects' do
project = create(:project, :legacy_storage, path: 'THE-path') project = create(:project, :legacy_storage, path: 'THE-path')
project.create_repository
project.create_wiki
_other_project = create(:project, :legacy_storage) _other_project = create(:project, :legacy_storage)
result_ids = subject.projects_for_paths.map(&:id) result_ids = subject.projects_for_paths.map(&:id)
...@@ -41,6 +46,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -41,6 +46,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
describe '#rename_projects' do describe '#rename_projects' do
let!(:projects) { create_list(:project, 2, :legacy_storage, path: 'the-path') } let!(:projects) { create_list(:project, 2, :legacy_storage, path: 'the-path') }
before do
projects.each do |p|
p.create_repository
p.create_wiki
end
end
it 'renames each project' do it 'renames each project' do
expect(subject).to receive(:rename_project).twice expect(subject).to receive(:rename_project).twice
...@@ -56,6 +68,10 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -56,6 +68,10 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
end end
describe '#rename_project' do describe '#rename_project' do
before do
project.create_repository
project.create_wiki
end
it 'renames path & route for the project' do it 'renames path & route for the project' do
expect(subject).to receive(:rename_path_for_routable) expect(subject).to receive(:rename_path_for_routable)
.with(project) .with(project)
...@@ -81,6 +97,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -81,6 +97,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
end end
describe '#move_project_folders' do describe '#move_project_folders' do
before do
project.create_repository
project.create_wiki
end
it 'moves the wiki & the repo' do it 'moves the wiki & the repo' do
expect(subject).to receive(:move_repository) expect(subject).to receive(:move_repository)
.with(project, 'known-parent/the-path.wiki', 'known-parent/the-path0.wiki') .with(project, 'known-parent/the-path.wiki', 'known-parent/the-path0.wiki')
...@@ -125,6 +146,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -125,6 +146,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
let(:known_parent) { create(:namespace, path: 'known-parent') } let(:known_parent) { create(:namespace, path: 'known-parent') }
let(:project) { create(:project, :repository, :legacy_storage, path: 'the-path', namespace: known_parent) } let(:project) { create(:project, :repository, :legacy_storage, path: 'the-path', namespace: known_parent) }
before do
project.create_repository
project.create_wiki
end
it 'moves the repository for a project' do it 'moves the repository for a project' do
expected_path = File.join(TestEnv.repos_path, 'known-parent', 'new-repo.git') expected_path = File.join(TestEnv.repos_path, 'known-parent', 'new-repo.git')
...@@ -135,6 +161,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -135,6 +161,11 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
end end
describe '#revert_renames', :redis do describe '#revert_renames', :redis do
before do
project.create_repository
project.create_wiki
end
it 'renames the routes back to the previous values' do it 'renames the routes back to the previous values' do
subject.rename_project(project) subject.rename_project(project)
...@@ -152,7 +183,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de ...@@ -152,7 +183,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1::RenameProjects, :de
end end
it 'moves the repositories back to their original place' do it 'moves the repositories back to their original place' do
project.create_repository
subject.rename_project(project) subject.rename_project(project)
expected_path = File.join(TestEnv.repos_path, 'known-parent', 'the-path.git') expected_path = File.join(TestEnv.repos_path, 'known-parent', 'the-path.git')
......
...@@ -362,9 +362,9 @@ describe Namespace do ...@@ -362,9 +362,9 @@ describe Namespace do
it 'updates project full path in .git/config' do it 'updates project full path in .git/config' do
parent.update(path: 'mygroup_new') parent.update(path: 'mygroup_new')
expect(project_rugged(project_in_parent_group).config['gitlab.fullpath']).to eq "mygroup_new/#{project_in_parent_group.path}" expect(project_rugged(project_in_parent_group.reload).config['gitlab.fullpath']).to eq "mygroup_new/#{project_in_parent_group.path}"
expect(project_rugged(hashed_project_in_subgroup).config['gitlab.fullpath']).to eq "mygroup_new/mysubgroup/#{hashed_project_in_subgroup.path}" expect(project_rugged(hashed_project_in_subgroup.reload).config['gitlab.fullpath']).to eq "mygroup_new/mysubgroup/#{hashed_project_in_subgroup.path}"
expect(project_rugged(legacy_project_in_subgroup).config['gitlab.fullpath']).to eq "mygroup_new/mysubgroup/#{legacy_project_in_subgroup.path}" expect(project_rugged(legacy_project_in_subgroup.reload).config['gitlab.fullpath']).to eq "mygroup_new/mysubgroup/#{legacy_project_in_subgroup.path}"
end end
it 'updates the project storage location' do it 'updates the project storage location' do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册