Commit 80c7702e authored by Jacob Vosmaer's avatar Jacob Vosmaer

Fetch pipeline refs by name in CI runner

This reverts af43dd6a with the aim of
reducing Gitaly server resouce usage when fetching Git data for CI
builds. Instead of fetching the pipeline ref by SHA, we go back to
fetching it by name 'refs/pipelines/1234'. This causes `git fetch` to
use the 'ref-prefix' option [1] when fetching refs. At the time of
af43dd6a, the server side
implementation of 'ref-prefix' was very inefficient. This got fixed in
Git by [2].

Currently each CI fetch causes a full ref walk on the Gitaly server.
By going back to fetching by ref, this changes to a filtered refwalk
which is much faster. Especially on repositories with many (server
side) refs, such as gitlab-org/gitlab.

[1]: https://gitlab.com/gitlab-org/gitlab-git/-/blob/v2.33.0/Documentation/technical/protocol-v2.txt#L191-193
[2]: https://gitlab.com/gitlab-org/gitlab-git/-/commit/b3970c702cb0acc0551d88a5f34ad4ad2e2a6d39
parent 96f5de2a
...@@ -105,10 +105,7 @@ module Ci ...@@ -105,10 +105,7 @@ module Ci
end end
def refspec_for_persistent_ref def refspec_for_persistent_ref
# Use persistent_ref.sha because it sometimes causes 'git fetch' to do "+#{pipeline.persistent_ref.path}:#{pipeline.persistent_ref.path}"
# less work. See
# https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/746.
"+#{pipeline.persistent_ref.sha}:#{pipeline.persistent_ref.path}"
end end
def persistent_ref_exist? def persistent_ref_exist?
......
...@@ -173,11 +173,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -173,11 +173,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}", is_expected.to contain_exactly("+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}",
"+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end
it 'uses a SHA in the persistent refspec' do
expect(subject[0]).to match(%r{^\+[0-9a-f]{40}:refs/pipelines/[0-9]+$})
end end
context 'when ref is tag' do context 'when ref is tag' do
...@@ -185,7 +181,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -185,7 +181,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}", is_expected.to contain_exactly("+refs/tags/#{build.ref}:refs/tags/#{build.ref}",
"+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end end
context 'when GIT_DEPTH is zero' do context 'when GIT_DEPTH is zero' do
...@@ -196,7 +192,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -196,7 +192,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly('+refs/tags/*:refs/tags/*', is_expected.to contain_exactly('+refs/tags/*:refs/tags/*',
'+refs/heads/*:refs/remotes/origin/*', '+refs/heads/*:refs/remotes/origin/*',
"+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") "+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end end
end end
end end
...@@ -212,7 +208,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -212,7 +208,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected is_expected
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}") .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}")
end end
context 'when GIT_DEPTH is zero' do context 'when GIT_DEPTH is zero' do
...@@ -222,7 +218,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -222,7 +218,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected is_expected
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
'+refs/heads/*:refs/remotes/origin/*', '+refs/heads/*:refs/remotes/origin/*',
'+refs/tags/*:refs/tags/*') '+refs/tags/*:refs/tags/*')
end end
...@@ -232,7 +228,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -232,7 +228,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) } let(:merge_request) { create(:merge_request, :with_legacy_detached_merge_request_pipeline) }
it 'returns the correct refspecs' do it 'returns the correct refspecs' do
is_expected.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", is_expected.to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
end end
end end
...@@ -250,7 +246,7 @@ RSpec.describe Ci::BuildRunnerPresenter do ...@@ -250,7 +246,7 @@ RSpec.describe Ci::BuildRunnerPresenter do
it 'exposes the persistent pipeline ref' do it 'exposes the persistent pipeline ref' do
is_expected is_expected
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}") "+refs/heads/#{build.ref}:refs/remotes/origin/#{build.ref}")
end end
end end
......
...@@ -156,7 +156,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -156,7 +156,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
'sha' => job.sha, 'sha' => job.sha,
'before_sha' => job.before_sha, 'before_sha' => job.before_sha,
'ref_type' => 'branch', 'ref_type' => 'branch',
'refspecs' => ["+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", 'refspecs' => ["+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
"+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"], "+refs/heads/#{job.ref}:refs/remotes/origin/#{job.ref}"],
'depth' => project.ci_default_git_depth } 'depth' => project.ci_default_git_depth }
end end
...@@ -291,7 +291,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -291,7 +291,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
expect(json_response['git_info']['refspecs']) expect(json_response['git_info']['refspecs'])
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
'+refs/tags/*:refs/tags/*', '+refs/tags/*:refs/tags/*',
'+refs/heads/*:refs/remotes/origin/*') '+refs/heads/*:refs/remotes/origin/*')
end end
...@@ -359,7 +359,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do ...@@ -359,7 +359,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
expect(json_response['git_info']['refspecs']) expect(json_response['git_info']['refspecs'])
.to contain_exactly("+#{pipeline.sha}:refs/pipelines/#{pipeline.id}", .to contain_exactly("+refs/pipelines/#{pipeline.id}:refs/pipelines/#{pipeline.id}",
'+refs/tags/*:refs/tags/*', '+refs/tags/*:refs/tags/*',
'+refs/heads/*:refs/remotes/origin/*') '+refs/heads/*:refs/remotes/origin/*')
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