Remove legacy query to find synced LFS objects

This commit removes the legacy queries to find synced
LFS objects since we made Foreign Data Wrapper (FDW)
a hard requirement for Geo on GitLab 12.0.
parent a36995c9
...@@ -6,14 +6,6 @@ module Geo ...@@ -6,14 +6,6 @@ module Geo
current_node.lfs_objects.syncable current_node.lfs_objects.syncable
end end
def lfs_objects_synced
legacy_inner_join_registry_ids(
syncable,
Geo::FileRegistry.lfs_objects.synced.pluck_file_key,
LfsObject
)
end
def lfs_objects_failed def lfs_objects_failed
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
syncable, syncable,
......
...@@ -110,11 +110,7 @@ module Geo ...@@ -110,11 +110,7 @@ module Geo
end end
def lfs_objects_synced def lfs_objects_synced
if use_legacy_queries_for_selective_sync? fdw_geo_node.lfs_objects.synced
legacy_finder.lfs_objects_synced
else
fdw_geo_node.lfs_objects.synced
end
end end
def lfs_objects_failed def lfs_objects_failed
......
...@@ -31,6 +31,27 @@ describe Geo::LfsObjectRegistryFinder, :geo do ...@@ -31,6 +31,27 @@ describe Geo::LfsObjectRegistryFinder, :geo do
stub_lfs_object_storage stub_lfs_object_storage
end end
shared_examples_for 'a file registry finder' do
it 'responds to file registry finder methods' do
file_registry_finder_methods = %i{
syncable
count_syncable
count_synced
count_failed
count_synced_missing_on_primary
count_registry
find_unsynced
find_migrated_local
find_retryable_failed_registries
find_retryable_synced_missing_on_primary_registries
}
file_registry_finder_methods.each do |method|
expect(subject).to respond_to(method)
end
end
end
shared_examples 'counts all the things' do shared_examples 'counts all the things' do
describe '#count_syncable' do describe '#count_syncable' do
before do before do
...@@ -642,5 +663,277 @@ describe Geo::LfsObjectRegistryFinder, :geo do ...@@ -642,5 +663,277 @@ describe Geo::LfsObjectRegistryFinder, :geo do
end end
end end
it_behaves_like 'a file registry finder' context 'FDW', :geo_fdw do
context 'with use_fdw_queries_for_selective_sync disabled' do
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
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
create(:lfs_objects_project, project: unsynced_project, lfs_object: lfs_object_3)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_4)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_5)
end
it 'counts LFS objects' do
expect(subject.count_syncable).to eq 5
end
it 'ignores remote LFS objects' do
lfs_object_1.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_syncable).to eq 4
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts LFS objects' do
expect(subject.count_syncable).to eq 2
end
it 'ignores remote LFS objects' do
lfs_object_1.update_column(:file_store, ObjectStorage::Store::REMOTE)
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 LFS objects' do
expect(subject.count_syncable).to eq 2
end
it 'ignores remote LFS objects' do
lfs_object_5.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_syncable).to eq 1
end
end
end
describe '#count_registry' do
it 'counts file registries for LFS objects' do
create(:geo_file_registry, :lfs, file_id: lfs_object_remote_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_3.id)
create(:geo_file_registry, :avatar)
expect(subject.count_registry).to eq 3
end
context 'with selective sync by namespace' do
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
create(:lfs_objects_project, project: unsynced_project, lfs_object: lfs_object_3)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'does not apply the selective sync restriction' do
create(:geo_file_registry, :lfs, file_id: lfs_object_remote_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_3.id)
create(:geo_file_registry, :avatar)
expect(subject.count_registry).to eq 3
end
end
context 'with selective sync by shard' do
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project_in_nested_group, lfs_object: lfs_object_2)
create(:lfs_objects_project, project: unsynced_project, lfs_object: lfs_object_3)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_4)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_remote_1)
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'does not apply the selective sync restriction' do
create(:geo_file_registry, :lfs, file_id: lfs_object_remote_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_4.id)
create(:geo_file_registry, :avatar)
expect(subject.count_registry).to eq 3
end
end
end
describe '#count_failed' do
it 'counts LFS objects that sync has failed' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_3.id)
expect(subject.count_failed).to eq 2
end
it 'ignores remote LFS objects' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_remote_1.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_3.id)
expect(subject.count_failed).to eq 2
end
context 'with selective sync by namespace' do
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2)
create(:lfs_objects_project, project: unsynced_project, lfs_object: lfs_object_3)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts LFS objects that sync has failed' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_3.id)
expect(subject.count_failed).to eq 1
end
it 'ignores remote LFS objects' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_1.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_3.id)
lfs_object_1.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_failed).to eq 1
end
end
context 'with selective sync by shard' do
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2)
create(:lfs_objects_project, project: unsynced_project, lfs_object: lfs_object_3)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_4)
create(:lfs_objects_project, project: project_broken_storage, lfs_object: lfs_object_5)
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'counts LFS objects that sync has failed' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_3.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_4.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_5.id)
expect(subject.count_failed).to eq 1
end
it 'ignores remote LFS objects' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_1.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_2.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_3.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_4.id)
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_5.id)
lfs_object_5.update_column(:file_store, ObjectStorage::Store::REMOTE)
expect(subject.count_failed).to eq 1
end
end
end
describe '#count_synced_missing_on_primary' do
it 'counts LFS objects that have been synced and are missing on the primary' do
create(:geo_file_registry, :lfs, file_id: lfs_object_1.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 1
end
it 'excludes LFS objects that are not missing on the primary' do
create(:geo_file_registry, :lfs, file_id: lfs_object_1.id)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 1
end
it 'excludes LFS objects that are not synced' do
create(:geo_file_registry, :lfs, :failed, file_id: lfs_object_1.id, missing_on_primary: true)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 1
end
it 'ignores remote LFS objects' do
create(:geo_file_registry, :lfs, file_id: lfs_object_remote_1.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 0
end
context 'with selective sync by namespace' do
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_1)
create(:lfs_objects_project, project: synced_project, lfs_object: lfs_object_2)
create(:lfs_objects_project, project: unsynced_project, lfs_object: lfs_object_3)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts LFS objects that has been synced' do
create(:geo_file_registry, :lfs, file_id: lfs_object_1.id, missing_on_primary: true)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id, missing_on_primary: true)
create(:geo_file_registry, :lfs, file_id: lfs_object_3.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 2
end
it 'ignores remote LFS objects' do
create(:geo_file_registry, :lfs, file_id: lfs_object_remote_1.id, missing_on_primary: true)
create(:geo_file_registry, :lfs, file_id: lfs_object_2.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 1
end
end
end
include_examples 'finds all the things'
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