Commit a4ed1e16 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '7722-geo-repository-verification-lease-key' into 'master'

Resolve "Geo::RepositoryVerification::Secondary::ShardWorker lease key is not namespaced by shard name"

Closes #7722

See merge request gitlab-org/gitlab-ee!7474
parents dde69913 79c6a1a7
...@@ -14,17 +14,17 @@ module Geo ...@@ -14,17 +14,17 @@ module Geo
super() super()
end end
# We need a custom key here since we are running one worker per shard
def lease_key
@lease_key ||= "#{self.class.name.underscore}:shard:#{shard_name}"
end
private private
def worker_metadata def worker_metadata
{ shard: shard_name } { shard: shard_name }
end end
# We need a custom key here since we are running one worker per shard
def lease_key
@lease_key ||= "#{self.class.name.underscore}:shard:#{shard_name}"
end
def max_capacity def max_capacity
current_node.verification_max_capacity current_node.verification_max_capacity
end end
......
...@@ -14,6 +14,10 @@ module Geo ...@@ -14,6 +14,10 @@ module Geo
super() super()
end end
def lease_key
@lease_key ||= "#{self.class.name.underscore}:shard:#{shard_name}"
end
private private
def worker_metadata def worker_metadata
......
---
title: 'Geo: repository shard verification job should have unique lease keys per shard
name'
merge_request: 7474
author:
type: fixed
...@@ -19,6 +19,14 @@ describe Geo::RepositoryVerification::Primary::ShardWorker, :postgresql, :clean_ ...@@ -19,6 +19,14 @@ describe Geo::RepositoryVerification::Primary::ShardWorker, :postgresql, :clean_
Gitlab::ShardHealthCache.update([shard_name]) Gitlab::ShardHealthCache.update([shard_name])
end end
context 'shard worker scheduler' do
it 'acquires lock namespacing it per shard name' do
subject.perform(shard_name)
expect(subject.lease_key).to include(shard_name)
end
end
it 'performs Geo::RepositoryVerification::Primary::SingleWorker for each project' do it 'performs Geo::RepositoryVerification::Primary::SingleWorker for each project' do
create_list(:project, 2) create_list(:project, 2)
......
...@@ -22,7 +22,15 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -22,7 +22,15 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
Gitlab::ShardHealthCache.update([shard_name]) Gitlab::ShardHealthCache.update([shard_name])
end end
it 'schedules job for each project' do context 'shard worker scheduler' do
it 'acquires lock namespacing it per shard name' do
subject.perform(shard_name)
expect(subject.lease_key).to include(shard_name)
end
end
it 'schedule a job for each project' do
other_project = create(:project) other_project = create(:project)
create(:repository_state, :repository_verified, project: project) create(:repository_state, :repository_verified, project: project)
create(:repository_state, :repository_verified, project: other_project) create(:repository_state, :repository_verified, project: other_project)
...@@ -34,7 +42,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -34,7 +42,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
subject.perform(shard_name) subject.perform(shard_name)
end end
it 'schedules job for projects missing repository verification' do it 'schedule jobs for projects missing repository verification' do
create(:repository_state, :repository_verified, :wiki_verified, project: project) create(:repository_state, :repository_verified, :wiki_verified, project: project)
missing_repository_verification = create(:geo_project_registry, :synced, :wiki_verified, project: project) missing_repository_verification = create(:geo_project_registry, :synced, :wiki_verified, project: project)
...@@ -43,7 +51,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -43,7 +51,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
subject.perform(shard_name) subject.perform(shard_name)
end end
it 'schedules job for projects missing wiki verification' do it 'schedule jobs for projects missing wiki verification' do
create(:repository_state, :repository_verified, :wiki_verified, project: project) create(:repository_state, :repository_verified, :wiki_verified, project: project)
missing_wiki_verification = create(:geo_project_registry, :synced, :repository_verified, project: project) missing_wiki_verification = create(:geo_project_registry, :synced, :repository_verified, project: project)
...@@ -73,7 +81,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -73,7 +81,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
let(:project1_repo_verified) { create(:repository_state, :repository_verified).project } let(:project1_repo_verified) { create(:repository_state, :repository_verified).project }
let(:project2_repo_verified) { create(:repository_state, :repository_verified).project } let(:project2_repo_verified) { create(:repository_state, :repository_verified).project }
let(:project3_repo_failed) { create(:repository_state, :repository_failed).project } let(:project3_repo_failed) { create(:repository_state, :repository_failed).project }
let(:project4_wiki_verified) { create(:repository_state, :wiki_verified).project } let(:project4_wiki_verified) { create(:repository_state, :wiki_verified).project }
let(:project5_both_verified) { create(:repository_state, :repository_verified, :wiki_verified).project } let(:project5_both_verified) { create(:repository_state, :repository_verified, :wiki_verified).project }
let(:project6_both_verified) { create(:repository_state, :repository_verified, :wiki_verified).project } let(:project6_both_verified) { create(:repository_state, :repository_verified, :wiki_verified).project }
......
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