Commit 2e216638 authored by Andreas Brandl's avatar Andreas Brandl

Cleanup checks for replication slot in Geo

This removes checking for the presence of PG
replication slots. This is not necessary anymore since that has been
supported since PG 9.4 and we're on >= PG11 now.
parent 5bca4b28
...@@ -300,19 +300,19 @@ class GeoNode < ApplicationRecord ...@@ -300,19 +300,19 @@ class GeoNode < ApplicationRecord
end end
def replication_slots_count def replication_slots_count
return unless Gitlab::Database.replication_slots_supported? && primary? return unless primary?
PgReplicationSlot.count PgReplicationSlot.count
end end
def replication_slots_used_count def replication_slots_used_count
return unless Gitlab::Database.replication_slots_supported? && primary? return unless primary?
PgReplicationSlot.used_slots_count PgReplicationSlot.used_slots_count
end end
def replication_slots_max_retained_wal_bytes def replication_slots_max_retained_wal_bytes
return unless Gitlab::Database.replication_slots_supported? && primary? return unless primary?
PgReplicationSlot.max_retained_wal PgReplicationSlot.max_retained_wal
end end
......
...@@ -3,52 +3,48 @@ ...@@ -3,52 +3,48 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe PgReplicationSlot do RSpec.describe PgReplicationSlot do
if Gitlab::Database.replication_slots_supported? it '#max_replication_slots' do
describe 'with replication slot support' do expect(described_class.max_replication_slots).to be >= 0
it '#max_replication_slots' do end
expect(described_class.max_replication_slots).to be >= 0
end skip_examples = described_class.max_replication_slots <= described_class.count
context 'with enough slots available' do
before(:all) do
skip('max_replication_slots too small') if skip_examples
@current_slot_count =
ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM pg_replication_slots;")
.first.fetch('count').to_i
@current_unused_count =
ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM pg_replication_slots WHERE active = 'f';")
.first.fetch('count').to_i
skip_examples = described_class.max_replication_slots <= described_class.count ActiveRecord::Base.connection.execute("SELECT * FROM pg_create_physical_replication_slot('test_slot');")
context 'with enough slots available' do end
before(:all) do
skip('max_replication_slots too small') if skip_examples after(:all) do
unless skip_examples
@current_slot_count = ActiveRecord::Base.connection.execute("SELECT pg_drop_replication_slot('test_slot');")
ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM pg_replication_slots;")
.first.fetch('count').to_i
@current_unused_count =
ActiveRecord::Base.connection.execute("SELECT COUNT(*) FROM pg_replication_slots WHERE active = 'f';")
.first.fetch('count').to_i
ActiveRecord::Base.connection.execute("SELECT * FROM pg_create_physical_replication_slot('test_slot');")
end
after(:all) do
unless skip_examples
ActiveRecord::Base.connection.execute("SELECT pg_drop_replication_slot('test_slot');")
end
end
it '#slots_count' do
expect(described_class.count).to eq(@current_slot_count + 1)
end
it '#unused_slots_count' do
expect(described_class.unused_slots_count).to eq(@current_unused_count + 1)
end
it '#max_retained_wal' do
expect(described_class.max_retained_wal).not_to be_nil
end
it '#slots_retained_bytes' do
slot = described_class.slots_retained_bytes.find {|x| x['slot_name'] == 'test_slot' }
expect(slot).not_to be_nil
expect(slot['retained_bytes']).to be_nil
end
end end
end end
it '#slots_count' do
expect(described_class.count).to eq(@current_slot_count + 1)
end
it '#unused_slots_count' do
expect(described_class.unused_slots_count).to eq(@current_unused_count + 1)
end
it '#max_retained_wal' do
expect(described_class.max_retained_wal).not_to be_nil
end
it '#slots_retained_bytes' do
slot = described_class.slots_retained_bytes.find {|x| x['slot_name'] == 'test_slot' }
expect(slot).not_to be_nil
expect(slot['retained_bytes']).to be_nil
end
end end
end end
...@@ -99,10 +99,6 @@ module Gitlab ...@@ -99,10 +99,6 @@ module Gitlab
version.to_f < 10 version.to_f < 10
end end
def self.replication_slots_supported?
version.to_f >= 9.4
end
def self.postgresql_minimum_supported_version? def self.postgresql_minimum_supported_version?
version.to_f >= MINIMUM_POSTGRES_VERSION version.to_f >= MINIMUM_POSTGRES_VERSION
end end
......
...@@ -156,20 +156,6 @@ RSpec.describe Gitlab::Database do ...@@ -156,20 +156,6 @@ RSpec.describe Gitlab::Database do
end end
end end
describe '.replication_slots_supported?' do
it 'returns false when using PostgreSQL 9.3' do
allow(described_class).to receive(:version).and_return('9.3.1')
expect(described_class.replication_slots_supported?).to eq(false)
end
it 'returns true when using PostgreSQL 9.4.0 or newer' do
allow(described_class).to receive(:version).and_return('9.4.0')
expect(described_class.replication_slots_supported?).to eq(true)
end
end
describe '.pg_wal_lsn_diff' do describe '.pg_wal_lsn_diff' do
it 'returns old name when using PostgreSQL 9.6' do it 'returns old name when using PostgreSQL 9.6' do
allow(described_class).to receive(:version).and_return('9.6') allow(described_class).to receive(:version).and_return('9.6')
......
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