Commit 870e135b authored by Nick Thomas's avatar Nick Thomas

Avoid creating superfluous namespaces on Geo secondaries during sync

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