diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/workers/git_garbage_collect_worker.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/workers/git_garbage_collect_worker.rb')
-rw-r--r-- | app/workers/git_garbage_collect_worker.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/workers/git_garbage_collect_worker.rb b/app/workers/git_garbage_collect_worker.rb index f2222c7be5e..6e4feea1b26 100644 --- a/app/workers/git_garbage_collect_worker.rb +++ b/app/workers/git_garbage_collect_worker.rb @@ -11,6 +11,7 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker LEASE_TIMEOUT = 86400 def perform(project_id, task = :gc, lease_key = nil, lease_uuid = nil) + lease_key ||= "git_gc:#{task}:#{project_id}" project = Project.find(project_id) active_uuid = get_lease_uuid(lease_key) @@ -26,14 +27,20 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker task = task.to_sym - ::Projects::GitDeduplicationService.new(project).execute if task == :gc + if task == :gc + ::Projects::GitDeduplicationService.new(project).execute + cleanup_orphan_lfs_file_references(project) + end gitaly_call(task, project.repository.raw_repository) # Refresh the branch cache in case garbage collection caused a ref lookup to fail flush_ref_caches(project) if task == :gc - project.repository.expire_statistics_caches if task != :pack_refs + if task != :pack_refs + project.repository.expire_statistics_caches + Projects::UpdateStatisticsService.new(project, nil, statistics: [:repository_size, :lfs_objects_size]).execute + end # In case pack files are deleted, release libgit2 cache and open file # descriptors ASAP instead of waiting for Ruby garbage collection @@ -86,6 +93,13 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker raise Gitlab::Git::CommandError.new(e) end + def cleanup_orphan_lfs_file_references(project) + return unless Feature.enabled?(:cleanup_lfs_during_gc, project) + return if Gitlab::Database.read_only? # GitGarbageCollectWorker may be run on a Geo secondary + + ::Gitlab::Cleanup::OrphanLfsFileReferences.new(project, dry_run: false, logger: logger).run! + end + def flush_ref_caches(project) project.repository.after_create_branch project.repository.branch_names |