Class: Gitlab::Database::HealthStatus::Indicators::WriteAheadLog

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/database/health_status/indicators/write_ahead_log.rb

Constant Summary collapse

LIMIT =
42
PENDING_WAL_COUNT_SQL =
<<~SQL
  WITH
  current_wal_file AS (
    SELECT pg_walfile_name(pg_current_wal_insert_lsn()) AS pg_walfile_name
  ),
  current_wal AS (
    SELECT
      ('x' || substring(pg_walfile_name, 9, 8))::bit(32)::int AS log,
      ('x' || substring(pg_walfile_name, 17, 8))::bit(32)::int AS seg,
      pg_walfile_name
    FROM current_wal_file
  ),
  archive_wal AS (
    SELECT
      ('x' || substring(last_archived_wal, 9, 8))::bit(32)::int AS log,
      ('x' || substring(last_archived_wal, 17, 8))::bit(32)::int AS seg,
      last_archived_wal
    FROM pg_stat_archiver
  )
  SELECT ((current_wal.log - archive_wal.log) * 256) + (current_wal.seg - archive_wal.seg) AS pending_wal_count
  FROM current_wal, archive_wal
SQL

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ WriteAheadLog

Returns a new instance of WriteAheadLog.



34
35
36
# File 'lib/gitlab/database/health_status/indicators/write_ahead_log.rb', line 34

def initialize(context)
  @connection = context.connection
end

Instance Method Details

#evaluateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gitlab/database/health_status/indicators/write_ahead_log.rb', line 38

def evaluate
  return Signals::NotAvailable.new(self.class, reason: 'indicator disabled') unless enabled?

  unless pending_wal_count
    return Signals::NotAvailable.new(self.class, reason: 'WAL archive queue can not be calculated')
  end

  if pending_wal_count > LIMIT
    Signals::Stop.new(self.class, reason: "WAL archive queue is too big")
  else
    Signals::Normal.new(self.class, reason: 'WAL archive queue is within limit')
  end
end