Add group restrictions when performing a full scan on Geo::LogCursor

parent 6a8fe020
...@@ -38,7 +38,17 @@ module Gitlab ...@@ -38,7 +38,17 @@ module Gitlab
# Projects without corresponding ProjectRegistry in the DR database # Projects without corresponding ProjectRegistry in the DR database
# See: https://robots.thoughtbot.com/postgres-foreign-data-wrapper (requires PG 9.6) # See: https://robots.thoughtbot.com/postgres-foreign-data-wrapper (requires PG 9.6)
$stdout.print 'Searching for non replicated projects...' $stdout.print 'Searching for non replicated projects...'
Project.select(:id).find_in_batches(batch_size: BATCH_SIZE) do |batch|
restricted_project_ids = Gitlab::Geo.current_node.project_ids
relation =
if restricted_project_ids
Project.where(id: restricted_project_ids)
else
Project.all
end
relation.select(:id).find_in_batches(batch_size: BATCH_SIZE) do |batch|
$stdout.print '.' $stdout.print '.'
project_ids = batch.map(&:id) project_ids = batch.map(&:id)
......
...@@ -83,8 +83,9 @@ describe Gitlab::Geo::LogCursor::Daemon do ...@@ -83,8 +83,9 @@ describe Gitlab::Geo::LogCursor::Daemon do
context 'when node have group restrictions' do context 'when node have group restrictions' do
let(:geo_node) { create(:geo_node, :current) } let(:geo_node) { create(:geo_node, :current) }
let(:group) { create(:group) } let(:group_1) { create(:group) }
let(:project) { create(:empty_project, group: group) } let(:group_2) { create(:group) }
let(:project) { create(:empty_project, group: group_1) }
let(:repository_updated_event) { create(:geo_repository_updated_event, project: project) } let(:repository_updated_event) { create(:geo_repository_updated_event, project: project) }
let(:event_log) { create(:geo_event_log, repository_updated_event: repository_updated_event) } let(:event_log) { create(:geo_event_log, repository_updated_event: repository_updated_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) } let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
...@@ -94,16 +95,32 @@ describe Gitlab::Geo::LogCursor::Daemon do ...@@ -94,16 +95,32 @@ describe Gitlab::Geo::LogCursor::Daemon do
end end
it 'replays events for projects that belong to selected groups to replicate' do it 'replays events for projects that belong to selected groups to replicate' do
geo_node.update_attribute(:groups, [group]) geo_node.update_attribute(:groups, [group_1])
expect { subject.run! }.to change(Geo::ProjectRegistry, :count).by(1) expect { subject.run! }.to change(Geo::ProjectRegistry, :count).by(1)
end end
it 'does not replay events for projects that do not belong to selected groups to replicate' do it 'does not replay events for projects that do not belong to selected groups to replicate' do
geo_node.update_attribute(:groups, [create(:group)]) geo_node.update_attribute(:groups, [group_2])
expect { subject.run! }.not_to change(Geo::ProjectRegistry, :count) expect { subject.run! }.not_to change(Geo::ProjectRegistry, :count)
end end
context 'when performing a full scan' do
subject { described_class.new(full_scan: true) }
it 'creates registries for missing projects that belong to selected groups' do
geo_node.update_attribute(:groups, [group_1])
expect { subject.run! }.to change(Geo::ProjectRegistry, :count).by(1)
end
it 'does not create registries for missing projects that do not belong to selected groups' do
geo_node.update_attribute(:groups, [group_2])
expect { subject.run! }.not_to change(Geo::ProjectRegistry, :count)
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