Remove legacy finder for job artifacts

This removes the legacy finder for job artifactssince
we made Foreign Data Wrapper (FDW) a hard requirement
for Geo on GitLab 12.0.
parent 89c650ab
...@@ -2,37 +2,33 @@ ...@@ -2,37 +2,33 @@
module Geo module Geo
class JobArtifactRegistryFinder < RegistryFinder class JobArtifactRegistryFinder < RegistryFinder
def initialize(current_node:)
@current_node = Geo::Fdw::GeoNode.find(current_node.id)
end
def count_registry
Geo::JobArtifactRegistry.count
end
def count_syncable def count_syncable
syncable.count syncable.count
end end
def count_synced def count_synced
registries_for_job_artifacts registries_for_job_artifacts.merge(Geo::JobArtifactRegistry.synced).count
.merge(Geo::JobArtifactRegistry.synced)
.count
end end
def count_failed def count_failed
registries_for_job_artifacts registries_for_job_artifacts.merge(Geo::JobArtifactRegistry.failed).count
.merge(Geo::JobArtifactRegistry.failed)
.count
end end
def count_synced_missing_on_primary def count_synced_missing_on_primary
registries_for_job_artifacts registries_for_job_artifacts.merge(Geo::JobArtifactRegistry.synced.missing_on_primary).count
.merge(Geo::JobArtifactRegistry.synced.missing_on_primary)
.count
end
def count_registry
Geo::JobArtifactRegistry.count
end end
def syncable def syncable
if use_legacy_queries_for_selective_sync? if selective_sync?
legacy_finder.syncable job_artifacts.syncable
elsif selective_sync?
fdw_geo_node.job_artifacts.syncable
else else
Ci::JobArtifact.syncable Ci::JobArtifact.syncable
end end
...@@ -50,8 +46,7 @@ module Geo ...@@ -50,8 +46,7 @@ module Geo
# @param [Array<Integer>] except_artifact_ids ids that will be ignored from the query # @param [Array<Integer>] except_artifact_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_artifact_ids: []) def find_unsynced(batch_size:, except_artifact_ids: [])
fdw_geo_node job_artifacts
.job_artifacts
.syncable .syncable
.missing_job_artifact_registry .missing_job_artifact_registry
.id_not_in(except_artifact_ids) .id_not_in(except_artifact_ids)
...@@ -61,8 +56,7 @@ module Geo ...@@ -61,8 +56,7 @@ module Geo
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def find_migrated_local(batch_size:, except_artifact_ids: []) def find_migrated_local(batch_size:, except_artifact_ids: [])
fdw_geo_node job_artifacts
.job_artifacts
.inner_join_job_artifact_registry .inner_join_job_artifact_registry
.with_files_stored_remotely .with_files_stored_remotely
.id_not_in(except_artifact_ids) .id_not_in(except_artifact_ids)
...@@ -93,19 +87,12 @@ module Geo ...@@ -93,19 +87,12 @@ module Geo
private private
# rubocop:disable CodeReuse/Finder def job_artifacts
def legacy_finder current_node.job_artifacts
@legacy_finder ||= Geo::LegacyJobArtifactRegistryFinder.new(current_node: current_node)
end
# rubocop:enable CodeReuse/Finder
def fdw_geo_node
@fdw_geo_node ||= Geo::Fdw::GeoNode.find(current_node.id)
end end
def registries_for_job_artifacts def registries_for_job_artifacts
fdw_geo_node job_artifacts
.job_artifacts
.inner_join_job_artifact_registry .inner_join_job_artifact_registry
.syncable .syncable
end end
......
# frozen_string_literal: true
module Geo
class LegacyJobArtifactRegistryFinder < RegistryFinder
def syncable
current_node.job_artifacts.syncable
end
end
end
require 'spec_helper' require 'spec_helper'
describe Geo::JobArtifactRegistryFinder, :geo do describe Geo::JobArtifactRegistryFinder, :geo_fdw do
include ::EE::GeoHelpers include ::EE::GeoHelpers
# Using let() instead of set() because set() does not work properly # Using let() instead of set() because set() does not work properly
...@@ -582,138 +582,6 @@ describe Geo::JobArtifactRegistryFinder, :geo do ...@@ -582,138 +582,6 @@ describe Geo::JobArtifactRegistryFinder, :geo do
end end
end end
context 'FDW', :geo_fdw do include_examples 'counts all the things'
context 'with use_fdw_queries_for_selective_sync disabled' do include_examples 'finds all the things'
before do
stub_feature_flags(use_fdw_queries_for_selective_sync: false)
end
include_examples 'counts all the things'
include_examples 'finds all the things'
end
context 'with use_fdw_queries_for_selective_sync enabled' do
before do
stub_feature_flags(use_fdw_queries_for_selective_sync: true)
end
include_examples 'counts all the things'
include_examples 'finds all the things'
end
end
context 'Legacy' do
before do
stub_fdw_disabled
end
describe '#count_syncable' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) }
let!(:job_artifact_3) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_4) { create(:ci_job_artifact, project: unsynced_project) }
let!(:job_artifact_5) { create(:ci_job_artifact, project: project_broken_storage) }
let!(:job_artifact_6) { create(:ci_job_artifact, project: project_broken_storage) }
it 'counts job artifacts' do
expect(subject.count_syncable).to eq 6
end
it 'ignores remote job artifacts' do
job_artifact_1.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_syncable).to eq 5
end
it 'ignores expired job artifacts' do
job_artifact_1.update_column(:expire_at, Date.yesterday)
expect(subject.count_syncable).to eq 5
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts job artifacts' do
expect(subject.count_syncable).to eq 2
end
it 'ignores remote job artifacts' do
job_artifact_1.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_syncable).to eq 1
end
it 'ignores expired job artifacts' do
job_artifact_1.update_column(:expire_at, Date.yesterday)
expect(subject.count_syncable).to eq 1
end
end
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'counts job artifacts' do
expect(subject.count_syncable).to eq 2
end
it 'ignores remote job artifacts' do
job_artifact_5.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_syncable).to eq 1
end
it 'ignores expired job artifacts' do
job_artifact_5.update_column(:expire_at, Date.yesterday)
expect(subject.count_syncable).to eq 1
end
end
end
describe '#count_registry' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) }
let!(:job_artifact_3) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_4) { create(:ci_job_artifact, project: unsynced_project) }
let!(:job_artifact_5) { create(:ci_job_artifact, project: project_broken_storage) }
let!(:job_artifact_6) { create(:ci_job_artifact, project: project_broken_storage) }
before do
create(:geo_job_artifact_registry, artifact_id: job_artifact_1.id, success: false)
create(:geo_job_artifact_registry, artifact_id: job_artifact_3.id, missing_on_primary: true)
create(:geo_job_artifact_registry, artifact_id: job_artifact_4.id)
create(:geo_job_artifact_registry, artifact_id: job_artifact_6.id)
end
it 'counts file registries for job artifacts' do
expect(subject.count_registry).to eq 4
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'does not apply the selective sync restriction' do
expect(subject.count_registry).to eq 4
end
end
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'does not apply the selective sync restriction' do
expect(subject.count_registry).to eq 4
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