Fly.Postgres.LSN.Tracker (Fly Postgres v0.2.2) View Source

Track the current PostgreSQL LSN or Log Sequence Number.

This is used to determine which portions of the database log have been replicated locally. This lets us determine if a specific transaction chunk has been replicated to know that some expected data is present.

The client process doesn't interact directly with the Tracker GenServer. The client can request_notification or request_and_await_notification and the Tracker will notify the process when the data replication has been seen.

Link to this section Summary

Functions

Blocking function that waits for a request_notification/2 response message to be received. The timeout defaults to 5s after which time it stops waiting and returns an {:error, :timeout} response.

Returns a specification to start this module under a supervisor.

Get the latest cached LSN replay value.

Get the Ecto.Repo used by the tracker.

Callback implementation for GenServer.init/1.

Return if the LSN value was replicated.

Request to be notified when the desired level of data replication has completed and wait for it to complete. Optionally it may timeout if it takes too long.

Request notification for when the database replication includes the LSN the process cares about. This allows a process to block and await their data to be replicated and be notified as soon as it's detected.

Start the Tracker that receives work requests.

Link to this section Functions

Link to this function

await_notification(lsn, opts \\ [])

View Source

Specs

await_notification(Fly.Postgres.LSN.t(), opts :: keyword()) ::
  :ready | {:error, :timeout}

Blocking function that waits for a request_notification/2 response message to be received. The timeout defaults to 5s after which time it stops waiting and returns an {:error, :timeout} response.

Options

  • :replication_timeout - Timeout duration to wait for replication to complete.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

get_last_replay(opts \\ [])

View Source

Specs

get_last_replay(opts :: keyword()) :: nil | Fly.Postgres.LSN.t()

Get the latest cached LSN replay value.

Options

  • :tracker - The tracker name to get the latest LSN replay value for. Uses the default tracker name. Needs to be provided when multiple trackers are used.

Specs

get_repo(opts :: keyword()) :: nil | module()

Get the Ecto.Repo used by the tracker.

Options

  • :tracker - The tracker name to get the latest LSN replay value for. Uses the default tracker name. Needs to be provided when multiple trackers are used.
Link to this function

get_table_name(base_table_name, opts \\ [])

View Source
Link to this function

handle_continue(atom, state)

View Source

Callback implementation for GenServer.handle_continue/2.

Callback implementation for GenServer.init/1.

Link to this function

replicated?(lsn, opts \\ [])

View Source

Specs

replicated?(Fly.Postgres.LSN.t(), opts :: keyword()) :: boolean()

Return if the LSN value was replicated.

Link to this function

request_and_await_notification(lsn, opts \\ [])

View Source

Specs

request_and_await_notification(Fly.Postgres.LSN.t(), opts :: keyword()) ::
  :ready | {:error, :timeout}

Request to be notified when the desired level of data replication has completed and wait for it to complete. Optionally it may timeout if it takes too long.

Options

  • :tracker - The name of the tracker to wait on for replication tracking.
  • :replication_timeout - Timeout duration to wait for replication to complete.
Link to this function

request_notification(lsn, opts \\ [])

View Source

Specs

request_notification(Fly.Postgres.LSN.t(), opts :: keyword()) :: :ok

Request notification for when the database replication includes the LSN the process cares about. This allows a process to block and await their data to be replicated and be notified as soon as it's detected.

Start the Tracker that receives work requests.