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
# Refresh the branch cache in case garbage collection caused a ref lookup to fail
flush_ref_caches(project) if task == :gc
if task != :pack_refs
project.repository.expire_statistics_caches
Projects::UpdateStatisticsService.new(project, nil, statistics: [:repository_size, :lfs_objects_size]).execute
end
update_repository_statistics(project) if task != :pack_refs
# In case pack files are deleted, release libgit2 cache and open file
# descriptors ASAP instead of waiting for Ruby garbage collection
......@@ -106,6 +103,13 @@ class GitGarbageCollectWorker # rubocop:disable Scalability/IdempotentWorker
project.repository.has_visible_content?
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?
Gitlab::CurrentSettings.housekeeping_bitmaps_enabled
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
end
shared_examples 'it updates the project statistics' do
specify do
expect_any_instance_of(Projects::UpdateStatisticsService).to receive(:execute).and_call_original
expect(Projects::UpdateStatisticsService)
.to receive(:new)
.with(project, nil, statistics: [:repository_size, :lfs_objects_size])
.and_call_original
it 'updates the project statistics' do
expect_next_instance_of(Projects::UpdateStatisticsService, project, nil, statistics: [:repository_size, :lfs_objects_size]) do |service|
expect(service).to receive(:execute).and_call_original
end
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)
end
......@@ -141,7 +147,8 @@ RSpec.describe GitGarbageCollectWorker do
end
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!)
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