View Source Electric.Replication.LogOffset (electric v0.9.5)
Uniquely identifies an operation inside the shape log. Combines a transaction ID with operation ID.
Summary
Functions
An offset that is smaller than all offsets in the log.
Compare two log offsets
The first possible offset in the log.
Parse the given string as a LogOffset value.
Increments the offset of the change inside the transaction.
The last possible offset in the log.
Create a new LogOffset value.
Format a LogOffset value to its text representation in an iolist.
Returns a tuple with the tx_offset and the op_offset.
Types
@type int64() :: 0..18_446_744_073_709_551_615
@type t() :: %Electric.Replication.LogOffset{ op_offset: non_neg_integer() | :infinity, tx_offset: int64() | -1 }
Functions
@spec before_all() :: t()
An offset that is smaller than all offsets in the log.
Examples
iex> compare(before_all(), first())
:lt
Compare two log offsets
Examples
iex> compare(new(10, 0), new(10, 1))
:lt
iex> compare(new(9, 1), new(10, 1))
:lt
iex> compare(new(10, 1), new(10, 0))
:gt
iex> compare(new(11, 1), new(10, 1))
:gt
iex> compare(new(0, 0), before_all())
:gt
iex> compare(new(10, 0), %LogOffset{tx_offset: 10, op_offset: 0})
:eq
@spec first() :: t()
The first possible offset in the log.
Parse the given string as a LogOffset value.
Examples
iex> from_string("-1")
{:ok, before_all()}
iex> from_string("0_0")
{:ok, %LogOffset{tx_offset: 0, op_offset: 0}}
iex> from_string("11_13")
{:ok, %LogOffset{tx_offset: 11, op_offset: 13}}
iex> from_string("0_02")
{:ok, %LogOffset{tx_offset: 0, op_offset: 2}}
iex> from_string("1_2_3")
{:error, "has invalid format"}
iex> from_string("1_2 ")
{:error, "has invalid format"}
iex> from_string("10")
{:error, "has invalid format"}
iex> from_string("10_32.1")
{:error, "has invalid format"}
Increments the offset of the change inside the transaction.
Examples
iex> increment(new(10, 5))
%LogOffset{tx_offset: 10, op_offset: 6}
iex> compare(new(10, 5) |> increment, new(10, 5))
:gt
iex> increment(new(10, 5), 5)
%LogOffset{tx_offset: 10, op_offset: 10}
iex> compare(new(10, 1) |> increment(4), new(10, 5))
:eq
@spec last() :: t()
The last possible offset in the log.
Examples
iex> compare(first(), last())
:lt
iex> compare(new(Lsn.from_integer(10), 0), last())
:lt
Create a new LogOffset value.
Examples
iex> new(Lsn.from_integer(10), 0)
%LogOffset{tx_offset: 10, op_offset: 0}
iex> new(11, 3)
%LogOffset{tx_offset: 11, op_offset: 3}
iex> new(to_tuple(new(Lsn.from_integer(5), 1)))
%LogOffset{tx_offset: 5, op_offset: 1}
iex> new({11, 3})
%LogOffset{tx_offset: 11, op_offset: 3}
iex> new({11, 3.2})
** (FunctionClauseError) no function clause matching in Electric.Replication.LogOffset.new/2
iex> new(10, -2)
** (FunctionClauseError) no function clause matching in Electric.Replication.LogOffset.new/2
Format a LogOffset value to its text representation in an iolist.
Examples
iex> to_iolist(first())
["0", ?_, "0"]
iex> to_iolist(new(Lsn.from_integer(10), 3))
["10", ?_, "3"]
iex> to_iolist(before_all())
["-1"]
@spec to_tuple(t()) :: {int64(), non_neg_integer()}
Returns a tuple with the tx_offset and the op_offset.
Examples
iex> to_tuple(first())
{0, 0}
iex> to_tuple(new(Lsn.from_integer(10), 3))
{10, 3}