Commit 27d7a37c authored by Gabriel Mazetto's avatar Gabriel Mazetto

Added rename_repository replication support for Geo

parent d3e2d9d5
module Geo
class RenameRepositoryService
include Gitlab::ShellAdapter
attr_reader :id, :name, :old_path_with_namespace, :new_path_with_namespace
def initialize(id, name, old_path_with_namespace, new_path_with_namespace)
@id = id
@name = name
@old_path_with_namespace = old_path_with_namespace
@new_path_with_namespace = new_path_with_namespace
end
def execute
project = Project.find(id)
project.expire_caches_before_rename(old_path_with_namespace)
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to send update instructions to users.
# However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions
begin
gitlab_shell.mv_repository("#{old_path_with_namespace}.wiki", "#{new_path_with_namespace}.wiki")
rescue
# Returning false does not rollback after_* transaction but gives
# us information about failing some of tasks
false
end
else
# if we cannot move namespace directory we should rollback
# db changes in order to prevent out of sync between db and fs
raise Exception.new('repository cannot be renamed')
end
end
end
end
module Geo
class ScheduleRepoRenameService
attr_reader :id, :name, :old_path_with_namespace, :path_with_namespace
def initialize(params)
@id = params['project_id']
@name = params['name']
@old_path_with_namespace = params['old_path_with_namespace']
@path_with_namespace = params['path_with_namespace']
end
def execute
GeoRepositoryRenameWorker.perform_async(id, name, old_path_with_namespace, path_with_namespace)
end
end
end
class GeoRepositoryRenameWorker
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(id, name, old_path_with_namespace, new_path_with_namespace)
Geo::RenameRepositoryService.new(id, name, old_path_with_namespace, new_path_with_namespace).execute
end
end
...@@ -33,6 +33,9 @@ module API ...@@ -33,6 +33,9 @@ module API
when 'project_destroy' when 'project_destroy'
required_attributes! %w(event_name project_id path_with_namespace) required_attributes! %w(event_name project_id path_with_namespace)
::Geo::ScheduleRepoDestroyService.new(params).execute ::Geo::ScheduleRepoDestroyService.new(params).execute
when 'project_rename'
required_attributes! %w(event_name project_id path_with_namespace old_path_with_namespace)
::Geo::ScheduleRepoRenameService.new(params).execute
end end
end 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