Commit 333196f4 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'fix-geo-activerecord-base' into 'master'

Fix ActiveRecord::Base accesses in geo files

See merge request gitlab-org/gitlab!82226
parents 71c9c7f8 2138863b
--- ---
Database/MultipleDatabases: Database/MultipleDatabases:
Exclude: Exclude:
- ee/lib/gitlab/geo/database_tasks.rb
- ee/lib/gitlab/geo/geo_tasks.rb
- ee/lib/gitlab/geo/health_check.rb
- ee/lib/gitlab/geo/log_cursor/daemon.rb
- ee/spec/services/ee/merge_requests/update_service_spec.rb - ee/spec/services/ee/merge_requests/update_service_spec.rb
- lib/backup/database.rb - lib/backup/database.rb
- lib/backup/manager.rb - lib/backup/manager.rb
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
end end
def set_secondary_as_primary def set_secondary_as_primary
ActiveRecord::Base.transaction do GeoNode.transaction do
primary_node = GeoNode.primary_node primary_node = GeoNode.primary_node
current_node = GeoNode.current_node current_node = GeoNode.current_node
......
...@@ -19,8 +19,9 @@ module Gitlab ...@@ -19,8 +19,9 @@ module Gitlab
end end
def db_replication_lag_seconds def db_replication_lag_seconds
# Geo currently only replicates the primary database (not the ci database)
# Obtain the replication lag in seconds # Obtain the replication lag in seconds
ActiveRecord::Base.connection ApplicationRecord.connection
.execute(db_replication_lag_seconds_query) .execute(db_replication_lag_seconds_query)
.first .first
.fetch('replication_lag').to_i .fetch('replication_lag').to_i
...@@ -71,7 +72,7 @@ module Gitlab ...@@ -71,7 +72,7 @@ module Gitlab
strong_memoize(:database_version) do strong_memoize(:database_version) do
if defined?(ActiveRecord) if defined?(ActiveRecord)
connection = ::Geo::BaseRegistry.connection connection = ::Geo::BaseRegistry.connection
schema_migrations_table_name = ActiveRecord::Base.schema_migrations_table_name schema_migrations_table_name = ApplicationRecord.schema_migrations_table_name
if connection.table_exists?(schema_migrations_table_name) if connection.table_exists?(schema_migrations_table_name)
connection.execute("SELECT MAX(version) AS version FROM #{schema_migrations_table_name}") connection.execute("SELECT MAX(version) AS version FROM #{schema_migrations_table_name}")
...@@ -107,7 +108,7 @@ module Gitlab ...@@ -107,7 +108,7 @@ module Gitlab
end end
def streaming_replication_enabled? def streaming_replication_enabled?
!ActiveRecord::Base.connection !ApplicationRecord.connection
.execute("SELECT * FROM pg_last_wal_receive_lsn() as result") .execute("SELECT * FROM pg_last_wal_receive_lsn() as result")
.first['result'] .first['result']
.nil? .nil?
...@@ -115,7 +116,7 @@ module Gitlab ...@@ -115,7 +116,7 @@ module Gitlab
def some_replication_active? def some_replication_active?
# Is some sort of replication active? # Is some sort of replication active?
!ActiveRecord::Base.connection !ApplicationRecord.connection
.execute("SELECT * FROM pg_last_xact_replay_timestamp() as result") .execute("SELECT * FROM pg_last_xact_replay_timestamp() as result")
.first['result'] .first['result']
.nil? .nil?
...@@ -123,7 +124,7 @@ module Gitlab ...@@ -123,7 +124,7 @@ module Gitlab
def streaming_replication_active? def streaming_replication_active?
# This only works for Postgresql 9.6 and greater # This only works for Postgresql 9.6 and greater
ActiveRecord::Base.connection ApplicationRecord.connection
.select_values('SELECT pid FROM pg_stat_wal_receiver').first.to_i > 0 .select_values('SELECT pid FROM pg_stat_wal_receiver').first.to_i > 0
end end
end end
......
...@@ -47,7 +47,7 @@ module Gitlab ...@@ -47,7 +47,7 @@ module Gitlab
# Wrap this with the connection to make it possible to reconnect if # Wrap this with the connection to make it possible to reconnect if
# PGbouncer dies: https://github.com/rails/rails/issues/29189 # PGbouncer dies: https://github.com/rails/rails/issues/29189
ActiveRecord::Base.connection_pool.with_connection do ::Geo::EventLog.connection_pool.with_connection do
LogCursor::EventLogs.new.fetch_in_batches do |batch, last_id| LogCursor::EventLogs.new.fetch_in_batches do |batch, last_id|
break if exit? break if exit?
......
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