Skip to content

Commit c5a74a9

Browse files
author
Nick Thomas
committed
Merge branch 'osw-enforces-project-removal-with-past-failed-attempts' into 'master'
Cleanup stale +deleted repo paths on project removal (adjusts project removal bug) Closes #46146 See merge request gitlab-org/gitlab-ce!24269
2 parents 17819c1 + 4fd848f commit c5a74a9

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

app/services/projects/destroy_service.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ class DestroyService < BaseService
77
DestroyError = Class.new(StandardError)
88

99
DELETED_FLAG = '+deleted'.freeze
10+
REPO_REMOVAL_DELAY = 5.minutes.to_i
1011

1112
def async_execute
1213
project.update_attribute(:pending_delete, true)
14+
15+
# Ensure no repository +deleted paths are kept,
16+
# regardless of any issue with the ProjectDestroyWorker
17+
# job process.
18+
schedule_stale_repos_removal
19+
1320
job_id = ProjectDestroyWorker.perform_async(project.id, current_user.id, params)
1421
Rails.logger.info("User #{current_user.id} scheduled destruction of project #{project.full_path} with job ID #{job_id}")
1522
end
@@ -92,14 +99,23 @@ def remove_repository(path)
9299
log_info(%Q{Repository "#{path}" moved to "#{new_path}" for project "#{project.full_path}"})
93100

94101
project.run_after_commit do
95-
# self is now project
96-
GitlabShellWorker.perform_in(5.minutes, :remove_repository, self.repository_storage, new_path)
102+
GitlabShellWorker.perform_in(REPO_REMOVAL_DELAY, :remove_repository, self.repository_storage, new_path)
97103
end
98104
else
99105
false
100106
end
101107
end
102108

109+
def schedule_stale_repos_removal
110+
repo_paths = [removal_path(repo_path), removal_path(wiki_path)]
111+
112+
# Ideally it should wait until the regular removal phase finishes,
113+
# so let's delay it a bit further.
114+
repo_paths.each do |path|
115+
GitlabShellWorker.perform_in(REPO_REMOVAL_DELAY * 2, :remove_repository, project.repository_storage, path)
116+
end
117+
end
118+
103119
def rollback_repository(old_path, new_path)
104120
# There is a possibility project does not have repository or wiki
105121
return true unless repo_exists?(old_path)
@@ -113,13 +129,11 @@ def repo_exists?(path)
113129
end
114130
# rubocop: enable CodeReuse/ActiveRecord
115131

116-
# rubocop: disable CodeReuse/ActiveRecord
117132
def mv_repository(from_path, to_path)
118-
return true unless gitlab_shell.exists?(project.repository_storage, from_path + '.git')
133+
return true unless repo_exists?(from_path)
119134

120135
gitlab_shell.mv_repository(project.repository_storage, from_path, to_path)
121136
end
122-
# rubocop: enable CodeReuse/ActiveRecord
123137

124138
def attempt_rollback(project, message)
125139
return unless project
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Cleanup stale +deleted repo paths on project removal (adjusts project removal bug)
3+
merge_request: 24269
4+
author:
5+
type: fixed

spec/services/projects/destroy_service_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,40 @@
281281
end
282282
end
283283

284+
context 'repository +deleted path removal' do
285+
def removal_path(path)
286+
"#{path}+#{project.id}#{described_class::DELETED_FLAG}"
287+
end
288+
289+
context 'regular phase' do
290+
it 'schedules +deleted removal of existing repos' do
291+
service = described_class.new(project, user, {})
292+
allow(service).to receive(:schedule_stale_repos_removal)
293+
294+
expect(GitlabShellWorker).to receive(:perform_in)
295+
.with(5.minutes, :remove_repository, project.repository_storage, removal_path(project.disk_path))
296+
297+
service.execute
298+
end
299+
end
300+
301+
context 'stale cleanup' do
302+
let!(:async) { true }
303+
304+
it 'schedules +deleted wiki and repo removal' do
305+
allow(ProjectDestroyWorker).to receive(:perform_async)
306+
307+
expect(GitlabShellWorker).to receive(:perform_in)
308+
.with(10.minutes, :remove_repository, project.repository_storage, removal_path(project.disk_path))
309+
310+
expect(GitlabShellWorker).to receive(:perform_in)
311+
.with(10.minutes, :remove_repository, project.repository_storage, removal_path(project.wiki.disk_path))
312+
313+
destroy_project(project, user, {})
314+
end
315+
end
316+
end
317+
284318
context '#attempt_restore_repositories' do
285319
let(:path) { project.disk_path + '.git' }
286320

0 commit comments

Comments
 (0)