summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2019-01-17 02:57:35 +0100
committerGabriel Mazetto <brodock@gmail.com>2019-03-01 15:49:20 +0100
commit1592b5830f7b2847dff02ef2c66b745cdc60565a (patch)
tree27066c127717d21ed67f8081c3a6f3ef0332d178 /app/workers
parentff2ca3569e704bb26c770ba5c28a888789d27230 (diff)
downloadgitlab-ce-1592b5830f7b2847dff02ef2c66b745cdc60565a.tar.gz
Adds Rollback functionality to HashedStorage migration
We are adding sidekiq workers and service classes to allow to rollback a hashed storage migration. There are some refactoring involved as well as part of the code can be reused by both the migration and the rollback logic.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/all_queues.yml1
-rw-r--r--app/workers/project_rollback_hashed_storage_worker.rb42
2 files changed, 43 insertions, 0 deletions
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index 337f39b2091..82351c1334f 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -127,6 +127,7 @@
- project_destroy
- project_export
- project_migrate_hashed_storage
+- project_rollback_hashed_storage
- project_service
- propagate_service_template
- reactive_caching
diff --git a/app/workers/project_rollback_hashed_storage_worker.rb b/app/workers/project_rollback_hashed_storage_worker.rb
new file mode 100644
index 00000000000..38faffd2bfa
--- /dev/null
+++ b/app/workers/project_rollback_hashed_storage_worker.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+class ProjectRollbackHashedStorageWorker
+ include ApplicationWorker
+
+ LEASE_TIMEOUT = 30.seconds.to_i
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def perform(project_id, old_disk_path = nil)
+ uuid = lease_for(project_id).try_obtain
+
+ if uuid
+ project = Project.find_by(id: project_id)
+ return if project.nil? || project.pending_delete?
+
+ old_disk_path ||= project.disk_path
+
+ ::Projects::HashedStorage::RollbackService.new(project, old_disk_path, logger: logger).execute
+ else
+ return false
+ end
+
+ ensure
+ cancel_lease_for(project_id, uuid) if uuid
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ def lease_for(project_id)
+ Gitlab::ExclusiveLease.new(lease_key(project_id), timeout: LEASE_TIMEOUT)
+ end
+
+ private
+
+ def lease_key(project_id)
+ # we share the same lease key for both migration and rollback so they don't run simultaneously
+ "#{ProjectMigrateHashedStorageWorker::LEASE_KEY_SEGMENT}:#{project_id}"
+ end
+
+ def cancel_lease_for(project_id, uuid)
+ Gitlab::ExclusiveLease.cancel(lease_key(project_id), uuid)
+ end
+end