debian-mirror-gitlab/lib/gitlab/gitaly_client/cleanup_service.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Gitlab
module GitalyClient
class CleanupService
2023-01-13 00:05:48 +05:30
include WithFeatureFlagActors
2019-02-15 15:39:39 +05:30
attr_reader :repository, :gitaly_repo, :storage
# 'repository' is a Gitlab::Git::Repository
def initialize(repository)
@repository = repository
@gitaly_repo = repository.gitaly_repository
@storage = repository.storage
2023-01-13 00:05:48 +05:30
self.repository_actor = repository
2019-02-15 15:39:39 +05:30
end
2019-07-31 22:56:46 +05:30
def apply_bfg_object_map_stream(io, &blk)
2023-01-13 00:05:48 +05:30
response = gitaly_client_call(
2019-07-31 22:56:46 +05:30
storage,
:cleanup_service,
:apply_bfg_object_map_stream,
build_object_map_enum(io),
2019-12-21 20:55:43 +05:30
timeout: GitalyClient.long_timeout
2019-07-31 22:56:46 +05:30
)
2020-07-28 23:09:34 +05:30
response.each(&blk)
2019-07-31 22:56:46 +05:30
end
private
2019-02-15 15:39:39 +05:30
2019-07-31 22:56:46 +05:30
def build_object_map_enum(io)
Enumerator.new do |y|
# First request. For simplicity, doesn't include any object map data
y << Gitaly::ApplyBfgObjectMapStreamRequest.new(repository: gitaly_repo)
2019-02-15 15:39:39 +05:30
2019-07-31 22:56:46 +05:30
# Now stream the BFG object map file to gitaly in chunks
2019-02-15 15:39:39 +05:30
while data = io.read(RepositoryService::MAX_MSG_SIZE)
2019-07-31 22:56:46 +05:30
y << Gitaly::ApplyBfgObjectMapStreamRequest.new(object_map: data)
2019-02-15 15:39:39 +05:30
break if io&.eof?
end
end
end
end
end
end