Put the streaming backfill worker behind a feature flag

parent bb5b266b
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
module Geo module Geo
class RepositorySyncWorker < Geo::Scheduler::Secondary::PerShardSchedulerWorker class RepositorySyncWorker < Geo::Scheduler::Secondary::PerShardSchedulerWorker
def schedule_job(shard_name) def schedule_job(shard_name)
# TODO: Put this behind a feature flag if ::Feature.enabled?(:geo_streaming_results_repository_sync)
Geo::Secondary::RepositoryBackfillWorker.perform_async(shard_name) Geo::Secondary::RepositoryBackfillWorker.perform_async(shard_name)
else
Geo::RepositoryShardSyncWorker.perform_async(shard_name)
end
end end
end end
end end
...@@ -8,11 +8,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do ...@@ -8,11 +8,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
let!(:synced_group) { create(:group) } let!(:synced_group) { create(:group) }
let!(:project_in_synced_group) { create(:project, group: synced_group) } let!(:project_in_synced_group) { create(:project, group: synced_group) }
let!(:unsynced_project) { create(:project) } let!(:unsynced_project) { create(:project) }
let(:healthy_shard_name) { project_in_synced_group.repository.storage } let(:healthy_shard_name) { project_in_synced_group.repository.storage }
subject { described_class.new }
before do before do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
end end
...@@ -21,7 +18,7 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do ...@@ -21,7 +18,7 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
Sidekiq::Testing.inline! { example.run } Sidekiq::Testing.inline! { example.run }
end end
describe '#perform' do shared_examples '#perform' do |worker|
context 'additional shards' do context 'additional shards' do
it 'skips backfill for repositories on other shards' do it 'skips backfill for repositories on other shards' do
create(:project, :broken_storage, group: synced_group) create(:project, :broken_storage, group: synced_group)
...@@ -32,7 +29,7 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do ...@@ -32,7 +29,7 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
raise GRPC::Unavailable.new('No Gitaly available') raise GRPC::Unavailable.new('No Gitaly available')
end end
expect(Geo::RepositoryShardSyncWorker).not_to receive(:perform_async).with('broken') expect(worker).not_to receive(:perform_async).with('broken')
subject.perform subject.perform
end end
...@@ -44,8 +41,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do ...@@ -44,8 +41,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
expect(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness) expect(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness)
.and_return([result(true, healthy_shard_name), result(true, 'broken')]) .and_return([result(true, healthy_shard_name), result(true, 'broken')])
expect(Geo::RepositoryShardSyncWorker).to receive(:perform_async).with('default') expect(worker).to receive(:perform_async).with('default')
expect(Geo::RepositoryShardSyncWorker).not_to receive(:perform_async).with('broken') expect(worker).not_to receive(:perform_async).with('broken')
subject.perform subject.perform
end end
...@@ -61,8 +58,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do ...@@ -61,8 +58,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
# hide the 'broken' storage for this spec # hide the 'broken' storage for this spec
stub_storage_settings({}) stub_storage_settings({})
expect(Geo::RepositoryShardSyncWorker).to receive(:perform_async).with(project_in_synced_group.repository.storage) expect(worker).to receive(:perform_async).with(project_in_synced_group.repository.storage)
expect(Geo::RepositoryShardSyncWorker).not_to receive(:perform_async).with('unknown') expect(worker).not_to receive(:perform_async).with('unknown')
subject.perform subject.perform
end end
...@@ -77,14 +74,30 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do ...@@ -77,14 +74,30 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
expect(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness) expect(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness)
.and_return([result(true, healthy_shard_name), result(false, 'broken')]) .and_return([result(true, healthy_shard_name), result(false, 'broken')])
expect(Geo::RepositoryShardSyncWorker).to receive(:perform_async).with(healthy_shard_name) expect(worker).to receive(:perform_async).with(healthy_shard_name)
expect(Geo::RepositoryShardSyncWorker).not_to receive(:perform_async).with('broken') expect(worker).not_to receive(:perform_async).with('broken')
subject.perform subject.perform
end end
end end
end end
context 'when geo_streaming_results_repository_sync flag is enabled', :geo_fdw do
before do
stub_feature_flags(geo_streaming_results_repository_sync: true)
end
include_examples '#perform', Geo::Secondary::RepositoryBackfillWorker
end
context 'when geo_streaming_results_repository_sync flag is disabled' do
before do
stub_feature_flags(geo_streaming_results_repository_sync: false)
end
include_examples '#perform', Geo::RepositoryShardSyncWorker
end
def result(success, shard) def result(success, shard)
Gitlab::HealthChecks::Result.new(success, nil, { shard: shard }) Gitlab::HealthChecks::Result.new(success, nil, { shard: shard })
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