Commit 3eb57cec authored by Yorick Peterse's avatar Yorick Peterse

Merge branch 'sh-fix-issue-52176' into 'master'

Disable replication lag check for Aurora PostgreSQL databases

Closes #52176

See merge request gitlab-org/gitlab-ce!22786
parents a5fa8228 fd7f95ee
......@@ -4,6 +4,15 @@ module Postgresql
class ReplicationSlot < ActiveRecord::Base
self.table_name = 'pg_replication_slots'
# Returns true if there are any replication slots in use.
# PostgreSQL-compatible databases such as Aurora don't support
# replication slots, so this will return false as well.
def self.in_use?
transaction { exists? }
rescue ActiveRecord::StatementInvalid
false
end
# Returns true if the lag observed across all replication slots exceeds a
# given threshold.
#
......@@ -11,6 +20,8 @@ module Postgresql
# statistics it takes between 1 and 5 seconds to replicate around
# 100 MB of data.
def self.lag_too_great?(max = 100.megabytes)
return false unless in_use?
lag_function = "#{Gitlab::Database.pg_wal_lsn_diff}" \
"(#{Gitlab::Database.pg_current_wal_insert_lsn}(), restart_lsn)::bigint"
......
---
title: Disable replication lag check for Aurora PostgreSQL databases
merge_request: 22786
author:
type: fixed
......@@ -3,7 +3,27 @@
require 'spec_helper'
describe Postgresql::ReplicationSlot, :postgresql do
describe '.in_use?' do
it 'returns true when replication slots are present' do
expect(described_class).to receive(:exists?).and_return(true)
expect(described_class.in_use?).to be_truthy
end
it 'returns false when replication slots are not present' do
expect(described_class.in_use?).to be_falsey
end
it 'returns false if the existence check is invalid' do
expect(described_class).to receive(:exists?).and_raise(ActiveRecord::StatementInvalid.new('PG::FeatureNotSupported'))
expect(described_class.in_use?).to be_falsey
end
end
describe '.lag_too_great?' do
before do
expect(described_class).to receive(:in_use?).and_return(true)
end
it 'returns true when replication lag is too great' do
expect(described_class)
.to receive(:pluck)
......
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