Commit cd05d08e authored by Nick Thomas's avatar Nick Thomas

Merge branch...

Merge branch '10350-follow-up-from-geo-support-archive-recovery-or-streaming-replication-types' into 'master'

Geo: Support archive recovery or streaming replication types

Closes #10350

See merge request gitlab-org/gitlab-ee!10473
parents f36e9a5b 20795aec
...@@ -34,6 +34,16 @@ module Gitlab ...@@ -34,6 +34,16 @@ module Gitlab
.fetch('replication_lag').to_i .fetch('replication_lag').to_i
end end
def replication_enabled?
streaming_replication_enabled? || archive_recovery_replication_enabled?
end
def replication_working?
return streaming_replication_active? if streaming_replication_enabled?
some_replication_active?
end
private private
def db_replication_lag_seconds_query def db_replication_lag_seconds_query
...@@ -105,10 +115,6 @@ module Gitlab ...@@ -105,10 +115,6 @@ module Gitlab
gitlab_schema_tables_count == foreign_schema_tables_count gitlab_schema_tables_count == foreign_schema_tables_count
end end
def replication_enabled?
streaming_replication_enabled? || archive_recovery_replication_enabled?
end
def archive_recovery_replication_enabled? def archive_recovery_replication_enabled?
!streaming_replication_enabled? && some_replication_active? !streaming_replication_enabled? && some_replication_active?
end end
...@@ -133,12 +139,6 @@ module Gitlab ...@@ -133,12 +139,6 @@ module Gitlab
ActiveRecord::Base.connection ActiveRecord::Base.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
def replication_working?
return streaming_replication_active? if streaming_replication_enabled?
some_replication_active?
end
end end
end end
end end
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
module SystemCheck module SystemCheck
module Geo module Geo
class DatabaseReplicationCheck < SystemCheck::BaseCheck class DatabaseReplicationEnabledCheck < SystemCheck::BaseCheck
set_name 'Using database streaming replication?' set_name 'Database replication enabled?'
set_skip_reason 'not a secondary node' set_skip_reason 'not a secondary node'
def skip? def skip?
...@@ -11,16 +11,22 @@ module SystemCheck ...@@ -11,16 +11,22 @@ module SystemCheck
end end
def check? def check?
Gitlab::Database.db_read_only? geo_health_check.replication_enabled?
end end
def show_error def show_error
try_fixing_it( try_fixing_it(
'Follow Geo setup instructions to configure primary and secondary nodes for streaming replication' 'Follow Geo setup instructions to configure primary and secondary nodes for replication'
) )
for_more_information('doc/gitlab-geo/database.md') for_more_information('doc/gitlab-geo/database.md')
end end
private
def geo_health_check
@geo_health_check ||= Gitlab::Geo::HealthCheck.new
end
end end
end end
end end
# frozen_string_literal: true
module SystemCheck
module Geo
class DatabaseReplicationWorkingCheck < SystemCheck::BaseCheck
set_name 'Database replication working?'
set_skip_reason 'not a secondary node'
def skip?
!Gitlab::Geo.secondary?
end
def check?
geo_health_check.replication_enabled? && geo_health_check.replication_working?
end
def show_error
try_fixing_it(
'Follow Geo setup instructions to configure primary and secondary nodes for replication'
)
for_more_information('doc/gitlab-geo/database.md')
end
private
def geo_health_check
@geo_health_check ||= Gitlab::Geo::HealthCheck.new
end
end
end
end
...@@ -15,7 +15,8 @@ module SystemCheck ...@@ -15,7 +15,8 @@ module SystemCheck
SystemCheck::Geo::LicenseCheck, SystemCheck::Geo::LicenseCheck,
SystemCheck::Geo::EnabledCheck, SystemCheck::Geo::EnabledCheck,
SystemCheck::Geo::GeoDatabaseConfiguredCheck, SystemCheck::Geo::GeoDatabaseConfiguredCheck,
SystemCheck::Geo::DatabaseReplicationCheck, SystemCheck::Geo::DatabaseReplicationEnabledCheck,
SystemCheck::Geo::DatabaseReplicationWorkingCheck,
SystemCheck::Geo::FdwEnabledCheck, SystemCheck::Geo::FdwEnabledCheck,
SystemCheck::Geo::FdwSchemaUpToDateCheck, SystemCheck::Geo::FdwSchemaUpToDateCheck,
SystemCheck::Geo::HttpConnectionCheck, SystemCheck::Geo::HttpConnectionCheck,
......
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe Gitlab::Geo::HealthCheck, :geo do describe Gitlab::Geo::HealthCheck, :geo do
include ::EE::GeoHelpers include ::EE::GeoHelpers
using RSpec::Parameterized::TableSyntax
set(:secondary) { create(:geo_node) } set(:secondary) { create(:geo_node) }
...@@ -176,4 +177,44 @@ describe Gitlab::Geo::HealthCheck, :geo do ...@@ -176,4 +177,44 @@ describe Gitlab::Geo::HealthCheck, :geo do
end end
end end
end end
describe '#replication_enabled?' do
where(:streaming_replication_enabled, :archive_recovery_replication_enabled, :result) do
false | false | false
true | false | true
false | true | true
end
with_them do
before do
allow(subject).to receive(:streaming_replication_enabled?).and_return(streaming_replication_enabled)
allow(subject).to receive(:archive_recovery_replication_enabled?).and_return(archive_recovery_replication_enabled)
end
it 'returns the correct result' do
expect(subject.replication_enabled?).to eq(result)
end
end
end
describe '#replication_working?' do
where(:streaming_replication_enabled, :streaming_replication_active, :some_replication_active, :result) do
false | nil | false | false
false | nil | true | true
true | false | nil | false
true | true | nil | true
end
with_them do
before do
allow(subject).to receive(:streaming_replication_enabled?).and_return(streaming_replication_enabled)
allow(subject).to receive(:streaming_replication_active?).and_return(streaming_replication_active)
allow(subject).to receive(:some_replication_active?).and_return(some_replication_active)
end
it 'returns the correct result' do
expect(subject.replication_working?).to eq(result)
end
end
end
end end
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