BigW Consortium Gitlab

Commit 6a4534b6 by Gabriel Mazetto

Code Style changes and `hashed_storage?` now receives optional feature

parent 95fa6270
......@@ -26,10 +26,15 @@ class Project < ActiveRecord::Base
NUMBER_OF_PERMITTED_BOARDS = 1
UNKNOWN_IMPORT_URL = 'http://unknown.git'.freeze
# Hashed Storage versions handle rolling out new storage to project and dependents models
# Hashed Storage versions handle rolling out new storage to project and dependents models:
# nil: legacy
# 1: repository
# 2: attachments
LATEST_STORAGE_VERSION = 2
HASHED_STORAGE_FEATURES = {
repository: 1,
attachments: 2
}.freeze
cache_markdown_field :description, pipeline: :description
......@@ -1387,7 +1392,7 @@ class Project < ActiveRecord::Base
if storage.rename_repo
Gitlab::AppLogger.info "Project was renamed: #{full_path_was} -> #{new_full_path}"
rename_repo_notify!
storage.after_rename_repo
after_rename_repo
else
Rails.logger.error "Repository could not be renamed: #{full_path_was} -> #{new_full_path}"
......@@ -1397,6 +1402,19 @@ class Project < ActiveRecord::Base
end
end
def after_rename_repo
path_before_change = previous_changes['path'].first
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless hashed_storage?(:attachments)
Gitlab::UploadsTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
end
Gitlab::PagesTransfer.new.rename_project(path_before_change, self.path, namespace.full_path)
end
def rename_repo_notify!
send_move_instructions(full_path_was)
expires_full_path_cache
......@@ -1596,8 +1614,10 @@ class Project < ActiveRecord::Base
[nil, 0].include?(self.storage_version)
end
def hashed_storage?
self.storage_version && self.storage_version >= 1
def hashed_storage?(feature=:repository)
raise ArgumentError, "Invalid feature" unless HASHED_STORAGE_FEATURES.include?(feature)
self.storage_version && self.storage_version >= HASHED_STORAGE_FEATURES[feature]
end
def renamed?
......
......@@ -32,19 +32,6 @@ module Storage
true
end
def after_rename_repo
path_before_change = project.previous_changes['path'].first
# We need to check if project had been rolled out to move resource to hashed storage or not and decide
# if we need execute any take action or no-op.
unless project.storage_version >= 2
Gitlab::UploadsTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
end
Gitlab::PagesTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
end
private
# Generates the hash for the project path and name on disk
......
......@@ -47,12 +47,5 @@ module Storage
false
end
def after_rename_repo
path_before_change = project.previous_changes['path'].first
Gitlab::UploadsTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
Gitlab::PagesTransfer.new.rename_project(path_before_change, project.path, project.namespace.full_path)
end
end
end
......@@ -2630,8 +2630,22 @@ describe Project do
end
describe '#hashed_storage?' do
it 'returns true' do
expect(project.hashed_storage?).to be_truthy
context 'without specifying feature' do
it 'returns true' do
expect(project.hashed_storage?).to be_truthy
end
end
context 'specifying feature' do
it 'returns true if rolled out' do
expect(project.hashed_storage?(:attachments)).to be_truthy
end
it 'returns false when not rolled out yet' do
project.storage_version = 1
expect(project.hashed_storage?(:attachments)).to be_falsey
end
end
end
......
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