Electric.Timeline (electric v1.0.17)

View Source

Module exporting functions for handling Postgres timelines. Verifies the Postgres ID and its timeline.

Summary

Functions

Checks that we're connected to the same Postgres DB as before and on the same timeline. TO this end, it checks the provided pg_id against the persisted PG ID. If the PG IDs match, it also checks the provided pg_timeline against the persisted timeline. Normally, Postgres and Electric are on the same timeline and nothing must be done. If the timelines differ, that indicates that a Point In Time Recovery (PITR) has occurred and all shapes must be cleaned. If we fail to fetch timeline information, we also clean all shapes for safety as we can't be sure that Postgres and Electric are on the same timeline.

Stores a timeline that is irrecoverable.

Types

check_result()

@type check_result() :: :ok | :timeline_changed

pg_id()

@type pg_id() :: non_neg_integer()

timeline()

@type timeline() :: {pg_id(), timeline_id()} | nil

timeline_id()

@type timeline_id() :: integer()

Functions

check(pg_timeline, opts)

@spec check(
  timeline(),
  keyword()
) :: check_result()

Checks that we're connected to the same Postgres DB as before and on the same timeline. TO this end, it checks the provided pg_id against the persisted PG ID. If the PG IDs match, it also checks the provided pg_timeline against the persisted timeline. Normally, Postgres and Electric are on the same timeline and nothing must be done. If the timelines differ, that indicates that a Point In Time Recovery (PITR) has occurred and all shapes must be cleaned. If we fail to fetch timeline information, we also clean all shapes for safety as we can't be sure that Postgres and Electric are on the same timeline.

load_timeline(opts)

@spec load_timeline(Keyword.t()) :: timeline()

store_irrecoverable_timeline(pg_id, opts)

@spec store_irrecoverable_timeline(pg_id(), Keyword.t()) :: :ok

Stores a timeline that is irrecoverable.

We use the fact that timelines are positive to store a special timeline that's guaranteed to not match thus ensuring shape cleanup.

store_timeline(arg, opts)

@spec store_timeline(timeline(), Keyword.t()) :: :ok