Remove legacy query to find unsynced job artifacts

This commit removes the legacy queries to find unsynced
job artifacts since we made Foreign Data Wrapper (FDW)
a hard requirement for Geo on GitLab 12.0.
parent 63ff161d
......@@ -50,14 +50,12 @@ module Geo
# @param [Array<Integer>] except_artifact_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_artifact_ids: [])
relation =
if use_legacy_queries_for_selective_sync?
legacy_finder.job_artifacts_unsynced(except_artifact_ids: except_artifact_ids)
else
job_artifacts_unsynced(except_artifact_ids: except_artifact_ids)
end
relation.limit(batch_size)
fdw_geo_node
.job_artifacts
.syncable
.missing_job_artifact_registry
.id_not_in(except_artifact_ids)
.limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -114,14 +112,6 @@ module Geo
.syncable
end
def job_artifacts_unsynced(except_artifact_ids:)
fdw_geo_node
.job_artifacts
.syncable
.missing_job_artifact_registry
.id_not_in(except_artifact_ids)
end
def job_artifacts_migrated_local(except_artifact_ids:)
fdw_geo_node
.job_artifacts
......
......@@ -6,16 +6,6 @@ module Geo
current_node.job_artifacts.syncable
end
def job_artifacts_unsynced(except_artifact_ids: [])
registry_artifact_ids = Geo::JobArtifactRegistry.pluck_artifact_key | except_artifact_ids
legacy_left_outer_join_registry_ids(
syncable,
registry_artifact_ids,
Ci::JobArtifact
)
end
def job_artifacts_migrated_local(except_artifact_ids: [])
registry_artifact_ids = Geo::JobArtifactRegistry.pluck_artifact_key - except_artifact_ids
......
......@@ -716,6 +716,68 @@ describe Geo::JobArtifactRegistryFinder, :geo do
end
end
include_examples 'finds all the things'
describe '#find_migrated_local' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_remote_1) { create(:ci_job_artifact, :remote_store, project: synced_project) }
let!(:job_artifact_remote_2) { create(:ci_job_artifact, :remote_store, project: unsynced_project) }
let!(:job_artifact_remote_3) { create(:ci_job_artifact, :remote_store, project: project_broken_storage, expire_at: Date.yesterday) }
it 'returns job artifacts remotely and successfully synced locally' do
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_1.id)
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_2.id)
job_artifacts = subject.find_migrated_local(batch_size: 10, except_artifact_ids: [job_artifact_remote_1.id])
expect(job_artifacts).to match_ids(job_artifact_remote_2)
end
it 'excludes synced job artifacts that are stored locally' do
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_1.id)
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_2.id)
create(:geo_job_artifact_registry, artifact_id: job_artifact_1.id)
job_artifacts = subject.find_migrated_local(batch_size: 10)
expect(job_artifacts).to match_ids(job_artifact_remote_1, job_artifact_remote_2)
end
it 'includes synced job artifacts that are expired' do
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_3.id)
job_artifacts = subject.find_migrated_local(batch_size: 10)
expect(job_artifacts).to match_ids(job_artifact_remote_3)
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'returns job artifacts remotely and successfully synced locally' do
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_1.id)
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_2.id)
job_artifacts = subject.find_migrated_local(batch_size: 10)
expect(job_artifacts).to match_ids(job_artifact_remote_1)
end
end
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'returns job artifacts remotely and successfully synced locally' do
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_1.id)
create(:geo_job_artifact_registry, artifact_id: job_artifact_remote_3.id)
job_artifacts = subject.find_migrated_local(batch_size: 10)
expect(job_artifacts).to match_ids(job_artifact_remote_3)
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