Commit 5a9ee3b0 authored by Stan Hu's avatar Stan Hu

Merge branch 'geo-prevent-removing-registry-records' into 'master'

[Geo] Don't remove project registry records

See merge request gitlab-org/gitlab-ee!5768
parents 7e551159 2f37d406
...@@ -16,8 +16,7 @@ module Geo ...@@ -16,8 +16,7 @@ module Geo
GEO_REMOTE_NAME = 'geo'.freeze GEO_REMOTE_NAME = 'geo'.freeze
LEASE_TIMEOUT = 8.hours.freeze LEASE_TIMEOUT = 8.hours.freeze
LEASE_KEY_PREFIX = 'geo_sync_service'.freeze LEASE_KEY_PREFIX = 'geo_sync_service'.freeze
RETRY_BEFORE_REDOWNLOAD = 5 RETRIES_BEFORE_REDOWNLOAD = 5
RETRY_LIMIT = 8
def initialize(project) def initialize(project)
@project = project @project = project
...@@ -29,13 +28,8 @@ module Geo ...@@ -29,13 +28,8 @@ module Geo
if should_be_retried? if should_be_retried?
sync_repository sync_repository
elsif should_be_redownloaded?
sync_repository(true)
else else
# Clean up the state of sync to start a new cycle sync_repository(true)
registry.delete
log_info("Clean up #{type} sync status")
break
end end
log_info("Finished #{type} sync") log_info("Finished #{type} sync")
...@@ -97,13 +91,7 @@ module Geo ...@@ -97,13 +91,7 @@ module Geo
def should_be_retried? def should_be_retried?
return false if registry.public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend return false if registry.public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
retry_count <= RETRY_BEFORE_REDOWNLOAD retry_count <= RETRIES_BEFORE_REDOWNLOAD
end
def should_be_redownloaded?
return true if registry.public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
(RETRY_BEFORE_REDOWNLOAD..RETRY_LIMIT) === retry_count
end end
def current_node def current_node
......
---
title: "[Geo] Don't remove project registry records"
merge_request:
author:
type: fixed
...@@ -252,7 +252,7 @@ describe Geo::RepositorySyncService do ...@@ -252,7 +252,7 @@ describe Geo::RepositorySyncService do
context 'retries' do context 'retries' do
it 'tries to fetch repo' do it 'tries to fetch repo' do
create(:geo_project_registry, project: project, repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD - 1) create(:geo_project_registry, project: project, repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD - 1)
expect(subject).to receive(:sync_repository).with(no_args) expect(subject).to receive(:sync_repository).with(no_args)
...@@ -260,7 +260,7 @@ describe Geo::RepositorySyncService do ...@@ -260,7 +260,7 @@ describe Geo::RepositorySyncService do
end end
it 'sets the redownload flag to false after success' do it 'sets the redownload flag to false after success' do
registry = create(:geo_project_registry, project: project, repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD + 1, force_to_redownload_repository: true) registry = create(:geo_project_registry, project: project, repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD + 1, force_to_redownload_repository: true)
subject.execute subject.execute
...@@ -268,7 +268,7 @@ describe Geo::RepositorySyncService do ...@@ -268,7 +268,7 @@ describe Geo::RepositorySyncService do
end end
it 'tries to redownload repo' do it 'tries to redownload repo' do
create(:geo_project_registry, project: project, repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD + 1) create(:geo_project_registry, project: project, repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD + 1)
expect(subject).to receive(:sync_repository).with(true).and_call_original expect(subject).to receive(:sync_repository).with(true).and_call_original
expect(subject.gitlab_shell).to receive(:mv_repository).exactly(2).times.and_call_original expect(subject.gitlab_shell).to receive(:mv_repository).exactly(2).times.and_call_original
...@@ -294,7 +294,7 @@ describe Geo::RepositorySyncService do ...@@ -294,7 +294,7 @@ describe Geo::RepositorySyncService do
create( create(
:geo_project_registry, :geo_project_registry,
project: project, project: project,
repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD - 1, repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD - 1,
force_to_redownload_repository: true force_to_redownload_repository: true
) )
...@@ -307,7 +307,7 @@ describe Geo::RepositorySyncService do ...@@ -307,7 +307,7 @@ describe Geo::RepositorySyncService do
create( create(
:geo_project_registry, :geo_project_registry,
project: project, project: project,
repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD - 1, repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD - 1,
force_to_redownload_repository: true force_to_redownload_repository: true
) )
...@@ -323,7 +323,7 @@ describe Geo::RepositorySyncService do ...@@ -323,7 +323,7 @@ describe Geo::RepositorySyncService do
registry = create( registry = create(
:geo_project_registry, :geo_project_registry,
project: project, project: project,
repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD + 2000, repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD + 2000,
repository_retry_at: timestamp, repository_retry_at: timestamp,
force_to_redownload_repository: true force_to_redownload_repository: true
) )
......
...@@ -119,7 +119,7 @@ shared_examples 'geo base sync fetch and repack' do ...@@ -119,7 +119,7 @@ shared_examples 'geo base sync fetch and repack' do
end end
shared_examples 'sync retries use the snapshot RPC' do shared_examples 'sync retries use the snapshot RPC' do
let(:retry_count) { Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD } let(:retry_count) { Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD }
context 'snapshot synchronization method' do context 'snapshot synchronization method' do
before do before do
......
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