Bedrock.DataPlane.Resolver.MetadataAccumulator (bedrock v0.7.0)
View SourceManages a version-ordered window of metadata mutations.
The accumulator maintains metadata mutations in version order, allowing efficient retrieval of mutations since a given version and pruning of old entries. This enables differential updates to be returned to proxies.
Internally, entries are stored in reverse order (newest first) for O(1) append.
Summary
Types
One metadata-carrying transaction's mutations with this resolver's LOCAL verdict. The commit proxy ANDs verdicts positionally across all resolvers' windows to obtain the global verdict.
Functions
Appends a version's transaction metadata (with local verdicts) to the accumulator.
Returns all entries in version order (oldest first).
Returns all mutations since (but not including) the given version.
Creates a new empty metadata accumulator.
Removes all entries with versions at or below the given version.
Types
@type entry() :: {version :: Bedrock.version(), [transaction_metadata()]}
@type mutation() :: Bedrock.Internal.TransactionBuilder.Tx.mutation()
@type t() :: %Bedrock.DataPlane.Resolver.MetadataAccumulator{ reversed_entries: [entry()] }
One metadata-carrying transaction's mutations with this resolver's LOCAL verdict. The commit proxy ANDs verdicts positionally across all resolvers' windows to obtain the global verdict.
Functions
@spec append(t(), Bedrock.version(), [transaction_metadata()]) :: t()
Appends a version's transaction metadata (with local verdicts) to the accumulator.
Entries are stored in version order. If the list is empty, this is a no-op.
Examples
iex> acc = new() |> append(v(1), [{[{:set, <<0xFF, "key">>, "value"}], true}])
iex> length(entries(acc))
1
Returns all entries in version order (oldest first).
Examples
iex> acc = new() |> append(v(1), [{[{:set, <<0xFF, "a">>, "1"}], true}])
iex> entries(acc)
[{<<0, 0, 0, 0, 0, 0, 0, 1>>, [{[{:set, <<0xFF, "a">>, "1"}], true}]}]
@spec mutations_since(t(), Bedrock.version() | nil) :: [entry()]
Returns all mutations since (but not including) the given version.
Returns mutations in version order (oldest first). If since_version is nil,
returns all mutations in the accumulator.
Parameters
accumulator- The accumulator to querysince_version- Return mutations after this version (exclusive), or nil for all
Examples
iex> acc = new()
iex> |> append(v(1), [{[{:set, <<0xFF, "a">>, "1"}], true}])
iex> |> append(v(2), [{[{:set, <<0xFF, "b">>, "2"}], true}])
iex> mutations_since(acc, v(1))
[{<<0, 0, 0, 0, 0, 0, 0, 2>>, [{[{:set, <<0xFF, "b">>, "2"}], true}]}]
@spec new() :: t()
Creates a new empty metadata accumulator.
Examples
iex> entries(new())
[]
@spec prune_through(t(), Bedrock.version()) :: t()
Removes all entries with versions at or below the given version.
This prunes entries every proxy has been served (windows are exact, so a served entry can never be requested again), keeping memory bounded.
Parameters
accumulator- The accumulator to prunethrough_version- Remove entries with versions <= this version
Examples
iex> acc = new()
iex> |> append(v(1), [{[{:set, <<0xFF, "a">>, "1"}], true}])
iex> |> append(v(2), [{[{:set, <<0xFF, "b">>, "2"}], true}])
iex> |> prune_through(v(1))
iex> length(entries(acc))
1