Skip to content
代码片段 群组 项目
提交 2138863b 编辑于 作者: Simon Tomlinson's avatar Simon Tomlinson
浏览文件

Fix ActiveRecord::Base accesses in geo files

Geo does not yet support syncing both primary and ci databases, so all
accesses here refer to the primary database.
上级 0cc6a229
No related branches found
No related tags found
无相关合并请求
--- ---
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 @@ def set_primary_geo_node ...@@ -18,7 +18,7 @@ def set_primary_geo_node
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 @@ def perform_checks ...@@ -19,8 +19,9 @@ def perform_checks
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 @@ def database_version ...@@ -71,7 +72,7 @@ def database_version
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 @@ def archive_recovery_replication_enabled? ...@@ -107,7 +108,7 @@ def archive_recovery_replication_enabled?
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 @@ def streaming_replication_enabled? ...@@ -115,7 +116,7 @@ def streaming_replication_enabled?
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 @@ def some_replication_active? ...@@ -123,7 +124,7 @@ def some_replication_active?
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 @@ def find_and_handle_events! ...@@ -47,7 +47,7 @@ def find_and_handle_events!
# 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?
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册