Commit 080311e7 authored by Stan Hu's avatar Stan Hu

Merge branch 'fix/1911' into 'master'

Handle missing tracking DB configuration on a Geo secondary node

Closes #1911

See merge request !1436
parents 420d5cd1 65703064
class Geo::BaseRegistry < ActiveRecord::Base class Geo::BaseRegistry < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
if Gitlab::Geo.secondary? || (Rails.env.test? && Rails.configuration.respond_to?(:geo_database)) if Gitlab::Geo.configured? && (Gitlab::Geo.secondary? || Rails.env.test?)
establish_connection Rails.configuration.geo_database establish_connection Rails.configuration.geo_database
end end
end end
...@@ -6,6 +6,7 @@ class GeoBackfillWorker ...@@ -6,6 +6,7 @@ class GeoBackfillWorker
BATCH_SIZE = 100.freeze BATCH_SIZE = 100.freeze
def perform def perform
return unless Gitlab::Geo.configured?
return unless Gitlab::Geo.primary_node.present? return unless Gitlab::Geo.primary_node.present?
start_time = Time.now start_time = Time.now
......
...@@ -22,6 +22,7 @@ class GeoFileDownloadDispatchWorker ...@@ -22,6 +22,7 @@ class GeoFileDownloadDispatchWorker
# files, excluding ones in progress. # files, excluding ones in progress.
# 5. Quit when we have scheduled all downloads or exceeded an hour. # 5. Quit when we have scheduled all downloads or exceeded an hour.
def perform def perform
return unless Gitlab::Geo.configured?
return unless Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
@start_time = Time.now @start_time = Time.now
......
...@@ -29,6 +29,10 @@ module Gitlab ...@@ -29,6 +29,10 @@ module Gitlab
Gitlab::Geo.current_node.reload.enabled? Gitlab::Geo.current_node.reload.enabled?
end end
def self.configured?
Rails.configuration.respond_to?(:geo_database)
end
def self.license_allows? def self.license_allows?
::License.current && ::License.current.add_on?('GitLab_Geo') ::License.current && ::License.current.add_on?('GitLab_Geo')
end end
......
...@@ -3,6 +3,7 @@ module Gitlab ...@@ -3,6 +3,7 @@ module Gitlab
class HealthCheck class HealthCheck
def self.perform_checks def self.perform_checks
return '' unless Gitlab::Geo.secondary? return '' unless Gitlab::Geo.secondary?
return 'The Geo database configuration file is missing.' unless Gitlab::Geo.configured?
database_version = self.get_database_version.to_i database_version = self.get_database_version.to_i
migration_version = self.get_migration_version.to_i migration_version = self.get_migration_version.to_i
......
require 'spec_helper'
describe Gitlab::Geo::HealthCheck do
let!(:secondary) { create(:geo_node, :current) }
subject { described_class }
describe '.perform_checks' do
it 'returns an empty string when not running on a secondary node' do
allow(Gitlab::Geo).to receive(:secondary?) { false }
expect(subject.perform_checks).to be_blank
end
it 'returns an error when configuration file is missing for tracking DB' do
allow(Rails.configuration).to receive(:respond_to?).with(:geo_database) { false }
expect(subject.perform_checks).not_to be_blank
end
it 'returns an error when Geo database version does not match the latest migration version' do
allow(subject).to receive(:get_database_version) { 1 }
expect(subject.perform_checks).not_to be_blank
end
it 'returns an error when latest migration version does not match the Geo database version' do
allow(subject).to receive(:get_migration_version) { 1 }
expect(subject.perform_checks).not_to be_blank
end
end
end
...@@ -18,6 +18,22 @@ describe Geo::GeoBackfillWorker, services: true do ...@@ -18,6 +18,22 @@ describe Geo::GeoBackfillWorker, services: true do
subject.perform subject.perform
end end
it 'does not perform Geo::RepositoryBackfillService when tracking DB is not available' do
allow(Rails.configuration).to receive(:respond_to?).with(:geo_database) { false }
expect(Geo::RepositoryBackfillService).not_to receive(:new)
subject.perform
end
it 'does not perform Geo::RepositoryBackfillService when primary node does not exists' do
allow(Gitlab::Geo).to receive(:primary_node) { nil }
expect(Geo::RepositoryBackfillService).not_to receive(:new)
subject.perform
end
it 'does not perform Geo::RepositoryBackfillService when node is disabled' do it 'does not perform Geo::RepositoryBackfillService when node is disabled' do
allow_any_instance_of(GeoNode).to receive(:enabled?) { false } allow_any_instance_of(GeoNode).to receive(:enabled?) { false }
......
...@@ -13,12 +13,24 @@ describe GeoFileDownloadDispatchWorker do ...@@ -13,12 +13,24 @@ describe GeoFileDownloadDispatchWorker do
subject { described_class.new } subject { described_class.new }
describe '#perform' do describe '#perform' do
it 'does not schedule anything when node is disabled' do it 'does not schedule anything when tracking DB is not available' do
create(:lfs_object, :with_file)
allow(Rails.configuration).to receive(:respond_to?).with(:geo_database) { false }
expect(GeoFileDownloadWorker).not_to receive(:perform_async) expect(GeoFileDownloadWorker).not_to receive(:perform_async)
subject.perform
end
it 'does not schedule anything when node is disabled' do
create(:lfs_object, :with_file)
@secondary.enabled = false @secondary.enabled = false
@secondary.save @secondary.save
expect(GeoFileDownloadWorker).not_to receive(:perform_async)
subject.perform subject.perform
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