Skip project validation when switching storage layouts

This is a fix for the Hashed Storage migration and Rollback procedure
to ignore any project-level validation error that can happen in a
long-running instance.

There are many situations where defaults and acceptable values changed
but, because we didn't provide a migration to "valid" attributes, it
can happen that project will not be `valid? => true`.

Because the changes we are making are limited to setting a project as
read_only or changing the storage_level, it's safe to bypass validation.
This commit is contained in:
Gabriel Mazetto 2019-03-05 03:59:17 +01:00
parent 7b4130d0f7
commit b4f2050207
9 changed files with 33 additions and 4 deletions

View File

@ -24,7 +24,7 @@ module Projects
result = move_folder!(origin, target)
if result
project.save!
project.save!(validate: false)
yield if block_given?
else

View File

@ -27,7 +27,7 @@ module Projects
end
project.repository_read_only = false
project.save!
project.save!(validate: false)
if result && block_given?
yield

View File

@ -19,7 +19,7 @@ module Projects
result = move_folder!(origin, target)
if result
project.save!
project.save!(validate: false)
yield if block_given?
else

View File

@ -27,7 +27,7 @@ module Projects
end
project.repository_read_only = false
project.save!
project.save!(validate: false)
if result && block_given?
yield

View File

@ -0,0 +1,5 @@
---
title: Skip Project validation during Hashed Storage migration or rollback
merge_request: 25753
author:
type: fixed

View File

@ -76,6 +76,12 @@ describe Projects::HashedStorage::MigrateAttachmentsService do
expect { service.execute }.to raise_error(Projects::HashedStorage::AttachmentCannotMoveError)
end
end
it 'works even when project validation fails' do
allow(project).to receive(:valid?) { false }
expect { service.execute }.to change { project.hashed_storage?(:attachments) }.to(true)
end
end
context '#old_disk_path' do

View File

@ -102,6 +102,12 @@ describe Projects::HashedStorage::MigrateRepositoryService do
end
end
it 'works even when project validation fails' do
allow(project).to receive(:valid?) { false }
expect { service.execute }.to change { project.hashed_storage?(:repository) }.to(true)
end
def expect_move_repository(from_name, to_name)
expect(gitlab_shell).to receive(:mv_repository).with(project.repository_storage, from_name, to_name).and_call_original
end

View File

@ -78,6 +78,12 @@ describe Projects::HashedStorage::RollbackAttachmentsService do
expect { service.execute }.to raise_error(Projects::HashedStorage::AttachmentCannotMoveError)
end
end
it 'works even when project validation fails' do
allow(project).to receive(:valid?) { false }
expect { service.execute }.to change { project.hashed_storage?(:attachments) }.to(false)
end
end
context '#old_disk_path' do

View File

@ -104,6 +104,12 @@ describe Projects::HashedStorage::RollbackRepositoryService, :clean_gitlab_redis
end
end
it 'works even when project validation fails' do
allow(project).to receive(:valid?) { false }
expect { service.execute }.to change { project.legacy_storage? }.to(true)
end
def expect_move_repository(from_name, to_name)
expect(gitlab_shell).to receive(:mv_repository).with(project.repository_storage, from_name, to_name).and_call_original
end