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
GEO_REMOTE_NAME = 'geo'.freeze
LEASE_TIMEOUT = 8.hours.freeze
LEASE_KEY_PREFIX = 'geo_sync_service'.freeze
RETRY_BEFORE_REDOWNLOAD = 5
RETRY_LIMIT = 8
RETRIES_BEFORE_REDOWNLOAD = 5
def initialize(project)
@project = project
......@@ -29,13 +28,8 @@ module Geo
if should_be_retried?
sync_repository
elsif should_be_redownloaded?
sync_repository(true)
else
# Clean up the state of sync to start a new cycle
registry.delete
log_info("Clean up #{type} sync status")
break
sync_repository(true)
end
log_info("Finished #{type} sync")
......@@ -97,13 +91,7 @@ module Geo
def should_be_retried?
return false if registry.public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
retry_count <= RETRY_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
retry_count <= RETRIES_BEFORE_REDOWNLOAD
end
def current_node
......
---
title: "[Geo] Don't remove project registry records"
merge_request:
author:
type: fixed
......@@ -252,7 +252,7 @@ describe Geo::RepositorySyncService do
context 'retries' 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)
......@@ -260,7 +260,7 @@ describe Geo::RepositorySyncService do
end
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
......@@ -268,7 +268,7 @@ describe Geo::RepositorySyncService do
end
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.gitlab_shell).to receive(:mv_repository).exactly(2).times.and_call_original
......@@ -294,7 +294,7 @@ describe Geo::RepositorySyncService do
create(
:geo_project_registry,
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
)
......@@ -307,7 +307,7 @@ describe Geo::RepositorySyncService do
create(
:geo_project_registry,
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
)
......@@ -323,7 +323,7 @@ describe Geo::RepositorySyncService do
registry = create(
:geo_project_registry,
project: project,
repository_retry_count: Geo::BaseSyncService::RETRY_BEFORE_REDOWNLOAD + 2000,
repository_retry_count: Geo::BaseSyncService::RETRIES_BEFORE_REDOWNLOAD + 2000,
repository_retry_at: timestamp,
force_to_redownload_repository: true
)
......
......@@ -119,7 +119,7 @@ shared_examples 'geo base sync fetch and repack' do
end
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
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