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 ...@@ -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)
......
---
title: 'Geo: Replicate repository changes when mirrors are updated'
merge_request: 39295
author:
type: fixed
...@@ -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,81 +1708,87 @@ RSpec.describe Project do ...@@ -1708,81 +1708,87 @@ RSpec.describe Project do
end end
describe '#after_import' do describe '#after_import' do
let(:project) { create(:project) } let_it_be(:project) { create(: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)
.and_return(repository_updated_service)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.wiki.repository)
.and_return(wiki_updated_service)
allow(::Geo::RepositoryUpdatedService) context 'Geo repository update events' do
.to receive(:new) let_it_be(:import_state) { create(:import_state, :started, project: project) }
.with(project.design_repository) let(:repository_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
.and_return(design_updated_service) let(:wiki_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
end let(:design_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do before do
allow(Gitlab::Geo).to receive(:primary?).and_return(true) allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project.repository)
.and_return(repository_updated_service)
expect(repository_updated_service).to receive(:execute).once allow(::Geo::RepositoryUpdatedService)
expect(wiki_updated_service).to receive(:execute).once .to receive(:new)
expect(design_updated_service).to receive(:execute).once .with(project.wiki.repository)
.and_return(wiki_updated_service)
project.after_import allow(::Geo::RepositoryUpdatedService)
end .to receive(:new)
.with(project.design_repository)
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do .and_return(design_updated_service)
allow(Gitlab::Geo).to receive(:primary?).and_return(false) end
expect(repository_updated_service).not_to receive(:execute) it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node', :aggregate_failures do
expect(wiki_updated_service).not_to receive(:execute) stub_primary_node
project.after_import expect(repository_updated_service).to receive(:execute).once
end expect(wiki_updated_service).to receive(:execute).once
expect(design_updated_service).to receive(:execute).once
context 'elasticsearch indexing disabled for this project' do project.after_import
before do
expect(project).to receive(:use_elasticsearch?).and_return(false)
end end
it 'does not index the wiki repository' do it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node', :aggregate_failures do
expect(ElasticCommitIndexerWorker).not_to receive(:perform_async) 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 project.after_import
end end
end end
context 'elasticsearch indexing enabled for this project' do context 'elasticsearch indexing' do
before do let_it_be(:import_state) { create(:import_state, project: project) }
expect(project).to receive(:use_elasticsearch?).and_return(true)
end context 'elasticsearch indexing disabled for this project' do
before do
expect(project).to receive(:use_elasticsearch?).and_return(false)
end
it 'schedules a full index of the wiki repository' do it 'does not index the wiki repository' do
expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(project.id, nil, nil, true) expect(ElasticCommitIndexerWorker).not_to receive(:perform_async)
project.after_import project.after_import
end
end end
context 'when project is forked' do context 'elasticsearch indexing enabled for this project' do
before do before do
expect(project).to receive(:forked?).and_return(true) expect(project).to receive(:use_elasticsearch?).and_return(true)
end end
it 'does not index the wiki repository' do
expect(ElasticCommitIndexerWorker).not_to receive(:perform_async) it 'schedules a full index of the wiki repository' do
expect(ElasticCommitIndexerWorker).to receive(:perform_async).with(project.id, nil, nil, true)
project.after_import project.after_import
end end
context 'when project is forked' 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)
project.after_import
end
end
end end
end end
end end
......
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