Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-15 15:11:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-15 15:11:13 +0300
commitae27cd3c8824d0d7815ad9ba550ad249f7e298a6 (patch)
treeb926ecf47418ab28a6c9a70f2f20cfe14091ff58 /lib/gitlab/database.rb
parent33f96e8df089c2291010598c50ec6868ab8cb1ef (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database.rb')
-rw-r--r--lib/gitlab/database.rb30
1 files changed, 23 insertions, 7 deletions
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb
index f3f0d0305d3..385ac40cf13 100644
--- a/lib/gitlab/database.rb
+++ b/lib/gitlab/database.rb
@@ -198,14 +198,30 @@ module Gitlab
::ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).map(&:name)
end
- def self.db_config_name(ar_connection)
- if ar_connection.respond_to?(:pool) &&
- ar_connection.pool.respond_to?(:db_config) &&
- ar_connection.pool.db_config.respond_to?(:name)
- return ar_connection.pool.db_config.name
- end
+ def self.db_config_for_connection(connection)
+ return unless connection
+
+ # The LB connection proxy does not have a direct db_config
+ # that can be referenced
+ return if connection.is_a?(::Gitlab::Database::LoadBalancing::ConnectionProxy)
+
+ # During application init we might receive `NullPool`
+ return unless connection.respond_to?(:pool) &&
+ connection.pool.respond_to?(:db_config)
+
+ connection.pool.db_config
+ end
- 'unknown'
+ # At the moment, the connection can only be retrieved by
+ # Gitlab::Database::LoadBalancer#read or #read_write or from the
+ # ActiveRecord directly. Therefore, if the load balancer doesn't
+ # recognize the connection, this method returns the primary role
+ # directly. In future, we may need to check for other sources.
+ # Expected returned names:
+ # main, main_replica, ci, ci_replica, unknown
+ def self.db_config_name(connection)
+ db_config = db_config_for_connection(connection)
+ db_config&.name || 'unknown'
end
def self.read_only?