Commit e02ee4b2 authored by Toon Claes's avatar Toon Claes

Do not generate Geo Log events when there are no secondaries

When there are no secondary nodes configured, there is no need to
generate Geo Log Events because no one will handle them.
parent 3e3f8786
......@@ -30,6 +30,7 @@ module Geo
def create
return unless Gitlab::Geo.primary?
return unless Gitlab::Geo.secondary_nodes.any? # no need to create an event if no one is listening
Geo::EventLog.create!("#{self.class.event_type}" => build_event)
rescue ActiveRecord::RecordInvalid, NoMethodError => e
......
......@@ -67,7 +67,8 @@ describe Namespace do
describe '#move_dir' do
context 'when running on a primary node' do
let!(:geo_node) { create(:geo_node, :primary) }
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
let(:gitlab_shell) { Gitlab::Shell.new }
it 'logs the Geo::RepositoryRenamedEvent for each project inside namespace' do
......@@ -84,7 +85,6 @@ describe Namespace do
allow(parent).to receive(:full_path).and_return(new_path)
allow(gitlab_shell).to receive(:mv_namespace)
.ordered
.with(project_1.repository_storage_path, full_path_was, new_path)
.and_return(true)
......
......@@ -759,7 +759,8 @@ describe Project do
describe '#rename_repo' do
context 'when running on a primary node' do
let!(:geo_node) { create(:geo_node, :primary) }
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
let(:project) { create(:project, :repository) }
let(:gitlab_shell) { Gitlab::Shell.new }
......
......@@ -161,7 +161,8 @@ describe Projects::CreateService, '#execute' do
end
context 'when running on a primary node' do
let!(:geo_node) { create(:geo_node, :primary) }
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
it 'logs an event to the Geo event log' do
expect { create_project(user, opts) }.to change(Geo::RepositoryCreatedEvent, :count).by(1)
......
......@@ -31,7 +31,8 @@ describe Projects::DestroyService do
end
context 'when running on a primary node' do
let!(:geo_node) { create(:geo_node, :primary) }
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
it 'logs an event to the Geo event log' do
# Run Sidekiq immediately to check that renamed repository will be removed
......
......@@ -7,9 +7,10 @@ describe Projects::HashedStorageMigrationService do
let(:hashed_storage) { Storage::HashedProject.new(project) }
describe '#execute' do
it 'creates a Geo::RepositoryRenamedEvent on success' do
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
it 'creates a Geo::RepositoryRenamedEvent on success' do
expect { service.execute }.to change { Geo::EventLog.count }.by(1)
event = Geo::EventLog.first.event
......@@ -32,7 +33,6 @@ describe Projects::HashedStorageMigrationService do
allow(service).to receive(:move_repository).and_call_original
allow(service).to receive(:move_repository).with(from_name, to_name).once { false } # will disable first move only
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
expect { service.execute }.not_to change { Geo::EventLog.count }
end
end
......
......@@ -12,7 +12,8 @@ describe Projects::TransferService do
end
context 'when running on a primary node' do
let!(:geo_node) { create(:geo_node, :primary) }
set(:primary) { create(:geo_node, :primary) }
set(:secondary) { create(:geo_node) }
it 'logs an event to the Geo event log' do
expect { subject.execute(group) }.to change(Geo::RepositoryRenamedEvent, :count).by(1)
......
......@@ -2,6 +2,7 @@ require 'spec_helper'
describe Geo::RepositoryCreatedEventStore do
set(:project) { create(:project) }
set(:secondary_node) { create(:geo_node) }
subject(:create!) { described_class.new(project).create }
......@@ -17,6 +18,12 @@ describe Geo::RepositoryCreatedEventStore do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { create! }.not_to change(Geo::RepositoryCreatedEvent, :count)
end
it 'creates a created event' do
expect { create! }.to change(Geo::RepositoryCreatedEvent, :count).by(1)
end
......
require 'spec_helper'
describe Geo::RepositoryDeletedEventStore do
let(:project) { create(:project, path: 'bar') }
let!(:project_id) { project.id }
let!(:project_name) { project.name }
let!(:repo_path) { project.full_path }
let!(:wiki_path) { "#{project.full_path}.wiki" }
let!(:storage_name) { project.repository_storage }
let!(:storage_path) { project.repository_storage_path }
set(:project) { create(:project, path: 'bar') }
set(:secondary_node) { create(:geo_node) }
let(:project_id) { project.id }
let(:project_name) { project.name }
let(:repo_path) { project.full_path }
let(:wiki_path) { "#{project.full_path}.wiki" }
let(:storage_name) { project.repository_storage }
let(:storage_path) { project.repository_storage_path }
subject { described_class.new(project, repo_path: repo_path, wiki_path: wiki_path) }
......@@ -23,6 +24,12 @@ describe Geo::RepositoryDeletedEventStore do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(Geo::RepositoryDeletedEvent, :count)
end
it 'creates a deleted event' do
expect { subject.create }.to change(Geo::RepositoryDeletedEvent, :count).by(1)
end
......
require 'spec_helper'
describe Geo::RepositoryRenamedEventStore do
let(:project) { create(:project, path: 'bar') }
set(:project) { create(:project, path: 'bar') }
set(:secondary_node) { create(:geo_node) }
let(:old_path) { 'foo' }
let(:old_path_with_namespace) { "#{project.namespace.full_path}/foo" }
......@@ -19,6 +20,12 @@ describe Geo::RepositoryRenamedEventStore do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(Geo::RepositoryRenamedEvent, :count)
end
it 'creates a renamed event' do
expect { subject.create }.to change(Geo::RepositoryRenamedEvent, :count).by(1)
end
......
require 'spec_helper'
describe Geo::RepositoryUpdatedEventStore do
let(:project) { create(:project, :repository) }
set(:project) { create(:project, :repository) }
set(:secondary_node) { create(:geo_node) }
let(:blankrev) { Gitlab::Git::BLANK_SHA }
let(:refs) { ['refs/heads/tést', 'refs/tags/tag'] }
......@@ -26,6 +27,14 @@ describe Geo::RepositoryUpdatedEventStore do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.create }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
it 'creates a push event' do
subject = described_class.new(project, refs: refs, changes: changes)
......
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