Commit fd326fc3 authored by Stan Hu's avatar Stan Hu

Merge branch '3371-filter-object-storage-backed-lfs-objects' into 'master'

Geo - Ignore S3-backed LFS objects on secondary nodes

Closes #3371

See merge request !2889
parents 4506615d c2555412
...@@ -114,11 +114,14 @@ class GeoNode < ActiveRecord::Base ...@@ -114,11 +114,14 @@ class GeoNode < ActiveRecord::Base
end end
def lfs_objects def lfs_objects
if restricted_project_ids relation =
LfsObject.joins(:projects).where(projects: { id: restricted_project_ids }) if restricted_project_ids
else LfsObject.joins(:projects).where(projects: { id: restricted_project_ids })
LfsObject.all else
end LfsObject.all
end
relation.with_files_stored_locally
end end
def projects def projects
......
---
title: Geo - Ignore S3-backed LFS objects on secondary nodes
merge_request: 2889
author:
type: other
...@@ -6,10 +6,9 @@ describe Geo::FileDownloadDispatchWorker do ...@@ -6,10 +6,9 @@ describe Geo::FileDownloadDispatchWorker do
before do before do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true) allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
allow_any_instance_of(Gitlab::ExclusiveLease) allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(true)
.to receive(:try_obtain).and_return(true) allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:renew).and_return(true)
allow_any_instance_of(Gitlab::ExclusiveLease) allow_any_instance_of(described_class).to receive(:over_time?).and_return(false)
.to receive(:renew).and_return(true)
WebMock.stub_request(:get, /primary-geo-node/).to_return(status: 200, body: "", headers: {}) WebMock.stub_request(:get, /primary-geo-node/).to_return(status: 200, body: "", headers: {})
end end
...@@ -37,13 +36,21 @@ describe Geo::FileDownloadDispatchWorker do ...@@ -37,13 +36,21 @@ describe Geo::FileDownloadDispatchWorker do
subject.perform subject.perform
end end
it 'executes GeoFileDownloadWorker for each LFS object' do context 'with LFS objects' do
create_list(:lfs_object, 2, :with_file) let!(:lfs_object_local_store) { create(:lfs_object, :with_file) }
let!(:lfs_object_remote_store) { create(:lfs_object, :with_file) }
allow_any_instance_of(described_class).to receive(:over_time?).and_return(false) before do
expect(GeoFileDownloadWorker).to receive(:perform_async).twice.and_call_original stub_lfs_object_storage
lfs_object_remote_store.file.migrate!(LfsObjectUploader::REMOTE_STORE)
end
subject.perform it 'filters S3-backed files' do
expect(GeoFileDownloadWorker).to receive(:perform_async).with(:lfs, lfs_object_local_store.id)
expect(GeoFileDownloadWorker).not_to receive(:perform_async).with(:lfs, lfs_object_remote_store.id)
subject.perform
end
end end
# Test the case where we have: # Test the case where we have:
...@@ -60,8 +67,6 @@ describe Geo::FileDownloadDispatchWorker do ...@@ -60,8 +67,6 @@ describe Geo::FileDownloadDispatchWorker do
create_list(:note, 2, :with_attachment) create_list(:note, 2, :with_attachment)
create(:appearance, logo: avatar, header_logo: avatar) create(:appearance, logo: avatar, header_logo: avatar)
allow_any_instance_of(described_class).to receive(:over_time?).and_return(false)
expect(GeoFileDownloadWorker).to receive(:perform_async).exactly(8).times.and_call_original expect(GeoFileDownloadWorker).to receive(:perform_async).exactly(8).times.and_call_original
# For 8 downloads, we expect three database reloads: # For 8 downloads, we expect three database reloads:
# 1. Load the first batch of 5. # 1. Load the first batch of 5.
...@@ -82,7 +87,6 @@ describe Geo::FileDownloadDispatchWorker do ...@@ -82,7 +87,6 @@ describe Geo::FileDownloadDispatchWorker do
before do before do
allow(ProjectCacheWorker).to receive(:perform_async).and_return(true) allow(ProjectCacheWorker).to receive(:perform_async).and_return(true)
allow_any_instance_of(described_class).to receive(:over_time?).and_return(false)
secondary.update_attribute(:namespaces, [synced_group]) secondary.update_attribute(:namespaces, [synced_group])
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