Commit aed980e7 authored by Nick Thomas's avatar Nick Thomas

Make Repository track shard

This makes a transitive dependency direct, and is a first step towards
removing `::Repository#{project,container}`
parent becfc8bc
...@@ -780,7 +780,7 @@ class Project < ApplicationRecord ...@@ -780,7 +780,7 @@ class Project < ApplicationRecord
end end
def repository def repository
@repository ||= Repository.new(full_path, self, disk_path: disk_path) @repository ||= Repository.new(full_path, self, shard: repository_storage, disk_path: disk_path)
end end
def cleanup def cleanup
...@@ -1411,8 +1411,8 @@ class Project < ApplicationRecord ...@@ -1411,8 +1411,8 @@ class Project < ApplicationRecord
# Expires various caches before a project is renamed. # Expires various caches before a project is renamed.
def expire_caches_before_rename(old_path) def expire_caches_before_rename(old_path)
repo = Repository.new(old_path, self) repo = Repository.new(old_path, self, shard: repository_storage)
wiki = Repository.new("#{old_path}.wiki", self) wiki = Repository.new("#{old_path}.wiki", self, shard: repository_storage, repo_type: Gitlab::GlRepository::WIKI)
if repo.exists? if repo.exists?
repo.before_delete repo.before_delete
......
...@@ -170,7 +170,7 @@ class ProjectWiki ...@@ -170,7 +170,7 @@ class ProjectWiki
end end
def repository def repository
@repository ||= Repository.new(full_path, @project, disk_path: disk_path, repo_type: Gitlab::GlRepository::WIKI) @repository ||= Repository.new(full_path, @project, shard: repository_storage, disk_path: disk_path, repo_type: Gitlab::GlRepository::WIKI)
end end
def default_branch def default_branch
......
...@@ -22,7 +22,7 @@ class Repository ...@@ -22,7 +22,7 @@ class Repository
include Gitlab::RepositoryCacheAdapter include Gitlab::RepositoryCacheAdapter
attr_accessor :full_path, :disk_path, :container, :repo_type attr_accessor :full_path, :shard, :disk_path, :container, :repo_type
delegate :ref_name_for_sha, to: :raw_repository delegate :ref_name_for_sha, to: :raw_repository
delegate :bundle_to_disk, to: :raw_repository delegate :bundle_to_disk, to: :raw_repository
...@@ -65,8 +65,9 @@ class Repository ...@@ -65,8 +65,9 @@ class Repository
xcode_config: :xcode_project? xcode_config: :xcode_project?
}.freeze }.freeze
def initialize(full_path, container, disk_path: nil, repo_type: Gitlab::GlRepository::PROJECT) def initialize(full_path, container, shard:, disk_path: nil, repo_type: Gitlab::GlRepository::PROJECT)
@full_path = full_path @full_path = full_path
@shard = shard
@disk_path = disk_path || full_path @disk_path = disk_path || full_path
@container = container @container = container
@commit_cache = {} @commit_cache = {}
...@@ -95,7 +96,7 @@ class Repository ...@@ -95,7 +96,7 @@ class Repository
def path_to_repo def path_to_repo
@path_to_repo ||= @path_to_repo ||=
begin begin
storage = Gitlab.config.repositories.storages[container.repository_storage] storage = Gitlab.config.repositories.storages[shard]
File.expand_path( File.expand_path(
File.join(storage.legacy_disk_path, disk_path + '.git') File.join(storage.legacy_disk_path, disk_path + '.git')
...@@ -1180,7 +1181,7 @@ class Repository ...@@ -1180,7 +1181,7 @@ class Repository
end end
def initialize_raw_repository def initialize_raw_repository
Gitlab::Git::Repository.new(container.repository_storage, Gitlab::Git::Repository.new(shard,
disk_path + '.git', disk_path + '.git',
repo_type.identifier_for_container(container), repo_type.identifier_for_container(container),
container.full_path) container.full_path)
......
...@@ -261,7 +261,7 @@ class Snippet < ApplicationRecord ...@@ -261,7 +261,7 @@ class Snippet < ApplicationRecord
end end
def repository def repository
@repository ||= Repository.new(full_path, self, disk_path: disk_path, repo_type: Gitlab::GlRepository::SNIPPET) @repository ||= Repository.new(full_path, self, shard: repository_storage, disk_path: disk_path, repo_type: Gitlab::GlRepository::SNIPPET)
end end
def storage def storage
......
...@@ -16,7 +16,7 @@ module DesignManagement ...@@ -16,7 +16,7 @@ module DesignManagement
full_path = project.full_path + EE::Gitlab::GlRepository::DESIGN.path_suffix full_path = project.full_path + EE::Gitlab::GlRepository::DESIGN.path_suffix
disk_path = project.disk_path + EE::Gitlab::GlRepository::DESIGN.path_suffix disk_path = project.disk_path + EE::Gitlab::GlRepository::DESIGN.path_suffix
super(full_path, project, disk_path: disk_path, repo_type: EE::Gitlab::GlRepository::DESIGN) super(full_path, project, shard: project.repository_storage, disk_path: disk_path, repo_type: EE::Gitlab::GlRepository::DESIGN)
end end
# Override of a method called on Repository instances but sent via # Override of a method called on Repository instances but sent via
......
...@@ -674,7 +674,7 @@ module EE ...@@ -674,7 +674,7 @@ module EE
def expire_caches_before_rename(old_path) def expire_caches_before_rename(old_path)
super super
design = ::Repository.new("#{old_path}#{EE::Gitlab::GlRepository::DESIGN.path_suffix}", self) design = ::Repository.new("#{old_path}#{::EE::Gitlab::GlRepository::DESIGN.path_suffix}", self, shard: repository_storage, repo_type: ::EE::Gitlab::GlRepository::DESIGN)
if design.exists? if design.exists?
design.before_delete design.before_delete
......
...@@ -13,7 +13,7 @@ class Geo::DeletedProject ...@@ -13,7 +13,7 @@ class Geo::DeletedProject
alias_method :full_path, :disk_path alias_method :full_path, :disk_path
def repository def repository
@repository ||= Repository.new(disk_path, self) @repository ||= Repository.new(disk_path, self, shard: repository_storage)
end end
def repository_storage def repository_storage
......
...@@ -30,7 +30,7 @@ module Geo ...@@ -30,7 +30,7 @@ module Geo
end end
def repository def repository
@repository ||= Repository.new(full_path, self, disk_path: disk_path) @repository ||= Repository.new(full_path, self, shard: repository_storage, disk_path: disk_path)
end end
def storage def storage
......
...@@ -204,7 +204,7 @@ module Geo ...@@ -204,7 +204,7 @@ module Geo
end end
def temp_repo def temp_repo
@temp_repo ||= ::Repository.new(repository.full_path, repository.project, disk_path: disk_path_temp, repo_type: repository.repo_type) @temp_repo ||= ::Repository.new(repository.full_path, repository.container, shard: repository.shard, disk_path: disk_path_temp, repo_type: repository.repo_type)
end end
def clean_up_temporary_repository def clean_up_temporary_repository
......
...@@ -2592,15 +2592,15 @@ describe Project do ...@@ -2592,15 +2592,15 @@ describe Project do
it 'expires the caches of the design repository' do it 'expires the caches of the design repository' do
allow(Repository).to receive(:new) allow(Repository).to receive(:new)
.with('foo', project) .with('foo', project, shard: project.repository_storage)
.and_return(repo) .and_return(repo)
allow(Repository).to receive(:new) allow(Repository).to receive(:new)
.with('foo.wiki', project) .with('foo.wiki', project, shard: project.repository_storage, repo_type: Gitlab::GlRepository::WIKI)
.and_return(wiki) .and_return(wiki)
allow(Repository).to receive(:new) allow(Repository).to receive(:new)
.with('foo.design', project) .with('foo.design', project, shard: project.repository_storage, repo_type: ::EE::Gitlab::GlRepository::DESIGN)
.and_return(design) .and_return(design)
expect(design).to receive(:before_delete) expect(design).to receive(:before_delete)
......
...@@ -238,6 +238,7 @@ describe Geo::RepositoryVerificationPrimaryService do ...@@ -238,6 +238,7 @@ describe Geo::RepositoryVerificationPrimaryService do
allow(Repository).to receive(:new).with( allow(Repository).to receive(:new).with(
project.full_path, project.full_path,
project, project,
shard: project.repository_storage,
disk_path: project.disk_path disk_path: project.disk_path
).and_return(repository) ).and_return(repository)
end end
...@@ -246,6 +247,7 @@ describe Geo::RepositoryVerificationPrimaryService do ...@@ -246,6 +247,7 @@ describe Geo::RepositoryVerificationPrimaryService do
allow(Repository).to receive(:new).with( allow(Repository).to receive(:new).with(
project.wiki.full_path, project.wiki.full_path,
project, project,
shard: project.repository_storage,
disk_path: project.wiki.disk_path, disk_path: project.wiki.disk_path,
repo_type: Gitlab::GlRepository::WIKI repo_type: Gitlab::GlRepository::WIKI
).and_return(repository) ).and_return(repository)
......
...@@ -1791,21 +1791,19 @@ describe Project do ...@@ -1791,21 +1791,19 @@ describe Project do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:repo) { double(:repo, exists?: true) } let(:repo) { double(:repo, exists?: true) }
let(:wiki) { double(:wiki, exists?: true) } let(:wiki) { double(:wiki, exists?: true) }
let(:design) { double(:wiki, exists?: false) }
it 'expires the caches of the repository and wiki' do it 'expires the caches of the repository and wiki' do
# In EE, there are design repositories as well
allow(Repository).to receive(:new).and_call_original
allow(Repository).to receive(:new) allow(Repository).to receive(:new)
.with('foo', project) .with('foo', project, shard: project.repository_storage)
.and_return(repo) .and_return(repo)
allow(Repository).to receive(:new) allow(Repository).to receive(:new)
.with('foo.wiki', project) .with('foo.wiki', project, shard: project.repository_storage, repo_type: Gitlab::GlRepository::WIKI)
.and_return(wiki) .and_return(wiki)
allow(Repository).to receive(:new)
.with('foo.design', project)
.and_return(design)
expect(repo).to receive(:before_delete) expect(repo).to receive(:before_delete)
expect(wiki).to receive(:before_delete) expect(wiki).to receive(:before_delete)
......
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