Commit ea7665aa authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Nick Thomas

Geo - Respect backoff time when repository have never been synced successfully

parent b229b7c5
...@@ -236,17 +236,17 @@ module Geo ...@@ -236,17 +236,17 @@ module Geo
# @return [ActiveRecord::Relation<Project>] list of projects updated recently # @return [ActiveRecord::Relation<Project>] list of projects updated recently
def legacy_find_projects_updated_recently def legacy_find_projects_updated_recently
registries = Geo::ProjectRegistry.dirty.retry_due.pluck(:project_id, :last_repository_successful_sync_at) registries = Geo::ProjectRegistry.dirty.retry_due.pluck(:project_id, :last_repository_synced_at)
return Project.none if registries.empty? return Project.none if registries.empty?
id_and_last_sync_values = registries.map do |id, last_repository_successful_sync_at| id_and_last_sync_values = registries.map do |id, last_repository_synced_at|
"(#{id}, #{quote_value(last_repository_successful_sync_at)})" "(#{id}, #{quote_value(last_repository_synced_at)})"
end end
joined_relation = current_node.projects.joins(<<~SQL) joined_relation = current_node.projects.joins(<<~SQL)
INNER JOIN INNER JOIN
(VALUES #{id_and_last_sync_values.join(',')}) (VALUES #{id_and_last_sync_values.join(',')})
project_registry(id, last_repository_successful_sync_at) project_registry(id, last_repository_synced_at)
ON #{Project.table_name}.id = project_registry.id ON #{Project.table_name}.id = project_registry.id
SQL SQL
......
...@@ -81,24 +81,24 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -81,24 +81,24 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
private private
def never_synced_repository? def never_synced_repository?
last_repository_successful_sync_at.nil? last_repository_synced_at.nil?
end end
def never_synced_wiki? def never_synced_wiki?
last_wiki_successful_sync_at.nil? last_wiki_synced_at.nil?
end end
def repository_sync_needed?(timestamp) def repository_sync_needed?(timestamp)
return false unless resync_repository? return false unless resync_repository?
return false if repository_retry_at && timestamp < repository_retry_at return false if repository_retry_at && timestamp < repository_retry_at
last_repository_synced_at.nil? || timestamp > last_repository_synced_at last_repository_synced_at && timestamp > last_repository_synced_at
end end
def wiki_sync_needed?(timestamp) def wiki_sync_needed?(timestamp)
return false unless resync_wiki? return false unless resync_wiki?
return false if wiki_retry_at && timestamp < wiki_retry_at return false if wiki_retry_at && timestamp < wiki_retry_at
last_wiki_synced_at.nil? || timestamp > last_wiki_synced_at last_wiki_synced_at && timestamp > last_wiki_synced_at
end end
end end
...@@ -65,7 +65,7 @@ module Geo ...@@ -65,7 +65,7 @@ module Geo
def find_project_ids_updated_recently(batch_size:) def find_project_ids_updated_recently(batch_size:)
shard_restriction(finder.find_projects_updated_recently(batch_size: batch_size)) shard_restriction(finder.find_projects_updated_recently(batch_size: batch_size))
.order('project_registry.last_repository_successful_sync_at ASC NULLS FIRST, projects.last_repository_updated_at ASC') .order('project_registry.last_repository_synced_at ASC NULLS FIRST, projects.last_repository_updated_at ASC')
.pluck(:id) .pluck(:id)
end end
......
---
title: Geo - Respect backoff time when repository have never been synced successfully
merge_request:
author:
type: fixed
...@@ -104,69 +104,73 @@ describe Geo::ProjectRegistry do ...@@ -104,69 +104,73 @@ describe Geo::ProjectRegistry do
end end
describe '#repository_sync_due?' do describe '#repository_sync_due?' do
where(:resync_repository, :last_successful_sync, :last_sync, :expected) do where(:last_synced_at, :resync, :retry_at, :expected) do
now = Time.now now = Time.now
past = now - 1.year past = now - 1.year
future = now + 1.year future = now + 1.year
true | nil | nil | true nil | false | nil | true
true | now | nil | true nil | true | nil | true
false | nil | nil | true nil | true | past | true
false | now | nil | false nil | true | future | true
true | nil | past | true past | false | nil | false
true | now | past | true past | true | nil | true
false | nil | past | true past | true | past | true
false | now | past | false past | true | future | false
true | nil | future | true future | false | nil | false
true | now | future | false future | true | nil | false
false | nil | future | true future | true | past | false
false | now | future | false future | true | future | false
end end
with_them do with_them do
before do before do
registry.update!(resync_repository: resync_repository, last_repository_successful_sync_at: last_successful_sync, last_repository_synced_at: last_sync) registry.update!(
last_repository_synced_at: last_synced_at,
resync_repository: resync,
repository_retry_at: retry_at
)
end end
subject { registry.repository_sync_due?(Time.now) } it { expect(registry.repository_sync_due?(Time.now)).to eq(expected) }
it { is_expected.to eq(expected) }
end end
end end
describe '#wiki_sync_due?' do describe '#wiki_sync_due?' do
where(:resync_wiki, :last_successful_sync, :last_sync, :expected) do where(:last_synced_at, :resync, :retry_at, :expected) do
now = Time.now now = Time.now
past = now - 1.year past = now - 1.year
future = now + 1.year future = now + 1.year
true | nil | nil | true nil | false | nil | true
true | now | nil | true nil | true | nil | true
false | nil | nil | true nil | true | past | true
false | now | nil | false nil | true | future | true
true | nil | past | true past | false | nil | false
true | now | past | true past | true | nil | true
false | nil | past | true past | true | past | true
false | now | past | false past | true | future | false
true | nil | future | true future | false | nil | false
true | now | future | false future | true | nil | false
false | nil | future | true future | true | past | false
false | now | future | false future | true | future | false
end end
with_them do with_them do
before do before do
registry.update!(resync_wiki: resync_wiki, last_wiki_successful_sync_at: last_successful_sync, last_wiki_synced_at: last_sync) registry.update!(
last_wiki_synced_at: last_synced_at,
resync_wiki: resync,
wiki_retry_at: retry_at
)
end end
subject { registry.wiki_sync_due?(Time.now) }
context 'wiki enabled' do context 'wiki enabled' do
it { is_expected.to eq(expected) } it { expect(registry.wiki_sync_due?(Time.now)).to eq(expected) }
end end
context 'wiki disabled' do context 'wiki disabled' do
...@@ -174,7 +178,7 @@ describe Geo::ProjectRegistry do ...@@ -174,7 +178,7 @@ describe Geo::ProjectRegistry do
project.update!(wiki_enabled: false) project.update!(wiki_enabled: false)
end end
it { is_expected.to be_falsy } it { expect(registry.wiki_sync_due?(Time.now)).to be_falsy }
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