Commit 1daa906e authored by Sean McGivern's avatar Sean McGivern

Merge branch 'pks-create-repository-atomic' into 'master'

Prepare for CreateRepository starting to fail with existing repos

See merge request gitlab-org/gitlab!72491
parents d7f44cc9 ddf054fe
...@@ -1091,6 +1091,13 @@ class Repository ...@@ -1091,6 +1091,13 @@ class Repository
after_create after_create
true true
rescue Gitlab::Git::Repository::RepositoryExists
# We do not want to call `#after_create` given that we didn't create the
# repo, but we obviously have a mismatch between what's in our exists cache
# and actual on-disk state as seen by Gitaly. Let's thus expire our caches.
expire_status_cache
nil
end end
def create_from_bundle(bundle_path) def create_from_bundle(bundle_path)
......
...@@ -102,16 +102,15 @@ end ...@@ -102,16 +102,15 @@ end
RSpec.shared_examples 'sync retries use the snapshot RPC' do RSpec.shared_examples 'sync retries use the snapshot RPC' do
context 'snapshot synchronization method' do context 'snapshot synchronization method' do
before do let(:temp_repo) { subject.send(:temp_repo) }
allow(subject).to receive(:temp_repo) { repository }
end
def receive_create_from_snapshot def receive_create_from_snapshot
receive(:create_from_snapshot).with(primary.snapshot_url(repository), match(/^GL-Geo/)) { Gitaly::CreateRepositoryFromSnapshotResponse.new } receive(:create_from_snapshot).with(primary.snapshot_url(temp_repo), match(/^GL-Geo/)) { Gitaly::CreateRepositoryFromSnapshotResponse.new }
end end
it 'does not attempt to snapshot for initial sync' do it 'does not attempt to snapshot for initial sync' do
expect(repository).not_to receive_create_from_snapshot expect(repository).not_to receive_create_from_snapshot
expect(temp_repo).not_to receive_create_from_snapshot
expect(subject).to receive(:fetch_geo_mirror).with(repository) expect(subject).to receive(:fetch_geo_mirror).with(repository)
subject.execute subject.execute
...@@ -121,6 +120,7 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do ...@@ -121,6 +120,7 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do
registry_with_retry_count(retry_count - 1) registry_with_retry_count(retry_count - 1)
expect(repository).not_to receive_create_from_snapshot expect(repository).not_to receive_create_from_snapshot
expect(temp_repo).not_to receive_create_from_snapshot
expect(subject).to receive(:fetch_geo_mirror).with(repository) expect(subject).to receive(:fetch_geo_mirror).with(repository)
subject.execute subject.execute
...@@ -130,16 +130,18 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do ...@@ -130,16 +130,18 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do
let!(:registry) { registry_with_retry_count(retry_count + 1) } let!(:registry) { registry_with_retry_count(retry_count + 1) }
it 'attempts to snapshot' do it 'attempts to snapshot' do
expect(repository).to receive_create_from_snapshot expect(repository).not_to receive_create_from_snapshot
expect(subject).not_to receive(:fetch_geo_mirror).with(repository) expect(temp_repo).to receive_create_from_snapshot
expect(subject).not_to receive(:fetch_geo_mirror).with(temp_repo)
expect(subject).to receive(:set_temp_repository_as_main) expect(subject).to receive(:set_temp_repository_as_main)
subject.execute subject.execute
end end
it 'attempts to fetch if snapshotting raises an exception' do it 'attempts to fetch if snapshotting raises an exception' do
expect(repository).to receive_create_from_snapshot.and_raise(ArgumentError) expect(repository).not_to receive_create_from_snapshot
expect(subject).to receive(:fetch_geo_mirror).with(repository) expect(temp_repo).to receive_create_from_snapshot.and_raise(ArgumentError)
expect(subject).to receive(:fetch_geo_mirror).with(temp_repo)
subject.execute subject.execute
end end
......
...@@ -20,6 +20,7 @@ module Gitlab ...@@ -20,6 +20,7 @@ module Gitlab
EMPTY_REPOSITORY_CHECKSUM = '0000000000000000000000000000000000000000' EMPTY_REPOSITORY_CHECKSUM = '0000000000000000000000000000000000000000'
NoRepository = Class.new(::Gitlab::Git::BaseError) NoRepository = Class.new(::Gitlab::Git::BaseError)
RepositoryExists = Class.new(::Gitlab::Git::BaseError)
InvalidRepository = Class.new(::Gitlab::Git::BaseError) InvalidRepository = Class.new(::Gitlab::Git::BaseError)
InvalidBlobName = Class.new(::Gitlab::Git::BaseError) InvalidBlobName = Class.new(::Gitlab::Git::BaseError)
InvalidRef = Class.new(::Gitlab::Git::BaseError) InvalidRef = Class.new(::Gitlab::Git::BaseError)
...@@ -101,6 +102,8 @@ module Gitlab ...@@ -101,6 +102,8 @@ module Gitlab
def create_repository def create_repository
wrapped_gitaly_errors do wrapped_gitaly_errors do
gitaly_repository_client.create_repository gitaly_repository_client.create_repository
rescue GRPC::AlreadyExists => e
raise RepositoryExists, e.message
end end
end end
......
...@@ -111,11 +111,11 @@ RSpec.describe Gitlab::BackgroundMigration::PopulatePersonalSnippetStatistics do ...@@ -111,11 +111,11 @@ RSpec.describe Gitlab::BackgroundMigration::PopulatePersonalSnippetStatistics do
if with_repo if with_repo
allow(snippet).to receive(:disk_path).and_return(disk_path(snippet)) allow(snippet).to receive(:disk_path).and_return(disk_path(snippet))
raw_repository(snippet).create_repository
TestEnv.copy_repo(snippet, TestEnv.copy_repo(snippet,
bare_repo: TestEnv.factory_repo_path_bare, bare_repo: TestEnv.factory_repo_path_bare,
refs: TestEnv::BRANCH_SHA) refs: TestEnv::BRANCH_SHA)
raw_repository(snippet).create_repository
end end
end end
end end
......
...@@ -183,11 +183,11 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateProjectSnippetStatistics do ...@@ -183,11 +183,11 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateProjectSnippetStatistics do
if with_repo if with_repo
allow(snippet).to receive(:disk_path).and_return(disk_path(snippet)) allow(snippet).to receive(:disk_path).and_return(disk_path(snippet))
raw_repository(snippet).create_repository
TestEnv.copy_repo(snippet, TestEnv.copy_repo(snippet,
bare_repo: TestEnv.factory_repo_path_bare, bare_repo: TestEnv.factory_repo_path_bare,
refs: TestEnv::BRANCH_SHA) refs: TestEnv::BRANCH_SHA)
raw_repository(snippet).create_repository
end end
end end
end end
......
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