Bedrock.DataPlane.Resolver.MetadataAccumulator (bedrock v0.5.2)
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
Functions
Appends mutations at a given version 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 strictly before the given version.
Types
@type entry() :: {version :: Bedrock.version(), mutations :: [mutation()]}
@type mutation() :: Bedrock.Internal.TransactionBuilder.Tx.mutation()
@type t() :: %Bedrock.DataPlane.Resolver.MetadataAccumulator{ reversed_entries: [entry()] }
Functions
@spec append(t(), Bedrock.version(), [mutation()]) :: t()
Appends mutations at a given version to the accumulator.
Mutations are stored in version order. If mutations is empty, this is a no-op.
Parameters
accumulator- The accumulator to append toversion- The commit version for these mutationsmutations- List of metadata mutations to append
Examples
iex> acc = new() |> append(v(1), [{:set, <<0xFF, "key">>, "value"}])
iex> length(entries(acc))
1
Returns all entries in version order (oldest first).
Examples
iex> acc = new() |> append(v(1), [{:set, <<0xFF, "a">>, "1"}])
iex> entries(acc)
[{<<0, 0, 0, 0, 0, 0, 0, 1>>, [{:set, <<0xFF, "a">>, "1"}]}]
@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"}])
iex> |> append(v(2), [{:set, <<0xFF, "b">>, "2"}])
iex> mutations_since(acc, v(1))
[{<<0, 0, 0, 0, 0, 0, 0, 2>>, [{:set, <<0xFF, "b">>, "2"}]}]
@spec new() :: t()
Creates a new empty metadata accumulator.
Examples
iex> entries(new())
[]
@spec prune_before(t(), Bedrock.version()) :: t()
Removes all entries with versions strictly before the given version.
This prunes old entries that are no longer needed, keeping memory bounded.
Parameters
accumulator- The accumulator to prunebefore_version- Remove entries with versions < this version
Examples
iex> acc = new()
iex> |> append(v(1), [{:set, <<0xFF, "a">>, "1"}])
iex> |> append(v(2), [{:set, <<0xFF, "b">>, "2"}])
iex> |> prune_before(v(2))
iex> length(entries(acc))
1