Commit 900b0719 authored by Catalin Irimie's avatar Catalin Irimie

Prevent group wiki writes on read-only DBs

With Geo, not having this prevents all group wikis from working,
due to the DB load balancer always being enabled, this gets marked
as a primary, and we attempt to stick to the primary, writeable DB,
which does not exist in the Geo case.

Changelog: fixed
EE: true
parent 314a36ab
......@@ -12,6 +12,8 @@ class GroupWiki < Wiki
end
def track_wiki_repository(shard)
return unless ::Gitlab::Database.read_write?
storage_record = container.group_wiki_repository || container.build_group_wiki_repository
storage_record.update!(shard_name: shard, disk_path: storage.disk_path)
end
......
......@@ -47,6 +47,16 @@ RSpec.describe GroupWiki do
shard_name: shard
)
end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not attempt to create a new entry' do
expect { subject.track_wiki_repository(shard) }.not_to change(wiki_container, :group_wiki_repository)
end
end
end
context 'when a tracking entry exists' do
......@@ -64,6 +74,23 @@ RSpec.describe GroupWiki do
shard_name: shard
)
end
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
it 'does not update the storage location' do
allow(subject.storage).to receive(:disk_path).and_return('fancy/new/path')
subject.track_wiki_repository(shard)
expect(wiki_container.group_wiki_repository).not_to have_attributes(
disk_path: 'fancy/new/path',
shard_name: shard
)
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