Commit 035c81a1 authored by Michael Kozono's avatar Michael Kozono

Merge branch '235674-mirrored-projects-don-t-replicate-tags-to-secondary-nodes' into 'master'

Geo - Create repository updated events when mirrors are updated

Closes #235674

See merge request gitlab-org/gitlab!39295
parents 973c6177 58e27660
......@@ -583,15 +583,18 @@ module EE
override :after_import
def after_import
super
repository.log_geo_updated_event
wiki.repository.log_geo_updated_event
design_repository.log_geo_updated_event
# Index the wiki repository after import of non-forked projects only, the project repository is indexed
# in ProjectImportState so ElasticSearch will get project repository changes when mirrors are updated
ElasticCommitIndexerWorker.perform_async(id, nil, nil, true) if use_elasticsearch? && !forked?
end
def log_geo_updated_events
repository.log_geo_updated_event
wiki.repository.log_geo_updated_event
design_repository.log_geo_updated_event
end
override :import?
def import?
super || gitlab_custom_project_template_import?
......
......@@ -59,6 +59,9 @@ module EE
end
after_transition started: :finished do |state, _|
# Create a Geo event so changes will be replicated to secondary node(s).
state.project.log_geo_updated_events
if state.project.use_elasticsearch?
state.run_after_commit do
ElasticCommitIndexerWorker.perform_async(state.project_id)
......
---
title: 'Geo: Replicate repository changes when mirrors are updated'
merge_request: 39295
author:
type: fixed
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe ProjectImportState, type: :model do
include ::EE::GeoHelpers
describe 'Project import job' do
let(:project) { import_state.project }
......@@ -33,6 +35,47 @@ RSpec.describe ProjectImportState, type: :model do
let(:project) { import_state.project }
context 'state transition: [:started] => [:finished]' do
context 'Geo repository update events' do
let(:repository_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:wiki_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:design_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
before do
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.repository)
.and_return(repository_updated_service)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.wiki.repository)
.and_return(wiki_updated_service)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.design_repository)
.and_return(design_updated_service)
end
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node', :aggregate_failures do
stub_primary_node
expect(repository_updated_service).to receive(:execute).once
expect(wiki_updated_service).to receive(:execute).once
expect(design_updated_service).to receive(:execute).once
import_state.finish
end
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node', :aggregate_failures do
expect(repository_updated_service).not_to receive(:execute)
expect(wiki_updated_service).not_to receive(:execute)
expect(design_updated_service).not_to receive(:execute)
import_state.finish
end
end
context 'elasticsearch indexing disabled for this project' do
before do
expect(project).to receive(:use_elasticsearch?).and_return(false)
......
......@@ -1708,14 +1708,15 @@ RSpec.describe Project do
end
describe '#after_import' do
let(:project) { create(:project) }
let_it_be(:project) { create(:project) }
context 'Geo repository update events' do
let_it_be(:import_state) { create(:import_state, :started, project: project) }
let(:repository_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:wiki_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:design_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
before do
create(:import_state, project: project)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.repository)
......@@ -1732,8 +1733,8 @@ RSpec.describe Project do
.and_return(design_updated_service)
end
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node', :aggregate_failures do
stub_primary_node
expect(repository_updated_service).to receive(:execute).once
expect(wiki_updated_service).to receive(:execute).once
......@@ -1742,14 +1743,17 @@ RSpec.describe Project do
project.after_import
end
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?).and_return(false)
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node', :aggregate_failures do
expect(repository_updated_service).not_to receive(:execute)
expect(wiki_updated_service).not_to receive(:execute)
expect(design_updated_service).not_to receive(:execute)
project.after_import
end
end
context 'elasticsearch indexing' do
let_it_be(:import_state) { create(:import_state, project: project) }
context 'elasticsearch indexing disabled for this project' do
before do
......@@ -1778,6 +1782,7 @@ RSpec.describe Project do
before do
expect(project).to receive(:forked?).and_return(true)
end
it 'does not index the wiki repository' do
expect(ElasticCommitIndexerWorker).not_to receive(:perform_async)
......@@ -1786,6 +1791,7 @@ RSpec.describe Project do
end
end
end
end
describe '#lfs_http_url_to_repo' do
let(:project) { create(:project) }
......
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