diff options
author | Gabriel Mazetto <brodock@gmail.com> | 2019-01-23 03:40:05 +0100 |
---|---|---|
committer | Gabriel Mazetto <brodock@gmail.com> | 2019-03-01 15:49:20 +0100 |
commit | fc0ff92807620c36d01f23eb0d7d88b02cb141c1 (patch) | |
tree | 8241564fc370782be698266bb14d5c1a69a1ded0 /app/services/projects | |
parent | d63380fa93dff921c69f7aaa31ff004864e4db13 (diff) | |
download | gitlab-ce-fc0ff92807620c36d01f23eb0d7d88b02cb141c1.tar.gz |
Added Rollbacker workers and support on the rake task
Rollback is done similar to Migration for the Hashed Storage.
It also shares the same ExclusiveLease key to prevent both happening
at the same time.
All Hashed Storage related workers now share the same queue namespace
which allows for assigning dedicated workers easily.
Diffstat (limited to 'app/services/projects')
4 files changed, 45 insertions, 8 deletions
diff --git a/app/services/projects/hashed_storage/migrate_attachments_service.rb b/app/services/projects/hashed_storage/migrate_attachments_service.rb index 03e0685d2cd..0df1e4ee130 100644 --- a/app/services/projects/hashed_storage/migrate_attachments_service.rb +++ b/app/services/projects/hashed_storage/migrate_attachments_service.rb @@ -5,13 +5,21 @@ module Projects AttachmentMigrationError = Class.new(StandardError) class MigrateAttachmentsService < BaseService - attr_reader :logger, :old_disk_path, :new_disk_path + # Returns the disk_path value before the execution + # This is used in EE for Geo + attr_reader :old_disk_path + + # Returns the diks_path value after the execution + # This is used in EE for Geo + attr_reader :new_disk_path + + # Returns the logger currently in use + attr_reader :logger def initialize(project, old_disk_path, logger: nil) @project = project @logger = logger || Rails.logger @old_disk_path = old_disk_path - @new_disk_path = project.disk_path @skipped = false end @@ -23,6 +31,8 @@ module Projects project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:attachments] target = FileUploader.absolute_base_dir(project) + @new_disk_path = project.disk_path + result = move_folder!(origin, target) project.save! @@ -33,6 +43,10 @@ module Projects result end + # Return whether this operation was skipped or not + # This is used in EE for Geo to decide if an event will be triggered or not + # + # @return [Boolean] true if skipped of false otherwise def skipped? @skipped end @@ -43,12 +57,13 @@ module Projects unless File.directory?(old_path) logger.info("Skipped attachments migration from '#{old_path}' to '#{new_path}', source path doesn't exist or is not a directory (PROJECT_ID=#{project.id})") @skipped = true + return true end if File.exist?(new_path) logger.error("Cannot migrate attachments from '#{old_path}' to '#{new_path}', target path already exist (PROJECT_ID=#{project.id})") - raise AttachmentMigrationError, "Target path '#{new_path}' already exist" + raise AttachmentMigrationError, "Target path '#{new_path}' already exists" end # Create hashed storage base path folder diff --git a/app/services/projects/hashed_storage/migrate_repository_service.rb b/app/services/projects/hashed_storage/migrate_repository_service.rb index 9c672283c7e..a45d8ace2df 100644 --- a/app/services/projects/hashed_storage/migrate_repository_service.rb +++ b/app/services/projects/hashed_storage/migrate_repository_service.rb @@ -15,7 +15,7 @@ module Projects result = move_repository(old_disk_path, new_disk_path) if move_wiki - result &&= move_repository("#{old_wiki_disk_path}", "#{new_disk_path}.wiki") + result &&= move_repository(old_wiki_disk_path, "#{new_disk_path}.wiki") end if result diff --git a/app/services/projects/hashed_storage/rollback_attachments_service.rb b/app/services/projects/hashed_storage/rollback_attachments_service.rb index 5183609ab85..8d0de27d30b 100644 --- a/app/services/projects/hashed_storage/rollback_attachments_service.rb +++ b/app/services/projects/hashed_storage/rollback_attachments_service.rb @@ -5,11 +5,21 @@ module Projects AttachmentRollbackError = Class.new(StandardError) class RollbackAttachmentsService < BaseService - attr_reader :logger, :old_disk_path + # Returns the disk_path value before the execution + # This is used in EE for Geo + attr_reader :old_disk_path + + # Returns the diks_path value after the execution + # This is used in EE for Geo + attr_reader :new_disk_path + + # Returns the logger currently in use + attr_reader :logger def initialize(project, logger: nil) @project = project @logger = logger || Rails.logger + @old_disk_path = project.disk_path end def execute @@ -17,6 +27,8 @@ module Projects project.storage_version = ::Project::HASHED_STORAGE_FEATURES[:repository] target = FileUploader.absolute_base_dir(project) + @new_disk_path = FileUploader.base_dir(project) + result = move_folder!(origin, target) project.save! @@ -27,24 +39,34 @@ module Projects result end + # Return whether this operation was skipped or not + # This is used in EE for Geo to decide if an event will be triggered or not + # + # @return [Boolean] true if skipped of false otherwise + def skipped? + @skipped + end + private def move_folder!(old_path, new_path) unless File.directory?(old_path) logger.info("Skipped attachments rollback from '#{old_path}' to '#{new_path}', source path doesn't exist or is not a directory (PROJECT_ID=#{project.id})") + @skipped = true + return true end if File.exist?(new_path) logger.error("Cannot rollback attachments from '#{old_path}' to '#{new_path}', target path already exist (PROJECT_ID=#{project.id})") - raise AttachmentRollbackError, "Target path '#{new_path}' already exist" + raise AttachmentRollbackError, "Target path '#{new_path}' already exists" end # Create hashed storage base path folder FileUtils.mkdir_p(File.dirname(new_path)) FileUtils.mv(old_path, new_path) - logger.info("Rolledback project attachments from '#{old_path}' to '#{new_path}' (PROJECT_ID=#{project.id})") + logger.info("Rolled project attachments back from '#{old_path}' to '#{new_path}' (PROJECT_ID=#{project.id})") true end diff --git a/app/services/projects/hashed_storage/rollback_repository_service.rb b/app/services/projects/hashed_storage/rollback_repository_service.rb index b57d05c50ca..46956ed72c7 100644 --- a/app/services/projects/hashed_storage/rollback_repository_service.rb +++ b/app/services/projects/hashed_storage/rollback_repository_service.rb @@ -15,7 +15,7 @@ module Projects result = move_repository(old_disk_path, new_disk_path) if move_wiki - result &&= move_repository("#{old_wiki_disk_path}", "#{new_disk_path}.wiki") + result &&= move_repository(old_wiki_disk_path, "#{new_disk_path}.wiki") end if result |