Commit f94f354d authored by Michael Kozono's avatar Michael Kozono

Merge branch '201866-repository-tracks-shard' into 'master'

Make Repository track shard

See merge request gitlab-org/gitlab!25911
parents abe7a9ba aed980e7
......@@ -780,7 +780,7 @@ class Project < ApplicationRecord
end
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
def cleanup
......@@ -1411,8 +1411,8 @@ class Project < ApplicationRecord
# Expires various caches before a project is renamed.
def expire_caches_before_rename(old_path)
repo = Repository.new(old_path, self)
wiki = Repository.new("#{old_path}.wiki", self)
repo = Repository.new(old_path, self, shard: repository_storage)
wiki = Repository.new("#{old_path}.wiki", self, shard: repository_storage, repo_type: Gitlab::GlRepository::WIKI)
if repo.exists?
repo.before_delete
......
......@@ -170,7 +170,7 @@ class ProjectWiki
end
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
def default_branch
......
......@@ -22,7 +22,7 @@ class Repository
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 :bundle_to_disk, to: :raw_repository
......@@ -65,8 +65,9 @@ class Repository
xcode_config: :xcode_project?
}.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
@shard = shard
@disk_path = disk_path || full_path
@container = container
@commit_cache = {}
......@@ -95,7 +96,7 @@ class Repository
def path_to_repo
@path_to_repo ||=
begin
storage = Gitlab.config.repositories.storages[container.repository_storage]
storage = Gitlab.config.repositories.storages[shard]
File.expand_path(
File.join(storage.legacy_disk_path, disk_path + '.git')
......@@ -1181,7 +1182,7 @@ class Repository
end
def initialize_raw_repository
Gitlab::Git::Repository.new(container.repository_storage,
Gitlab::Git::Repository.new(shard,
disk_path + '.git',
repo_type.identifier_for_container(container),
container.full_path)
......
......@@ -261,7 +261,7 @@ class Snippet < ApplicationRecord
end
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
def storage
......
......@@ -16,7 +16,7 @@ module DesignManagement
full_path = project.full_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
# Override of a method called on Repository instances but sent via
......
......@@ -674,7 +674,7 @@ module EE
def expire_caches_before_rename(old_path)
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?
design.before_delete
......
......@@ -13,7 +13,7 @@ class Geo::DeletedProject
alias_method :full_path, :disk_path
def repository
@repository ||= Repository.new(disk_path, self)
@repository ||= Repository.new(disk_path, self, shard: repository_storage)
end
def repository_storage
......
......@@ -30,7 +30,7 @@ module Geo
end
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
def storage
......
......@@ -204,7 +204,7 @@ module Geo
end
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
def clean_up_temporary_repository
......
......@@ -2592,15 +2592,15 @@ describe Project do
it 'expires the caches of the design repository' do
allow(Repository).to receive(:new)
.with('foo', project)
.with('foo', project, shard: project.repository_storage)
.and_return(repo)
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)
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)
expect(design).to receive(:before_delete)
......
......@@ -238,6 +238,7 @@ describe Geo::RepositoryVerificationPrimaryService do
allow(Repository).to receive(:new).with(
project.full_path,
project,
shard: project.repository_storage,
disk_path: project.disk_path
).and_return(repository)
end
......@@ -246,6 +247,7 @@ describe Geo::RepositoryVerificationPrimaryService do
allow(Repository).to receive(:new).with(
project.wiki.full_path,
project,
shard: project.repository_storage,
disk_path: project.wiki.disk_path,
repo_type: Gitlab::GlRepository::WIKI
).and_return(repository)
......
......@@ -1791,21 +1791,19 @@ describe Project do
let(:project) { create(:project, :repository) }
let(:repo) { double(:repo, exists?: true) }
let(:wiki) { double(:wiki, exists?: true) }
let(:design) { double(:wiki, exists?: false) }
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)
.with('foo', project)
.with('foo', project, shard: project.repository_storage)
.and_return(repo)
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)
allow(Repository).to receive(:new)
.with('foo.design', project)
.and_return(design)
expect(repo).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