Commit e51d78bf authored by Yorick Peterse's avatar Yorick Peterse

Remove Database::Connection.healthy?

This method was added using an EE only method, and just inverted the
result of Postgresql::ReplicationSlot. This however creates a problem: a
Connection is tied to a specific database connection, but
ReplicationSlot is tied to the main database.

When we add support for multiple databases to ReplicationSlot, we'd
somehow have to figure out what model to use for the `healthy?` class,
as there would a ReplicationSlot model per primary database. Instead of
trying to work this out, which likely would get hairy, we simply remove
the `healthy?` method in favour of using ReplicationSlot directly. It
was only used in one place anyway, ant there is no harm in using
ReplicationSlot directly in that instance.
parent 89aff662
......@@ -17,7 +17,7 @@ module Geo
def perform
return if Gitlab::Database.read_only?
return unless Gitlab::Database.main.healthy?
return if Postgresql::ReplicationSlot.lag_too_great?
unless ::GeoNode.secondary_nodes.any?
Geo::PruneEventLogService.new(:all).execute
......
......@@ -6,10 +6,6 @@ module EE
module Connection
extend ActiveSupport::Concern
def healthy?
!Postgresql::ReplicationSlot.lag_too_great?
end
def geo_uncached_queries(&block)
raise 'No block given' unless block_given?
......
......@@ -7,20 +7,6 @@ RSpec.describe Gitlab::Database::Connection do
let(:connection) { described_class.new }
describe '#healthy?' do
it 'returns true when replication lag is not too great' do
allow(Postgresql::ReplicationSlot).to receive(:lag_too_great?).and_return(false)
expect(connection.healthy?).to be_truthy
end
it 'returns false when replication lag is too great' do
allow(Postgresql::ReplicationSlot).to receive(:lag_too_great?).and_return(true)
expect(connection.healthy?).to be_falsey
end
end
describe '#geo_uncached_queries' do
context 'when no block is given' do
it 'raises error' do
......
......@@ -29,8 +29,11 @@ RSpec.describe Geo::PruneEventLogWorker, :geo do
end
it 'does nothing when database is not feeling healthy' do
allow(Gitlab::Database.main).to receive(:healthy?).and_return(false)
allow(Postgresql::ReplicationSlot)
.to receive(:lag_too_great?)
.and_return(true)
expect(GeoNode).not_to receive(:secondary_nodes)
expect(Geo::PruneEventLogService).not_to receive(:new)
worker.perform
......
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