Commit a6e438f7 authored by John Cai's avatar John Cai

Adding PraefectInfoService as a gitaly service client

PraefectInfoService is a gRPC service in praefect that provides
information like the checksum of a repository and all of its replicas
parent 928dcc19
......@@ -944,6 +944,10 @@ module Gitlab
Gitlab::GitalyClient::ConflictsService.new(self, our_commit_oid, their_commit_oid)
end
def praefect_info_client
@praefect_info_client ||= Gitlab::GitalyClient::PraefectInfoService.new(self)
end
def clean_stale_repository_files
wrapped_gitaly_errors do
gitaly_repository_client.cleanup if exists?
......@@ -1019,6 +1023,12 @@ module Gitlab
raise NoRepository # Guard against data races.
end
def replicas
wrapped_gitaly_errors do
praefect_info_client.replicas
end
end
private
def empty_diff_stats
......
# frozen_string_literal: true
module Gitlab
module GitalyClient
class PraefectInfoService
def initialize(repository)
@repository = repository
@gitaly_repo = repository.gitaly_repository
@storage = repository.storage
end
def replicas
request = Gitaly::RepositoryReplicasRequest.new(repository: @gitaly_repo)
GitalyClient.call(@storage, :praefect_info_service, :repository_replicas, request, timeout: GitalyClient.fast_timeout)
end
end
end
end
......@@ -1919,6 +1919,15 @@ describe Gitlab::Git::Repository, :seed_helper do
end
end
describe '#replicas', :praefect do
it 'gets the replica checksum through praefect' do
resp = repository.replicas
expect(resp.replicas).to be_empty
expect(resp.primary.checksum).to eq(repository.checksum)
end
end
describe '#clean_stale_repository_files' do
let(:worktree_id) { 'rebase-1' }
let(:gitlab_worktree_path) { File.join(repository_path, 'gitlab-worktree', worktree_id) }
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GitalyClient::PraefectInfoService do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:gitaly_repository) { repository.gitaly_repository }
let(:client) { described_class.new(repository) }
describe '#repository_replicas', :praefect do
it 'sends an RPC request' do
request = Gitaly::RepositoryReplicasRequest.new(repository: gitaly_repository)
expect_any_instance_of(Gitaly::PraefectInfoService::Stub).to receive(:repository_replicas).with(request, kind_of(Hash))
client.replicas
end
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