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