Populate the tracking DB for projects synced before upgrade to 9.0

parent a67245a8
......@@ -51,7 +51,18 @@ class GeoBackfillWorker
end
def synced?(project)
project.repository_exists? || registry_exists?(project)
return true if registry_exists?(project)
return false unless project.repository.exists?
return false if project.repository.exists? && project.repository.empty?
# When Geo customers upgrade to 9.0, the secondaries nodes that are enabled
# will start the backfilling process automatically. We need to populate the
# tracking database correctly for projects synced before. Otherwise, the
# query to retrieve the projects will always return the same 100 projects
# because they don't have entries in the tracking database.
create_missing_registry(project)
true
end
def registry_exists?(project)
......@@ -60,6 +71,16 @@ class GeoBackfillWorker
.any?
end
def create_missing_registry(project)
logger.info "Creating missing registry for project #{project.path_with_namespace} (#{project.id})"
Geo::ProjectRegistry.create(
project_id: project.id,
last_repository_synced_at: DateTime.now,
last_repository_successful_sync_at: DateTime.now
)
end
def try_obtain_lease
lease = Gitlab::ExclusiveLease.new(lease_key, timeout: lease_timeout).try_obtain
......
......@@ -26,12 +26,28 @@ describe Geo::GeoBackfillWorker, services: true do
subject.perform
end
it 'does not perform Geo::RepositoryBackfillService for projects that repository exists' do
create_list(:project, 2)
context 'when repository exists' do
it 'does not perform Geo::RepositoryBackfillService for non empty repositories' do
create_list(:project, 2)
expect(Geo::RepositoryBackfillService).to receive(:new).twice.and_return(spy)
expect(Geo::RepositoryBackfillService).to receive(:new).twice.and_return(spy)
subject.perform
subject.perform
end
it 'performs Geo::RepositoryBackfillService for empty repositories' do
create(:empty_project)
expect(Geo::RepositoryBackfillService).to receive(:new).exactly(3).times.and_return(spy)
subject.perform
end
it 'creates missing registry for non empty repositories' do
create(:project)
expect { subject.perform }.to change(Geo::ProjectRegistry, :count).by(3)
end
end
it 'does not perform Geo::RepositoryBackfillService when can not obtain a lease' 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