Commit 893b2585 authored by Imre Farkas's avatar Imre Farkas

Merge branch...

Merge branch '249910-does-not-update-repository-statistics-when-running-on-a-read-only-instance' into 'master'

Does not update repository statistics when running housekeeping and repository cleanup on a read-only instance

Closes #249910

See merge request gitlab-org/gitlab!42409
parents 0791f443 c6e92ab3
...@@ -37,10 +37,7 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -37,10 +37,7 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker
# Refresh the branch cache in case garbage collection caused a ref lookup to fail # Refresh the branch cache in case garbage collection caused a ref lookup to fail
flush_ref_caches(project) if task == :gc flush_ref_caches(project) if task == :gc
if task != :pack_refs update_repository_statistics(project) 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 # In case pack files are deleted, release libgit2 cache and open file
# descriptors ASAP instead of waiting for Ruby garbage collection # descriptors ASAP instead of waiting for Ruby garbage collection
...@@ -106,6 +103,13 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -106,6 +103,13 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker
project.repository.has_visible_content? project.repository.has_visible_content?
end end
def update_repository_statistics(project)
project.repository.expire_statistics_caches
return if Gitlab::Database.read_only? # GitGarbageCollectWorker may be run on a Geo secondary
Projects::UpdateStatisticsService.new(project, nil, statistics: [:repository_size, :lfs_objects_size]).execute
end
def bitmaps_enabled? def bitmaps_enabled?
Gitlab::CurrentSettings.housekeeping_bitmaps_enabled Gitlab::CurrentSettings.housekeeping_bitmaps_enabled
end end
......
---
title: Does not update repository statistics when running housekeeping and repository
cleanup on a read-only instance
merge_request: 42409
author:
type: fixed
...@@ -25,12 +25,18 @@ RSpec.describe GitGarbageCollectWorker do ...@@ -25,12 +25,18 @@ RSpec.describe GitGarbageCollectWorker do
end end
shared_examples 'it updates the project statistics' do shared_examples 'it updates the project statistics' do
specify do it 'updates the project statistics' do
expect_any_instance_of(Projects::UpdateStatisticsService).to receive(:execute).and_call_original expect_next_instance_of(Projects::UpdateStatisticsService, project, nil, statistics: [:repository_size, :lfs_objects_size]) do |service|
expect(Projects::UpdateStatisticsService) expect(service).to receive(:execute).and_call_original
.to receive(:new) end
.with(project, nil, statistics: [:repository_size, :lfs_objects_size])
.and_call_original subject.perform(*params)
end
it 'does nothing if the database is read-only' do
allow(Gitlab::Database).to receive(:read_only?) { true }
expect_any_instance_of(Projects::UpdateStatisticsService).not_to receive(:execute)
subject.perform(*params) subject.perform(*params)
end end
...@@ -141,7 +147,8 @@ RSpec.describe GitGarbageCollectWorker do ...@@ -141,7 +147,8 @@ RSpec.describe GitGarbageCollectWorker do
end end
it 'does nothing if the database is read-only' do it 'does nothing if the database is read-only' do
expect(Gitlab::Database).to receive(:read_only?) { true } allow(Gitlab::Database).to receive(:read_only?) { true }
expect_any_instance_of(Gitlab::Cleanup::OrphanLfsFileReferences).not_to receive(:run!) expect_any_instance_of(Gitlab::Cleanup::OrphanLfsFileReferences).not_to receive(:run!)
subject.perform(*params) subject.perform(*params)
......
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