Class: Mammoth::Sources::PostgresSlotHealth

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/sources/postgres_slot_health.rb

Overview

Immutable operator-facing health snapshot for one PostgreSQL replication slot.

This is a Mammoth-owned policy view. The transport layer supplies catalog facts; Mammoth decides whether they make the configured source ready for continuous delivery. Typed PostgreSQL slot health and readiness policy.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slot_name:, present:, active:, retained_wal_bytes:, wal_status:, safe_wal_size:, inactive_since:, invalidation_reason:, restart_lsn:, restart_lsn_bytes:, confirmed_flush_lsn:, confirmed_flush_lsn_bytes:, conflicting:) ⇒ void

Build a PostgreSQL slot health snapshot from normalized catalog facts.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 19

def initialize(slot_name:, present:, active:, retained_wal_bytes:, wal_status:, safe_wal_size:, inactive_since:,
               invalidation_reason:, restart_lsn:, restart_lsn_bytes:, confirmed_flush_lsn:,
               confirmed_flush_lsn_bytes:, conflicting:)
  @slot_name = slot_name
  @present = present
  @active = active
  @retained_wal_bytes = retained_wal_bytes
  @wal_status = wal_status
  @safe_wal_size = safe_wal_size
  @inactive_since = inactive_since
  @invalidation_reason = invalidation_reason
  @restart_lsn = restart_lsn
  @restart_lsn_bytes = restart_lsn_bytes
  @confirmed_flush_lsn = confirmed_flush_lsn
  @confirmed_flush_lsn_bytes = confirmed_flush_lsn_bytes
  @conflicting = conflicting
  freeze
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def active
  @active
end

#confirmed_flush_lsnObject (readonly)

Returns the value of attribute confirmed_flush_lsn.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def confirmed_flush_lsn
  @confirmed_flush_lsn
end

#confirmed_flush_lsn_bytesObject (readonly)

Returns the value of attribute confirmed_flush_lsn_bytes.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def confirmed_flush_lsn_bytes
  @confirmed_flush_lsn_bytes
end

#conflictingObject (readonly)

Returns the value of attribute conflicting.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def conflicting
  @conflicting
end

#inactive_sinceObject (readonly)

Returns the value of attribute inactive_since.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def inactive_since
  @inactive_since
end

#invalidation_reasonObject (readonly)

Returns the value of attribute invalidation_reason.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def invalidation_reason
  @invalidation_reason
end

#presentObject (readonly)

Returns the value of attribute present.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def present
  @present
end

#restart_lsnObject (readonly)

Returns the value of attribute restart_lsn.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def restart_lsn
  @restart_lsn
end

#restart_lsn_bytesObject (readonly)

Returns the value of attribute restart_lsn_bytes.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def restart_lsn_bytes
  @restart_lsn_bytes
end

#retained_wal_bytesObject (readonly)

Returns the value of attribute retained_wal_bytes.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def retained_wal_bytes
  @retained_wal_bytes
end

#safe_wal_sizeObject (readonly)

Returns the value of attribute safe_wal_size.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def safe_wal_size
  @safe_wal_size
end

#slot_nameObject (readonly)

Returns the value of attribute slot_name.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def slot_name
  @slot_name
end

#wal_statusObject (readonly)

Returns the value of attribute wal_status.



12
13
14
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 12

def wal_status
  @wal_status
end

Class Method Details

.missing(slot_name) ⇒ PostgresSlotHealth

Build a snapshot for a missing configured slot.

Parameters:

  • slot_name (String)

    configured replication slot

Returns:



42
43
44
45
46
47
48
49
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 42

def self.missing(slot_name)
  new(
    slot_name:, present: false, active: false, retained_wal_bytes: nil,
    wal_status: nil, safe_wal_size: nil, inactive_since: nil,
    invalidation_reason: nil, restart_lsn: nil, restart_lsn_bytes: nil,
    confirmed_flush_lsn: nil, confirmed_flush_lsn_bytes: nil, conflicting: false
  )
end

Instance Method Details

#ready?Boolean

Whether the slot is present, active, and retaining usable WAL.

Returns:

  • (Boolean)


54
55
56
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 54

def ready?
  reason.nil?
end

#reasonString?

Operator-facing reason the slot is not ready.

Returns:

  • (String, nil)


61
62
63
64
65
66
67
68
69
70
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 61

def reason
  return "slot is missing" unless present
  return "slot is inactive" unless active
  return "wal_status=#{wal_status}" if %w[lost unreserved].include?(wal_status)
  return "slot is invalidated: #{invalidation_reason}" unless blank?(invalidation_reason)
  return "slot is conflicting" if conflicting
  return "slot has no restart LSN" if blank?(restart_lsn)

  nil
end

#summaryHash

Stable readiness payload without transport-library types.

Returns:

  • (Hash)


75
76
77
78
79
80
81
# File 'lib/mammoth/sources/postgres_slot_health.rb', line 75

def summary
  {
    slot_name:, present:, active:, retained_wal_bytes:, wal_status:, safe_wal_size:, inactive_since:,
    invalidation_reason:, restart_lsn:, restart_lsn_bytes:, confirmed_flush_lsn:,
    confirmed_flush_lsn_bytes:, conflicting:, ready: ready?, reason:
  }
end