Commit e50d7588 authored by Stan Hu's avatar Stan Hu

Merge branch 'fix-geo-add-namespace-weirdness' into 'master'

Avoid creating superfluous namespaces on Geo secondaries during sync

See merge request gitlab-org/gitlab-ee!5378
parents 6e58c573 870e135b
......@@ -201,17 +201,21 @@ module Geo
# Remove the deleted path in case it exists, but it may not be there
gitlab_shell.remove_repository(project.repository_storage_path, deleted_disk_path_temp)
# Make sure we have a namespace directory
gitlab_shell.add_namespace(project.repository_storage_path, deleted_disk_path_temp)
# Make sure we have the most current state of exists?
repository.expire_exists_cache
if repository.exists? && !gitlab_shell.mv_repository(project.repository_storage_path, repository.disk_path, deleted_disk_path_temp)
raise Gitlab::Shell::Error, 'Can not move original repository out of the way'
# Move the current canonical repository to the deleted path for reference
if repository.exists?
ensure_repository_namespace(deleted_disk_path_temp)
unless gitlab_shell.mv_repository(project.repository_storage_path, repository.disk_path, deleted_disk_path_temp)
raise Gitlab::Shell::Error, 'Can not move original repository out of the way'
end
end
gitlab_shell.add_namespace(project.repository_storage_path, repository.disk_path)
# Move the temporary repository to the canonical path
ensure_repository_namespace(repository.disk_path)
unless gitlab_shell.mv_repository(project.repository_storage_path, disk_path_temp, repository.disk_path)
raise Gitlab::Shell::Error, 'Can not move temporary repository'
......@@ -223,6 +227,13 @@ module Geo
end
end
def ensure_repository_namespace(disk_path)
gitlab_shell.add_namespace(
project.repository_storage_path,
File.dirname(disk_path)
)
end
# To prevent the retry time from storing invalid dates in the database,
# cap the max time to a week plus some random jitter value.
def next_retry_time(retry_count)
......
......@@ -257,12 +257,12 @@ describe Geo::RepositorySyncService do
expect(subject.gitlab_shell).to receive(:add_namespace).with(
project.repository_storage_path,
"@failed-geo-sync/#{repository.disk_path}"
"@failed-geo-sync/#{File.dirname(repository.disk_path)}"
).and_call_original
expect(subject.gitlab_shell).to receive(:add_namespace).with(
project.repository_storage_path,
repository.disk_path
File.dirname(repository.disk_path)
).and_call_original
expect(subject.gitlab_shell).to receive(:remove_repository).exactly(2).times.and_call_original
......
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