diff --git a/.rubocop_todo/database/multiple_databases.yml b/.rubocop_todo/database/multiple_databases.yml index 8364ee2af7fa845c26ccbdfa32724b67f246a140..27e28128a98693c5e71dc3572e85666a6787b634 100644 --- a/.rubocop_todo/database/multiple_databases.yml +++ b/.rubocop_todo/database/multiple_databases.yml @@ -1,10 +1,6 @@ --- Database/MultipleDatabases: 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 - lib/backup/database.rb - lib/backup/manager.rb diff --git a/ee/lib/gitlab/geo/geo_tasks.rb b/ee/lib/gitlab/geo/geo_tasks.rb index 7b41cb8b501e808c4920eb798fd55c84bac2b17e..3e6cd99d87264ce5142ec3a91c694dd456cea08f 100644 --- a/ee/lib/gitlab/geo/geo_tasks.rb +++ b/ee/lib/gitlab/geo/geo_tasks.rb @@ -18,7 +18,7 @@ def set_primary_geo_node end def set_secondary_as_primary - ActiveRecord::Base.transaction do + GeoNode.transaction do primary_node = GeoNode.primary_node current_node = GeoNode.current_node diff --git a/ee/lib/gitlab/geo/health_check.rb b/ee/lib/gitlab/geo/health_check.rb index 8fa4159243b4e981c0e8fb5829c7c58a126860e4..0b5cdbab6e9a8cc626c3853975fee0b14bfcd149 100644 --- a/ee/lib/gitlab/geo/health_check.rb +++ b/ee/lib/gitlab/geo/health_check.rb @@ -19,8 +19,9 @@ def perform_checks end def db_replication_lag_seconds + # Geo currently only replicates the primary database (not the ci database) # Obtain the replication lag in seconds - ActiveRecord::Base.connection + ApplicationRecord.connection .execute(db_replication_lag_seconds_query) .first .fetch('replication_lag').to_i @@ -71,7 +72,7 @@ def database_version strong_memoize(:database_version) do if defined?(ActiveRecord) 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) connection.execute("SELECT MAX(version) AS version FROM #{schema_migrations_table_name}") @@ -107,7 +108,7 @@ def archive_recovery_replication_enabled? end def streaming_replication_enabled? - !ActiveRecord::Base.connection + !ApplicationRecord.connection .execute("SELECT * FROM pg_last_wal_receive_lsn() as result") .first['result'] .nil? @@ -115,7 +116,7 @@ def streaming_replication_enabled? def some_replication_active? # Is some sort of replication active? - !ActiveRecord::Base.connection + !ApplicationRecord.connection .execute("SELECT * FROM pg_last_xact_replay_timestamp() as result") .first['result'] .nil? @@ -123,7 +124,7 @@ def some_replication_active? def streaming_replication_active? # 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 end end diff --git a/ee/lib/gitlab/geo/log_cursor/daemon.rb b/ee/lib/gitlab/geo/log_cursor/daemon.rb index c9b07caa94fe92c595e776d1ad4968ef1ae61ea6..09e8a94b1abd39f5c604b7c9ceb44609dc1dc2ae 100644 --- a/ee/lib/gitlab/geo/log_cursor/daemon.rb +++ b/ee/lib/gitlab/geo/log_cursor/daemon.rb @@ -47,7 +47,7 @@ def find_and_handle_events! # Wrap this with the connection to make it possible to reconnect if # 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| break if exit?