Decide what actions to take based on the change in storage_version

parent 51b33e29
module Geo
class HashedStorageMigrationService
attr_reader :project_id, :old_disk_path, :new_disk_path
attr_reader :project_id, :old_disk_path, :new_disk_path,
:old_storage_version, :new_storage_version
def initialize(project_id, old_disk_path, new_disk_path)
def initialize(project_id, old_disk_path, new_disk_path, old_storage_version, new_storage_version)
@project_id = project_id
@old_disk_path = old_disk_path
@new_disk_path = new_disk_path
@old_storage_version = old_storage_version
@new_storage_version = new_storage_version
end
def async_execute
Geo::HashedStorageMigrationWorker.perform_async(project_id, old_disk_path, new_disk_path)
Geo::HashedStorageMigrationWorker.perform_async(project_id, old_disk_path, new_disk_path, old_storage_version, new_storage_version)
end
def execute
project = Project.find(project_id)
project.expire_caches_before_rename(old_disk_path)
if migrating_from_legacy_storage?
Geo::MoveRepositoryService.new(project, old_disk_path, new_disk_path).execute
end
true
end
private
def migrating_from_legacy_storage?
from_legacy_storage? && new_storage_version >= Project::HASHED_STORAGE_FEATURES[:repository]
end
def from_legacy_storage?
old_storage_version.nil? || old_storage_version.zero?
end
end
end
......@@ -3,8 +3,14 @@ module Geo
include Sidekiq::Worker
include GeoQueue
def perform(project_id, old_disk_path, new_disk_path)
Geo::HashedStorageMigrationService.new(project_id, old_disk_path, new_disk_path).execute
def perform(project_id, old_disk_path, new_disk_path, old_storage_version, new_storage_version)
Geo::HashedStorageMigrationService.new(
project_id,
old_disk_path,
new_disk_path,
old_storage_version,
new_storage_version
).execute
end
end
end
......@@ -201,9 +201,13 @@ module Gitlab
event = event_log.hashed_storage_migrated_event
return unless event.project_id
job_id = ::Geo::HashedStorageMigrationService
.new(event.project_id, event.old_disk_path, event.new_disk_path)
.async_execute
job_id = ::Geo::HashedStorageMigrationService.new(
event.project_id,
event.old_disk_path,
event.new_disk_path,
event.old_storage_version,
event.new_storage_version
).async_execute
log_event_info(
event_log.created_at,
......
......@@ -3,28 +3,29 @@ require 'spec_helper'
describe Geo::HashedStorageMigrationService do
let(:project) { create(:project, :repository) }
let(:new_path) { "#{project.full_path}+renamed" }
let(:new_storage_version) { Project::LATEST_STORAGE_VERSION }
describe '#execute' do
it 'moves project backed by legacy storage' do
service = described_class.new(project.id, project.full_path, new_path)
service = described_class.new(project.id, project.full_path, new_path, project.storage_version, new_storage_version)
expect_any_instance_of(Geo::MoveRepositoryService).to receive(:execute).once
service.execute
end
it 'moves project backed by hashed storage' do
it 'does not move project backed by hashed storage' do
project_hashed_storage = create(:project, :hashed)
service = described_class.new(project_hashed_storage.id, project_hashed_storage.full_path, new_path)
service = described_class.new(project_hashed_storage.id, project_hashed_storage.full_path, new_path, project.storage_version, new_storage_version)
expect_any_instance_of(Geo::MoveRepositoryService).to receive(:execute).once
expect_any_instance_of(Geo::MoveRepositoryService).not_to receive(:execute).once
service.execute
end
end
describe '#async_execute' do
subject(:service) { described_class.new(project.id, project.full_path, new_path) }
subject(:service) { described_class.new(project.id, project.full_path, new_path, project.storage_version, new_storage_version) }
it 'starts the worker' do
expect(Geo::HashedStorageMigrationWorker).to receive(:perform_async)
......
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