Commit 5a0d653f authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '263416-fix-group-wiki-repository-storage' into 'master'

Memoize repository storage shard in GroupWiki

See merge request gitlab-org/gitlab!44727
parents de02ea4e 16dc492b
...@@ -9,7 +9,7 @@ class GroupWiki < Wiki ...@@ -9,7 +9,7 @@ class GroupWiki < Wiki
super super
storage_record = container.group_wiki_repository || container.build_group_wiki_repository storage_record = container.group_wiki_repository || container.build_group_wiki_repository
storage_record.update!(shard_name: repository_storage, disk_path: storage.disk_path) storage_record.update!(shard_name: repository.shard, disk_path: storage.disk_path)
end end
override :storage override :storage
...@@ -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?
......
...@@ -13,7 +13,10 @@ RSpec.describe GroupWiki do ...@@ -13,7 +13,10 @@ RSpec.describe GroupWiki do
describe '#create_wiki_repository' do describe '#create_wiki_repository' do
before do before do
# Don't actually create the repository, because we're using storage shards that don't exist. # Use a custom storage shard value, to make sure we're not falling back to the default.
allow(subject).to receive(:repository_storage).and_return('foo')
# Don't actually create the repository, because the storage shard doesn't exist.
allow(subject.repository).to receive(:create_if_not_exists) allow(subject.repository).to receive(:create_if_not_exists)
allow(subject).to receive(:repository_exists?).and_return(true) allow(subject).to receive(:repository_exists?).and_return(true)
end end
...@@ -27,8 +30,6 @@ RSpec.describe GroupWiki do ...@@ -27,8 +30,6 @@ RSpec.describe GroupWiki do
end end
it 'tracks the storage location' do it 'tracks the storage location' do
expect(subject).to receive(:repository_storage).and_return('foo')
subject.create_wiki_repository subject.create_wiki_repository
expect(wiki_container.group_wiki_repository).to have_attributes( expect(wiki_container.group_wiki_repository).to have_attributes(
...@@ -44,7 +45,6 @@ RSpec.describe GroupWiki do ...@@ -44,7 +45,6 @@ RSpec.describe GroupWiki do
end end
it 'updates the storage location' do it 'updates the storage location' do
expect(subject).to receive(:repository_storage).and_return('foo')
expect(subject.storage).to receive(:disk_path).and_return('fancy/new/path') expect(subject.storage).to receive(:disk_path).and_return('fancy/new/path')
subject.create_wiki_repository subject.create_wiki_repository
...@@ -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