Commit dbc1a472 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'backup_wrap_concurrency' into 'master'

Fix race condition in concurrent backups

Closes #238847

See merge request gitlab-org/gitlab!39894
parents e6a58a0e 86527290
---
title: Fix race condition in concurrent backups
merge_request: 39894
author:
type: fixed
...@@ -26,13 +26,17 @@ module Backup ...@@ -26,13 +26,17 @@ module Backup
threads = Gitlab.config.repositories.storages.keys.map do |storage| threads = Gitlab.config.repositories.storages.keys.map do |storage|
Thread.new do Thread.new do
Rails.application.executor.wrap do
dump_storage(storage, semaphore, max_storage_concurrency: max_storage_concurrency) dump_storage(storage, semaphore, max_storage_concurrency: max_storage_concurrency)
rescue => e rescue => e
errors << e errors << e
end end
end end
end
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
threads.each(&:join) threads.each(&:join)
end
raise errors.pop unless errors.empty? raise errors.pop unless errors.empty?
end end
...@@ -155,6 +159,7 @@ module Backup ...@@ -155,6 +159,7 @@ module Backup
threads = Array.new(max_storage_concurrency) do threads = Array.new(max_storage_concurrency) do
Thread.new do Thread.new do
Rails.application.executor.wrap do
while project = queue.pop while project = queue.pop
semaphore.acquire semaphore.acquire
...@@ -169,6 +174,7 @@ module Backup ...@@ -169,6 +174,7 @@ module Backup
end end
end end
end end
end
Project.for_repository_storage(storage).find_each(batch_size: 100) do |project| Project.for_repository_storage(storage).find_each(batch_size: 100) do |project|
break unless errors.empty? break unless errors.empty?
...@@ -177,7 +183,9 @@ module Backup ...@@ -177,7 +183,9 @@ module Backup
end end
queue.close queue.close
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
threads.each(&:join) threads.each(&:join)
end
raise errors.pop unless errors.empty? raise errors.pop unless errors.empty?
end end
......
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