Commit a440c2be authored by Gabriel Mazetto's avatar Gabriel Mazetto

Add FeatureFlag to disable hashed storage migration when renaming

We usually want a feature flag to be disabled by default and
hide the feature until it's enabled.

This is an unconventional use: when the flag is enabled, it will
"DISABLE" the behavior.
parent fe77eb4d
...@@ -2072,13 +2072,19 @@ class Project < ActiveRecord::Base ...@@ -2072,13 +2072,19 @@ class Project < ActiveRecord::Base
private private
def rename_or_migrate_repository! def rename_or_migrate_repository!
if Gitlab::CurrentSettings.hashed_storage_enabled? && storage_version != LATEST_STORAGE_VERSION if Gitlab::CurrentSettings.hashed_storage_enabled? &&
storage_upgradable? &&
Feature.disabled?(:disable_hashed_storage_upgrade) # kill switch in case we need to disable upgrade behavior
::Projects::HashedStorageMigrationService.new(self, full_path_was).execute ::Projects::HashedStorageMigrationService.new(self, full_path_was).execute
else else
storage.rename_repo storage.rename_repo
end end
end end
def storage_upgradable?
storage_version != LATEST_STORAGE_VERSION
end
def after_rename_repository(full_path_before, path_before) def after_rename_repository(full_path_before, path_before)
execute_rename_repository_hooks!(full_path_before) execute_rename_repository_hooks!(full_path_before)
......
...@@ -249,7 +249,17 @@ describe Projects::UpdateService do ...@@ -249,7 +249,17 @@ describe Projects::UpdateService do
expect(project.errors.messages[:base]).to include('There is already a repository with that name on disk') expect(project.errors.messages[:base]).to include('There is already a repository with that name on disk')
end end
context 'when hashed storage enabled' do it 'renames the project without upgrading it' do
result = update_project(project, admin, path: 'new-path')
expect(result).not_to include(status: :error)
expect(project).to be_valid
expect(project.errors).to be_empty
expect(project.disk_path).to include('new-path')
expect(project.reload.hashed_storage?(:repository)).to be_falsey
end
context 'when hashed storage is enabled' do
before do before do
stub_application_setting(hashed_storage_enabled: true) stub_application_setting(hashed_storage_enabled: true)
end end
...@@ -262,6 +272,22 @@ describe Projects::UpdateService do ...@@ -262,6 +272,22 @@ describe Projects::UpdateService do
expect(project.errors).to be_empty expect(project.errors).to be_empty
expect(project.reload.hashed_storage?(:repository)).to be_truthy expect(project.reload.hashed_storage?(:repository)).to be_truthy
end end
context 'when disable_hashed_storage_upgrade feature flag is enabled' do
before do
expect(Feature).to receive(:enabled?).with(:disable_hashed_storage_upgrade) { true }
end
it 'renames the project without upgrading it' do
result = update_project(project, admin, path: 'new-path')
expect(result).not_to include(status: :error)
expect(project).to be_valid
expect(project.errors).to be_empty
expect(project.disk_path).to include('new-path')
expect(project.reload.hashed_storage?(:repository)).to be_falsey
end
end
end 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