Commit 0a2f474e authored by Valery Sizov's avatar Valery Sizov Committed by Douglas Barbosa Alexandre

Geo: Synchronize repository and registry removal

Moving registry deletion into the job that deletes
the files and project record
parent d7ce1b1d
module Geo
class RepositoryDestroyService
include ::Gitlab::Geo::LogHelpers
attr_reader :id, :name, :disk_path, :repository_storage
def initialize(id, name, disk_path, repository_storage)
......@@ -14,11 +16,24 @@ module Geo
end
def execute
::Projects::DestroyService.new(deleted_project, nil).geo_replicate
destroy_project
delete_project_registry_entries
end
private
def destroy_project
::Projects::DestroyService.new(deleted_project, nil).geo_replicate
end
# rubocop: disable CodeReuse/ActiveRecord
def delete_project_registry_entries
::Geo::ProjectRegistry.where(project_id: id).delete_all
log_info("Project registry entry removed", project_id: id)
end
# rubocop: enable CodeReuse/ActiveRecord
def deleted_project
# We don't have access to the original model anymore, so we are
# rebuilding only what our service class requires
......
---
title: 'Geo: Moving registry deletion into the job that deletes the files and project
record'
merge_request: 8480
author:
type: fixed
......@@ -10,7 +10,6 @@ module Gitlab
unless skippable?
job_id = destroy_repository
delete_project_registry_entries
end
log_event(job_id)
......@@ -28,12 +27,6 @@ module Gitlab
).async_execute
end
# rubocop: disable CodeReuse/ActiveRecord
def delete_project_registry_entries
::Geo::ProjectRegistry.where(project_id: event.project_id).delete_all
end
# rubocop: enable CodeReuse/ActiveRecord
def log_event(job_id)
logger.event_info(
created_at,
......
......@@ -32,10 +32,6 @@ describe Gitlab::Geo::LogCursor::Events::RepositoryDeletedEvent, :postgresql, :c
context 'when a tracking entry exists' do
let!(:tracking_entry) { create(:geo_project_registry, project: project) }
it 'removes the tracking entry' do
expect { subject.process }.to change(Geo::ProjectRegistry, :count).by(-1)
end
context 'when selective sync is enabled' do
let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [project.namespace]) }
......@@ -47,6 +43,10 @@ describe Gitlab::Geo::LogCursor::Events::RepositoryDeletedEvent, :postgresql, :c
subject.process
end
it 'does not remove the tracking entry' do
expect { subject.process }.not_to change(Geo::ProjectRegistry, :count)
end
end
end
end
......
......@@ -27,6 +27,12 @@ describe Geo::RepositoryDestroyService do
service.execute
end
it 'removes the tracking entry' do
create(:geo_project_registry, project: project)
expect { service.execute }.to change(Geo::ProjectRegistry, :count).by(-1)
end
context 'legacy storage project' do
let(:project) { create(:project_empty_repo, :legacy_storage) }
......
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