Use keyword argument on Geo::HashedStorageMigrationService

parent c57fe5aa
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
:old_storage_version, :new_storage_version
def initialize(project_id, old_disk_path, new_disk_path, old_storage_version, new_storage_version) def initialize(project_id, old_disk_path:, new_disk_path:, old_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 @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, old_storage_version, new_storage_version) Geo::HashedStorageMigrationWorker.perform_async(
project_id,
old_disk_path,
new_disk_path,
old_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? if migrating_from_legacy_storage?(project)
Geo::MoveRepositoryService.new(project, old_disk_path, new_disk_path).execute Geo::MoveRepositoryService.new(project, old_disk_path, new_disk_path).execute
end end
...@@ -28,8 +31,8 @@ module Geo ...@@ -28,8 +31,8 @@ module Geo
private private
def migrating_from_legacy_storage? def migrating_from_legacy_storage?(project)
from_legacy_storage? && new_storage_version >= Project::HASHED_STORAGE_FEATURES[:repository] from_legacy_storage? && project.hashed_storage?(:repository)
end end
def from_legacy_storage? def from_legacy_storage?
......
...@@ -3,13 +3,12 @@ module Geo ...@@ -3,13 +3,12 @@ module Geo
include Sidekiq::Worker include Sidekiq::Worker
include GeoQueue include GeoQueue
def perform(project_id, old_disk_path, new_disk_path, old_storage_version, new_storage_version) def perform(project_id, old_disk_path, new_disk_path, old_storage_version)
Geo::HashedStorageMigrationService.new( Geo::HashedStorageMigrationService.new(
project_id, project_id,
old_disk_path, old_disk_path: old_disk_path,
new_disk_path, new_disk_path: new_disk_path,
old_storage_version, old_storage_version: old_storage_version
new_storage_version
).execute ).execute
end end
end end
......
...@@ -203,10 +203,9 @@ module Gitlab ...@@ -203,10 +203,9 @@ module Gitlab
job_id = ::Geo::HashedStorageMigrationService.new( job_id = ::Geo::HashedStorageMigrationService.new(
event.project_id, event.project_id,
event.old_disk_path, old_disk_path: event.old_disk_path,
event.new_disk_path, new_disk_path: event.new_disk_path,
event.old_storage_version, old_storage_version: event.old_storage_version
event.new_storage_version
).async_execute ).async_execute
log_event_info( log_event_info(
......
...@@ -230,10 +230,9 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do ...@@ -230,10 +230,9 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql do
old_disk_path = hashed_storage_migrated_event.old_disk_path old_disk_path = hashed_storage_migrated_event.old_disk_path
new_disk_path = hashed_storage_migrated_event.new_disk_path new_disk_path = hashed_storage_migrated_event.new_disk_path
old_storage_version = project.storage_version old_storage_version = project.storage_version
new_storage_version = hashed_storage_migrated_event.new_storage_version
expect(::Geo::HashedStorageMigrationWorker).to receive(:perform_async) expect(::Geo::HashedStorageMigrationWorker).to receive(:perform_async)
.with(project.id, old_disk_path, new_disk_path, old_storage_version, new_storage_version) .with(project.id, old_disk_path, new_disk_path, old_storage_version)
daemon.run_once! daemon.run_once!
end end
......
require 'spec_helper' require 'spec_helper'
describe Geo::HashedStorageMigrationService do describe Geo::HashedStorageMigrationService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository, :hashed) }
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, project.storage_version, new_storage_version) service = described_class.new(
project.id,
old_disk_path: project.full_path,
new_disk_path: new_path,
old_storage_version: nil
)
expect_any_instance_of(Geo::MoveRepositoryService).to receive(:execute).once expect_any_instance_of(Geo::MoveRepositoryService).to receive(:execute).once
...@@ -15,8 +19,12 @@ describe Geo::HashedStorageMigrationService do ...@@ -15,8 +19,12 @@ describe Geo::HashedStorageMigrationService do
end end
it 'does not move 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(
service = described_class.new(project_hashed_storage.id, project_hashed_storage.full_path, new_path, project.storage_version, new_storage_version) project.id,
old_disk_path: project.full_path,
new_disk_path: "#{project.full_path}+renamed",
old_storage_version: project.storage_version
)
expect_any_instance_of(Geo::MoveRepositoryService).not_to receive(:execute).once expect_any_instance_of(Geo::MoveRepositoryService).not_to receive(:execute).once
...@@ -25,7 +33,7 @@ describe Geo::HashedStorageMigrationService do ...@@ -25,7 +33,7 @@ describe Geo::HashedStorageMigrationService do
end end
describe '#async_execute' do describe '#async_execute' do
subject(:service) { described_class.new(project.id, project.full_path, new_path, project.storage_version, new_storage_version) } subject(:service) { described_class.new(project.id, old_disk_path: project.full_path, new_disk_path: new_path, old_storage_version: nil) }
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