Commit 32a15367 authored by James Fargher's avatar James Fargher Committed by Douglas Barbosa Alexandre

Configure gitaly-backup for maximum concurrency per storage

GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY was already in place to limit
total concurrency per storage. We're now passing this through to
gitaly-backup.
parent 7d8e54ba
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
module Backup module Backup
# Backup and restores repositories using gitaly-backup # Backup and restores repositories using gitaly-backup
class GitalyBackup class GitalyBackup
def initialize(progress, parallel: nil) def initialize(progress, parallel: nil, parallel_storage: nil)
@progress = progress @progress = progress
@parallel = parallel @parallel = parallel
@parallel_storage = parallel_storage
end end
def start(type) def start(type)
...@@ -22,6 +23,7 @@ module Backup ...@@ -22,6 +23,7 @@ module Backup
args = [] args = []
args += ['-parallel', @parallel.to_s] if type == :create && @parallel args += ['-parallel', @parallel.to_s] if type == :create && @parallel
args += ['-parallel-storage', @parallel_storage.to_s] if type == :create && @parallel_storage
@read_io, @write_io = IO.pipe @read_io, @write_io = IO.pipe
@pid = Process.spawn(bin_path, command, '-path', backup_repos_path, *args, in: @read_io, out: @progress) @pid = Process.spawn(bin_path, command, '-path', backup_repos_path, *args, in: @read_io, out: @progress)
......
...@@ -299,7 +299,8 @@ namespace :gitlab do ...@@ -299,7 +299,8 @@ namespace :gitlab do
def repository_backup_strategy def repository_backup_strategy
if Feature.enabled?(:gitaly_backup) if Feature.enabled?(:gitaly_backup)
max_concurrency = ENV['GITLAB_BACKUP_MAX_CONCURRENCY'].presence max_concurrency = ENV['GITLAB_BACKUP_MAX_CONCURRENCY'].presence
Backup::GitalyBackup.new(progress, parallel: max_concurrency) max_storage_concurrency = ENV['GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY'].presence
Backup::GitalyBackup.new(progress, parallel: max_concurrency, parallel_storage: max_storage_concurrency)
else else
Backup::GitalyRpcBackup.new(progress) Backup::GitalyRpcBackup.new(progress)
end end
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Backup::GitalyBackup do RSpec.describe Backup::GitalyBackup do
let(:parallel) { nil } let(:parallel) { nil }
let(:parallel_storage) { nil }
let(:progress) do let(:progress) do
Tempfile.new('progress').tap do |progress| Tempfile.new('progress').tap do |progress|
progress.unlink progress.unlink
...@@ -14,7 +15,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -14,7 +15,7 @@ RSpec.describe Backup::GitalyBackup do
progress.close progress.close
end end
subject { described_class.new(progress, parallel: parallel) } subject { described_class.new(progress, parallel: parallel, parallel_storage: parallel_storage) }
context 'unknown' do context 'unknown' do
it 'fails to start unknown' do it 'fails to start unknown' do
...@@ -59,6 +60,17 @@ RSpec.describe Backup::GitalyBackup do ...@@ -59,6 +60,17 @@ RSpec.describe Backup::GitalyBackup do
end end
end end
context 'parallel_storage option set' do
let(:parallel_storage) { 3 }
it 'passes parallel option through' do
expect(Process).to receive(:spawn).with(anything, 'create', '-path', anything, '-parallel-storage', '3', { in: anything, out: progress }).and_call_original
subject.start(:create)
subject.wait
end
end
it 'raises when the exit code not zero' do it 'raises when the exit code not zero' do
expect(subject).to receive(:bin_path).and_return(Gitlab::Utils.which('false')) expect(subject).to receive(:bin_path).and_return(Gitlab::Utils.which('false'))
......
...@@ -407,7 +407,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do ...@@ -407,7 +407,7 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
.with(max_concurrency: 5, max_storage_concurrency: 2) .with(max_concurrency: 5, max_storage_concurrency: 2)
.and_call_original .and_call_original
end end
expect(::Backup::GitalyBackup).to receive(:new).with(anything, parallel: 5).and_call_original expect(::Backup::GitalyBackup).to receive(:new).with(anything, parallel: 5, parallel_storage: 2).and_call_original
expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process expect { run_rake_task('gitlab:backup:create') }.to output.to_stdout_from_any_process
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