Load Geo DB only when Geo is enabled, and only if it is a secondary node

parent 9cfd10dd
class Geo::BaseRegistry < ActiveRecord::Base
self.abstract_class = true
establish_connection Rails.configuration.geo_database
if Gitlab::Geo.secondary?
establish_connection Rails.configuration.geo_database
end
end
......@@ -158,5 +158,8 @@ module Gitlab
config.generators do |g|
g.factory_girl false
end
# This is needed for GitLab Geo
config.assets.initialize_on_precompile = false
end
end
Rails.application.configure do
config.geo_database = config_for(:database_geo)
if Gitlab::Geo.secondary?
Rails.application.configure do
config.geo_database = config_for(:database_geo)
end
end
......@@ -2,7 +2,9 @@ HealthCheck.setup do |config|
config.standard_checks = %w(database migrations cache)
config.full_checks = %w(database migrations cache)
config.add_custom_check('geo') do
Gitlab::Geo::HealthCheck.perform_checks
if Gitlab::Geo.secondary?
config.add_custom_check('geo') do
Gitlab::Geo::HealthCheck.perform_checks
end
end
end
......@@ -19,7 +19,7 @@ module Gitlab
end
def self.enabled?
self.cache_value(:geo_node_enabled) { GeoNode.exists? }
self.cache_value(:geo_node_enabled) { self.connected_to_primary_db? && GeoNode.exists? }
end
def self.license_allows?
......@@ -31,7 +31,7 @@ module Gitlab
end
def self.secondary?
self.cache_value(:geo_node_secondary) { self.enabled? && self.current_node && !self.current_node.primary? }
self.cache_value(:geo_node_secondary) { self.enabled? && self.current_node && self.current_node.secondary? }
end
def self.primary_ssh_path_prefix
......@@ -80,5 +80,10 @@ module Gitlab
# urlsafe_base64 may return a string of size * 4/3
SecureRandom.urlsafe_base64(size)[0, size]
end
def self.connected_to_primary_db?
ActiveRecord::Base.connection.active? &&
ActiveRecord::Base.connection.table_exists?(GeoNode.table_name)
end
end
end
......@@ -24,13 +24,19 @@ namespace :geo do
# append and prepend proper tasks to all the tasks defined above
ns.tasks.each do |task|
task.enhance ['geo:config:set'] do
task.enhance ['geo:config:check', 'geo:config:set'] do
Rake::Task['geo:config:restore'].invoke
end
end
end
namespace :config do
task :check do
unless File.exist?(Rails.root.join('config/database_geo.yml'))
abort('You should run these tasks only when GitLab Geo is enabled, and only if it is a secondary node')
end
end
task :set do
# save current configuration
@previous_config = {
......
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