Commit fd9d7438 authored by Nick Thomas's avatar Nick Thomas

Skip backfill workers for shards that are disabled in selective sync

parent fe547a9f
......@@ -12,7 +12,7 @@ module Geo
return unless Gitlab::Geo.geo_database_configured?
return unless Gitlab::Geo.secondary?
shards = healthy_shards
shards = selective_sync_filter(healthy_shards)
Gitlab::Geo::ShardHealthCache.update(shards)
......@@ -32,5 +32,11 @@ module Geo
.compact
.uniq
end
def selective_sync_filter(shards)
return shards unless ::Gitlab::Geo.current_node&.selective_sync_by_shards?
shards & ::Gitlab::Geo.current_node.selective_sync_shards
end
end
end
......@@ -9,6 +9,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
let!(:project_in_synced_group) { create(:project, group: synced_group) }
let!(:unsynced_project) { create(:project) }
let(:healthy_shard) { project_in_synced_group.repository.storage }
subject { described_class.new }
before do
......@@ -32,6 +34,21 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
Sidekiq::Testing.inline! { subject.perform }
end
it 'skips backfill for projects on shards excluded by selective sync' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: [healthy_shard])
# Report both shards as healthy
expect(Gitlab::HealthChecks::FsShardsCheck).to receive(:readiness)
.and_return([result(true, healthy_shard), result(true, 'broken')])
expect(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness)
.and_return([result(true, healthy_shard), result(true, 'broken')])
expect(Geo::RepositoryShardSyncWorker).to receive(:perform_async).with('default')
expect(Geo::RepositoryShardSyncWorker).not_to receive(:perform_async).with('broken')
Sidekiq::Testing.inline! { subject.perform }
end
it 'skips backfill for projects on missing shards' do
missing_not_synced = create(:project, group: synced_group)
missing_not_synced.update_column(:repository_storage, 'unknown')
......@@ -52,17 +69,14 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
it 'skips backfill for projects with downed Gitaly server' do
create(:project, group: synced_group, repository_storage: 'broken')
unhealthy_dirty = create(:project, group: synced_group, repository_storage: 'broken')
healthy_shard = project_in_synced_group.repository.storage
create(:geo_project_registry, :synced, :repository_dirty, project: unhealthy_dirty)
# Report only one healthy shard
allow(Gitlab::HealthChecks::FsShardsCheck).to receive(:readiness).and_return(
[Gitlab::HealthChecks::Result.new(true, nil, { shard: healthy_shard }),
Gitlab::HealthChecks::Result.new(true, nil, { shard: 'broken' })])
allow(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness).and_return(
[Gitlab::HealthChecks::Result.new(true, nil, { shard: healthy_shard }),
Gitlab::HealthChecks::Result.new(false, nil, { shard: 'broken' })])
expect(Gitlab::HealthChecks::FsShardsCheck).to receive(:readiness)
.and_return([result(true, healthy_shard), result(true, 'broken')])
expect(Gitlab::HealthChecks::GitalyCheck).to receive(:readiness)
.and_return([result(true, healthy_shard), result(false, 'broken')])
expect(Geo::RepositoryShardSyncWorker).to receive(:perform_async).with(healthy_shard)
expect(Geo::RepositoryShardSyncWorker).not_to receive(:perform_async).with('broken')
......@@ -71,4 +85,8 @@ describe Geo::RepositorySyncWorker, :geo, :clean_gitlab_redis_cache do
end
end
end
def result(success, 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