Commit 236884cd authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add allow_disk_access blocks for EE code

parent 1689ecee
...@@ -11,12 +11,17 @@ module EE ...@@ -11,12 +11,17 @@ module EE
end end
# Transiently sets a configuration variable # Transiently sets a configuration variable
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/1241
def with_config(values = {}) def with_config(values = {})
values.each { |k, v| rugged.config[k] = v } ::Gitlab::GitalyClient::StorageSettings.allow_disk_access do
values.each { |k, v| rugged.config[k] = v }
end
yield yield
ensure ensure
values.keys.each { |key| rugged.config.delete(key) } ::Gitlab::GitalyClient::StorageSettings.allow_disk_access do
values.keys.each { |key| rugged.config.delete(key) }
end
end end
# Runs code after a repository has been synced. # Runs code after a repository has been synced.
...@@ -25,5 +30,10 @@ module EE ...@@ -25,5 +30,10 @@ module EE
expire_branch_cache if exists? expire_branch_cache if exists?
expire_content_cache expire_content_cache
end end
def upstream_branches
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/1243
::Gitlab::GitalyClient::StorageSettings.allow_disk_access { super }
end
end end
end end
...@@ -374,7 +374,8 @@ module Elasticsearch ...@@ -374,7 +374,8 @@ module Elasticsearch
def repository_for_indexing(repo_path = nil) def repository_for_indexing(repo_path = nil)
return @rugged_repo_indexer if defined? @rugged_repo_indexer return @rugged_repo_indexer if defined? @rugged_repo_indexer
@path_to_repo ||= repo_path || path_to_repo # Gitaly: how are we going to migrate ES code search? https://gitlab.com/gitlab-org/gitaly/issues/760
@path_to_repo ||= allow_disk_access { repo_path || path_to_repo }
set_repository_id set_repository_id
...@@ -384,6 +385,19 @@ module Elasticsearch ...@@ -384,6 +385,19 @@ module Elasticsearch
def client_for_indexing def client_for_indexing
@client_for_indexing ||= Elasticsearch::Client.new retry_on_failure: 5 @client_for_indexing ||= Elasticsearch::Client.new retry_on_failure: 5
end end
def allow_disk_access
# Sometimes this code runs as part of a bin/elastic_repo_indexer
# process. When that is the case Gitlab::GitalyClient::StorageSettings
# is not defined.
if defined?(Gitlab::GitalyClient::StorageSettings)
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
yield
end
else
yield
end
end
end end
module ClassMethods module ClassMethods
......
...@@ -56,7 +56,9 @@ module Gitlab ...@@ -56,7 +56,9 @@ module Gitlab
end end
def run_indexer!(from_sha, to_sha) def run_indexer!(from_sha, to_sha)
command = [path_to_indexer, project.id.to_s, repository.path_to_repo] command = ::Gitlab::GitalyClient::StorageSettings.allow_disk_access do
[path_to_indexer, project.id.to_s, repository.path_to_repo]
end
vars = @vars.merge('FROM_SHA' => from_sha, 'TO_SHA' => to_sha) vars = @vars.merge('FROM_SHA' => from_sha, 'TO_SHA' => to_sha)
output, status = Gitlab::Popen.popen(command, nil, vars) output, status = Gitlab::Popen.popen(command, nil, vars)
......
...@@ -420,7 +420,9 @@ describe Gitlab::Checks::ChangeAccess do ...@@ -420,7 +420,9 @@ describe Gitlab::Checks::ChangeAccess do
# #
# That means only the merge commit should be validated. # That means only the merge commit should be validated.
let(:newrev) do let(:newrev) do
rugged = project.repository.raw_repository.rugged rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
project.repository.raw_repository.rugged
end
base = oldrev base = oldrev
to_merge = '2d1096e3a0ecf1d2baf6dee036cc80775d4940ba' to_merge = '2d1096e3a0ecf1d2baf6dee036cc80775d4940ba'
......
...@@ -47,7 +47,7 @@ describe Gitlab::Elastic::Indexer do ...@@ -47,7 +47,7 @@ describe Gitlab::Elastic::Indexer do
[ [
File.join(Rails.root, 'bin/elastic_repo_indexer'), File.join(Rails.root, 'bin/elastic_repo_indexer'),
project.id.to_s, project.id.to_s,
project.repository.path_to_repo Gitlab::GitalyClient::StorageSettings.allow_disk_access { project.repository.path_to_repo }
], ],
nil, nil,
hash_including( hash_including(
......
...@@ -97,6 +97,8 @@ describe DropRepositoryStorageEventsForGeoEvents, :migration do ...@@ -97,6 +97,8 @@ describe DropRepositoryStorageEventsForGeoEvents, :migration do
end end
def legacy_disk_path(name) def legacy_disk_path(name)
Gitlab.config.repositories.storages[name].legacy_disk_path Gitlab::GitalyClient::StorageSettings.allow_disk_access do
Gitlab.config.repositories.storages[name].legacy_disk_path
end
end end
end end
...@@ -10,12 +10,19 @@ describe Geo::MoveRepositoryService, :geo do ...@@ -10,12 +10,19 @@ describe Geo::MoveRepositoryService, :geo do
subject(:service) { described_class.new(project, old_path, new_path) } subject(:service) { described_class.new(project, old_path, new_path) }
it 'renames the project repositories' do it 'renames the project repositories' do
old_disk_path = project.repository.path_to_repo old_disk_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
old_wiki_disk_path = project.wiki.repository.path_to_repo project.repository.path_to_repo
full_new_path = File.join( end
Gitlab.config.repositories.storages[project.repository_storage].legacy_disk_path, old_wiki_disk_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
new_path project.wiki.repository.path_to_repo
) end
full_new_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
File.join(
Gitlab.config.repositories.storages[project.repository_storage].legacy_disk_path,
new_path
)
end
expect(File.directory?(old_disk_path)).to be_truthy expect(File.directory?(old_disk_path)).to be_truthy
expect(File.directory?(old_wiki_disk_path)).to be_truthy expect(File.directory?(old_wiki_disk_path)).to be_truthy
......
...@@ -222,7 +222,9 @@ describe Projects::UpdateMirrorService do ...@@ -222,7 +222,9 @@ describe Projects::UpdateMirrorService do
end end
def fetch_mirror(repository) def fetch_mirror(repository)
rugged = repository.rugged rugged = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
repository.rugged
end
masterrev = repository.find_branch('master').dereferenced_target.id masterrev = repository.find_branch('master').dereferenced_target.id
parentrev = repository.commit(masterrev).parent_id parentrev = repository.commit(masterrev).parent_id
......
...@@ -17,7 +17,9 @@ describe Projects::UpdateRepositoryStorageService do ...@@ -17,7 +17,9 @@ describe Projects::UpdateRepositoryStorageService do
context 'when the move succeeds' do context 'when the move succeeds' do
it 'moves the repository to the new storage and unmarks the repository as read only' do it 'moves the repository to the new storage and unmarks the repository as read only' do
old_path = project.repository.path_to_repo old_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
project.repository.path_to_repo
end
expect_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror) expect_any_instance_of(Gitlab::Git::Repository).to receive(:fetch_repository_as_mirror)
.with(project.repository.raw).and_return(true) .with(project.repository.raw).and_return(true)
......
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