Decide what actions to take based on the change in storage_version

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