diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-07-19 17:16:47 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-08-06 15:20:36 +0200 |
commit | 91b752dce63147bc99d7784d3d37865efb5e9352 (patch) | |
tree | 447dcd9dc5efcb14af5439f247d87938daf845dc /spec/models/postgresql | |
parent | 5f742eb95a0080343167469ccabfeccd3630007d (diff) | |
download | gitlab-ce-91b752dce63147bc99d7784d3d37865efb5e9352.tar.gz |
Respond to DB health in background migrations
This changes the BackgroundMigration worker so it checks for the health
of the DB before performing a background migration. This in turn allows
us to reduce the minimum interval, without having to worry about blowing
things up if we schedule too many migrations.
In this setup, the BackgroundMigration worker will reschedule jobs as
long as the database is considered to be in an unhealthy state. Once the
database has recovered, the migration can be performed.
To determine if the database is in a healthy state, we look at the
replication lag of any replication slots defined on the primary. If the
lag is deemed to great (100 MB by default) for too many slots, the
migration is rescheduled for a later point in time.
The health checking code is hidden behind a feature flag, allowing us to
disable it if necessary.
Diffstat (limited to 'spec/models/postgresql')
-rw-r--r-- | spec/models/postgresql/replication_slot_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/models/postgresql/replication_slot_spec.rb b/spec/models/postgresql/replication_slot_spec.rb new file mode 100644 index 00000000000..919a7526803 --- /dev/null +++ b/spec/models/postgresql/replication_slot_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Postgresql::ReplicationSlot, :postgresql do + describe '.lag_too_great?' do + it 'returns true when replication lag is too great' do + expect(described_class) + .to receive(:pluck) + .and_return([125.megabytes]) + + expect(described_class.lag_too_great?).to eq(true) + end + + it 'returns false when more than one replicas is up to date enough' do + expect(described_class) + .to receive(:pluck) + .and_return([125.megabytes, 0.megabytes, 0.megabytes]) + + expect(described_class.lag_too_great?).to eq(false) + end + + it 'returns false when replication lag is not too great' do + expect(described_class) + .to receive(:pluck) + .and_return([0.megabytes]) + + expect(described_class.lag_too_great?).to eq(false) + end + end +end |