2018-11-19 10:03:58 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class CleanupService
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
def apply_bfg_object_map_stream(io, &blk)
|
2020-06-30 20:09:02 -04:00
|
|
|
response = GitalyClient.call(
|
2019-03-25 10:29:51 -04:00
|
|
|
storage,
|
|
|
|
:cleanup_service,
|
|
|
|
:apply_bfg_object_map_stream,
|
|
|
|
build_object_map_enum(io),
|
2019-09-19 14:06:18 -04:00
|
|
|
timeout: GitalyClient.long_timeout
|
2020-06-30 20:09:02 -04:00
|
|
|
)
|
|
|
|
response.each(&blk)
|
2019-03-25 10:29:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
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)
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
# Now stream the BFG object map file to gitaly in chunks
|
2018-11-19 10:03:58 -05:00
|
|
|
while data = io.read(RepositoryService::MAX_MSG_SIZE)
|
2019-03-25 10:29:51 -04:00
|
|
|
y << Gitaly::ApplyBfgObjectMapStreamRequest.new(object_map: data)
|
|
|
|
|
2018-12-15 08:49:15 -05:00
|
|
|
break if io&.eof?
|
2018-11-19 10:03:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|