Create Geo repository updated events when mirrors are updated

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