diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-06-08 11:49:13 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-06-08 11:49:13 +0000 |
commit | f068479e637c52b839c3474a87c2d01e82ba0829 (patch) | |
tree | 07cb0c54629d9374677de06f0ebf1de3766a92e5 /lib | |
parent | d0a040d315f160a1f6700cdb2aa8d194c2104f55 (diff) | |
parent | 2bbac66cae09a1dde81121399daa56bf166dd78e (diff) | |
download | gitlab-ce-f068479e637c52b839c3474a87c2d01e82ba0829.tar.gz |
Merge branch 'use-restore-custom-hooks-gitaly' into 'master'
Use RestoreCustomHooks RPC in restore rake task
See merge request gitlab-org/gitlab-ce!19370
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backup/repository.rb | 33 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/repository_service.rb | 55 |
2 files changed, 60 insertions, 28 deletions
diff --git a/lib/backup/repository.rb b/lib/backup/repository.rb index 1b1c83d9fb3..0119c5d6851 100644 --- a/lib/backup/repository.rb +++ b/lib/backup/repository.rb @@ -112,18 +112,31 @@ module Backup end end + def local_restore_custom_hooks(project, dir) + path_to_project_repo = Gitlab::GitalyClient::StorageSettings.allow_disk_access do + path_to_repo(project) + end + cmd = %W(tar -xf #{path_to_tars(project, dir)} -C #{path_to_project_repo} #{dir}) + output, status = Gitlab::Popen.popen(cmd) + unless status.zero? + progress_warn(project, cmd.join(' '), output) + end + end + + def gitaly_restore_custom_hooks(project, dir) + custom_hooks_path = path_to_tars(project, dir) + Gitlab::GitalyClient::RepositoryService.new(project.repository) + .restore_custom_hooks(custom_hooks_path) + end + def restore_custom_hooks(project) - # TODO: Need to find a way to do this for gitaly - # Gitaly migration issue: https://gitlab.com/gitlab-org/gitaly/issues/1195 in_path(path_to_tars(project)) do |dir| - path_to_project_repo = Gitlab::GitalyClient::StorageSettings.allow_disk_access do - path_to_repo(project) - end - cmd = %W(tar -xf #{path_to_tars(project, dir)} -C #{path_to_project_repo} #{dir}) - - output, status = Gitlab::Popen.popen(cmd) - unless status.zero? - progress_warn(project, cmd.join(' '), output) + gitaly_migrate(:restore_custom_hooks) do |is_enabled| + if is_enabled + local_restore_custom_hooks(project, dir) + else + gitaly_restore_custom_hooks(project, dir) + end end end end diff --git a/lib/gitlab/gitaly_client/repository_service.rb b/lib/gitlab/gitaly_client/repository_service.rb index ee01f5a5bd9..4340f779e53 100644 --- a/lib/gitlab/gitaly_client/repository_service.rb +++ b/lib/gitlab/gitaly_client/repository_service.rb @@ -213,25 +213,20 @@ module Gitlab end def create_from_bundle(bundle_path) - request = Gitaly::CreateRepositoryFromBundleRequest.new(repository: @gitaly_repo) - enum = Enumerator.new do |y| - File.open(bundle_path, 'rb') do |f| - while data = f.read(MAX_MSG_SIZE) - request.data = data - - y.yield request - - request = Gitaly::CreateRepositoryFromBundleRequest.new - end - end - end - - GitalyClient.call( - @storage, - :repository_service, + gitaly_repo_stream_request( + bundle_path, :create_repository_from_bundle, - enum, - timeout: GitalyClient.default_timeout + Gitaly::CreateRepositoryFromBundleRequest, + GitalyClient.default_timeout + ) + end + + def restore_custom_hooks(custom_hooks_path) + gitaly_repo_stream_request( + custom_hooks_path, + :restore_custom_hooks, + Gitaly::RestoreCustomHooksRequest, + GitalyClient.default_timeout ) end @@ -311,6 +306,30 @@ module Gitlab request = Gitaly::SearchFilesByContentRequest.new(repository: @gitaly_repo, ref: ref, query: query) GitalyClient.call(@storage, :repository_service, :search_files_by_content, request).flat_map(&:matches) end + + private + + def gitaly_repo_stream_request(file_path, rpc_name, request_class, timeout) + request = request_class.new(repository: @gitaly_repo) + enum = Enumerator.new do |y| + File.open(file_path, 'rb') do |f| + while data = f.read(MAX_MSG_SIZE) + request.data = data + + y.yield request + request = request_class.new + end + end + end + + GitalyClient.call( + @storage, + :repository_service, + rpc_name, + enum, + timeout: timeout + ) + end end end end |