AuroraMeter.Storage.Ecto (Aurora Meter v1.0.0)

View Source

Internal. Not part of the supported API (see API inventory). It may change in any release, including a patch.

Default AuroraMeter.Storage adapter, backed by the host's Ecto repo (AuroraMeter.Config.repo/0). Counter and event writes use insert_all for throughput. Flushes add deltas in a transaction with a unique batch receipt, so retrying an uncertain commit cannot duplicate usage.

Summary

Functions

Whether this call is already inside a transaction the host opened.

The most rows of schema one insert_all/3 statement can carry.

The generation that holds the frozen copy of the active generation taken when building was announced.

Functions

host_transaction?()

@spec host_transaction?() :: boolean()

Whether this call is already inside a transaction the host opened.

It is repo.in_transaction?/0, which reads the Ecto-side connection this process holds: Ecto.Adapters.SQL's implementation matches on a conn_mode: :transaction connection in the process dictionary, and the sandbox's own BEGIN is issued inside the connection process rather than through it. The value is measured rather than assumed in docs/evidence/v1/phase-03/03b-in-transaction.md, including under Ecto.Adapters.SQL.Sandbox, because the correct implementation depends on an observable fact about ecto_sql and not on a reading of its documentation.

rows_per_statement(schema)

@spec rows_per_statement(module()) :: pos_integer()

The most rows of schema one insert_all/3 statement can carry.

Derived from the schema, because Postgres's 65,535 bind-parameter ceiling is per statement and insert_all/3 spends one parameter per column per row (open-findings.md X338). Public so that a test can flush one row more than this against a real database rather than trusting the arithmetic.

Examples

iex> AuroraMeter.Storage.Ecto.rows_per_statement(AuroraMeter.Schema.Counter)
9362

seed_generation(building)

@spec seed_generation(pos_integer()) :: neg_integer()

The generation that holds the frozen copy of the active generation taken when building was announced.

Negative, so it cannot collide with any generation a replay will ever build and an operator reading the table can see at a glance which rows are the seed for which build.

Examples

iex> AuroraMeter.Storage.Ecto.seed_generation(3)
-3