Commit 422fa21d authored by Stan Hu's avatar Stan Hu

Merge branch '11126-fix-repository-size-check-ce' into 'master'

Add client code to call GetObjectDirectorySize RPC

See merge request gitlab-org/gitlab-ce!28918
parents b8a62abd 40fd0b9e
...@@ -426,7 +426,7 @@ group :ed25519 do ...@@ -426,7 +426,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 1.27.0', require: 'gitaly' gem 'gitaly-proto', '~> 1.32.0', require: 'gitaly'
gem 'grpc', '~> 1.19.0' gem 'grpc', '~> 1.19.0'
......
...@@ -298,7 +298,7 @@ GEM ...@@ -298,7 +298,7 @@ GEM
gettext_i18n_rails (>= 0.7.1) gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gitaly-proto (1.27.0) gitaly-proto (1.32.0)
grpc (~> 1.0) grpc (~> 1.0)
github-markup (1.7.0) github-markup (1.7.0)
gitlab-default_value_for (3.1.1) gitlab-default_value_for (3.1.1)
...@@ -1087,7 +1087,7 @@ DEPENDENCIES ...@@ -1087,7 +1087,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3) gettext_i18n_rails_js (~> 1.3)
gitaly-proto (~> 1.27.0) gitaly-proto (~> 1.32.0)
github-markup (~> 1.7.0) github-markup (~> 1.7.0)
gitlab-default_value_for (~> 3.1.1) gitlab-default_value_for (~> 3.1.1)
gitlab-labkit (~> 0.2.0) gitlab-labkit (~> 0.2.0)
......
...@@ -282,6 +282,11 @@ module Gitlab ...@@ -282,6 +282,11 @@ module Gitlab
(size.to_f / 1024).round(2) (size.to_f / 1024).round(2)
end end
# Return git object directory size in bytes
def object_directory_size
gitaly_repository_client.get_object_directory_size.to_f * 1024
end
# Build an array of commits. # Build an array of commits.
# #
# Usage. # Usage.
......
...@@ -47,6 +47,13 @@ module Gitlab ...@@ -47,6 +47,13 @@ module Gitlab
response.size response.size
end end
def get_object_directory_size
request = Gitaly::GetObjectDirectorySizeRequest.new(repository: @gitaly_repo)
response = GitalyClient.call(@storage, :repository_service, :get_object_directory_size, request, timeout: GitalyClient.medium_timeout)
response.size
end
def apply_gitattributes(revision) def apply_gitattributes(revision)
request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: encode_binary(revision)) request = Gitaly::ApplyGitattributesRequest.new(repository: @gitaly_repo, revision: encode_binary(revision))
GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request, timeout: GitalyClient.fast_timeout) GitalyClient.call(@storage, :repository_service, :apply_gitattributes, request, timeout: GitalyClient.fast_timeout)
......
...@@ -186,6 +186,18 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -186,6 +186,18 @@ describe Gitlab::Git::Repository, :seed_helper do
it { is_expected.to be < 2 } it { is_expected.to be < 2 }
end end
describe '#object_directory_size' do
before do
allow(repository.gitaly_repository_client)
.to receive(:get_object_directory_size)
.and_return(2)
end
subject { repository.object_directory_size }
it { is_expected.to eq 2048 }
end
describe '#empty?' do describe '#empty?' do
it { expect(repository).not_to be_empty } it { expect(repository).not_to be_empty }
end end
......
...@@ -73,6 +73,17 @@ describe Gitlab::GitalyClient::RepositoryService do ...@@ -73,6 +73,17 @@ describe Gitlab::GitalyClient::RepositoryService do
end end
end end
describe '#get_object_directory_size' do
it 'sends a get_object_directory_size message' do
expect_any_instance_of(Gitaly::RepositoryService::Stub)
.to receive(:get_object_directory_size)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return(size: 0)
client.get_object_directory_size
end
end
describe '#apply_gitattributes' do describe '#apply_gitattributes' do
let(:revision) { 'master' } let(:revision) { 'master' }
......
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