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