Commit b92bbde8 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Repository archives: dispatching to HGitaly for Mercurial repos

For archive production, the Rails app duty is to return
direct connection information to Workhorse, so that it can call
Gitaly directly.

We're reusing the dispatching logic for our existing (yet unplugged)
HGitaly integration: by prefixing the storage (shard) with `hg:` for
Mercurial repositories, we have the `GitalyClient.address` return
connection information for the HGitaly server.

For this to work, we need `archive_metadata` method of the
Mercurial Repository classes to provide the Mercurial SHA, which we do
by intoducing the dedicated `archive_sha` method.

--HG--
branch : heptapod
parent f1f3ff16acc1
Pipeline #11587 skipped with stages
......@@ -237,17 +237,26 @@ def delete_all_refs_except(prefixes)
end
end
# Return the SHA to send to Gitaly's GetArchive for a given main SHA
#
# Typically overridden in subclasses.
def archive_sha(sha)
sha
end
def archive_metadata(ref, storage_path, project_path, format = "tar.gz", append_sha:, path: nil)
ref ||= root_ref
commit = Gitlab::Git::Commit.find(self, ref)
return {} if commit.nil?
prefix = archive_prefix(ref, commit.id, project_path, append_sha: append_sha, path: path)
commit_id = archive_sha(commit.id)
prefix = archive_prefix(ref, commit_id, project_path, append_sha: append_sha, path: path)
{
'ArchivePrefix' => prefix,
'ArchivePath' => archive_file_path(storage_path, commit.id, prefix, format),
'CommitId' => commit.id,
'ArchivePath' => archive_file_path(storage_path, commit_id, prefix, format),
'CommitId' => commit_id,
'GitalyRepository' => gitaly_repository.to_h
}
end
......
......@@ -300,6 +300,10 @@ def hgsha_from_sha(sha)
hg_sha_map[sha]
end
def archive_sha(sha)
hgsha_from_sha(sha)
end
def batch_by_hgsha(sha_prefixes)
# TODO stupid algorithm. Above a certain size, it's more efficient
# to call hg with a the `sha_prefixes.join('+')` revset but then, we
......
module Gitlab
module Mercurial
def archive_sha(sha)
sha
end
class HGitalyRepository < HgGitRepository
def gitaly_ref_client
@gitaly_ref_client ||= Gitlab::GitalyClient::RefService.new(self, vcs: 'hg')
......
......@@ -95,7 +95,7 @@ def send_git_archive(repository, ref:, format:, append_sha:, path: nil)
# If present, DisableCache must be a Boolean. Otherwise
# workhorse ignores it.
params['DisableCache'] = true if git_archive_cache_disabled?
params['GitalyServer'] = gitaly_server_hash(repository)
params['GitalyServer'] = gitaly_server_hash(repository, vcs_dispatch: true)
[
SEND_DATA_HEADER,
......@@ -241,9 +241,17 @@ def encode_binary(binary)
Base64.encode64(binary)
end
def gitaly_server_hash(repository)
def gitaly_server_hash(repository, vcs_dispatch: false)
vcs_storage =
if vcs_dispatch
Gitlab::GitalyClient.vcs_qualified_storage(
repository.shard, repository.mercurial? ? "hg" : "git")
else
repository.shard
end
{
address: Gitlab::GitalyClient.address(repository.shard),
address: Gitlab::GitalyClient.address(vcs_storage),
token: Gitlab::GitalyClient.token(repository.shard),
features: Feature::Gitaly.server_feature_flags
}
......
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