Commit 99cc4f17 authored by Markus Koller's avatar Markus Koller

Memoize repository storage shard in GroupWiki

This caused a bug where sometimes one shard was used for the repository
creation in `Wiki#create_wiki_repository`, but then a different one was
persisted to the DB in `GroupWiki#create_wiki_repository`.

So subsequent requests would use the wrong shard, and run into
`Gitlab::Git::Repository::NoRepository` errors.
parent 5c9d9178
...@@ -19,7 +19,9 @@ class GroupWiki < Wiki ...@@ -19,7 +19,9 @@ class GroupWiki < Wiki
override :repository_storage override :repository_storage
def repository_storage def repository_storage
container.group_wiki_repository&.shard_name || self.class.pick_repository_storage strong_memoize(:repository_storage) do
container.group_wiki_repository&.shard_name || self.class.pick_repository_storage
end
end end
override :hashed_storage? override :hashed_storage?
......
...@@ -70,6 +70,21 @@ RSpec.describe GroupWiki do ...@@ -70,6 +70,21 @@ RSpec.describe GroupWiki do
it 'returns the default shard' do it 'returns the default shard' do
expect(subject.repository_storage).to eq('default') expect(subject.repository_storage).to eq('default')
end end
context 'when multiple shards are configured' do
let(:shards) { (1..).each }
before do
# Force pick_repository_storage to always return a different value
allow(Gitlab::CurrentSettings).to receive(:pick_repository_storage) { "storage-#{shards.next}" }
end
it 'always returns the same shard when called repeatedly' do
shard = subject.repository_storage
expect(subject.repository_storage).to eq(shard)
end
end
end end
context 'when a tracking entry exists' do context 'when a tracking entry exists' do
......
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