Bedrock.DataPlane.Resolver.MetadataAccumulator (bedrock v0.5.2)

View Source

Manages 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

entry()

@type entry() :: {version :: Bedrock.version(), mutations :: [mutation()]}

mutation()

t()

@type t() :: %Bedrock.DataPlane.Resolver.MetadataAccumulator{
  reversed_entries: [entry()]
}

Functions

append(accumulator, version, mutations)

@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 to
  • version - The commit version for these mutations
  • mutations - List of metadata mutations to append

Examples

iex> acc = new() |> append(v(1), [{:set, <<0xFF, "key">>, "value"}])
iex> length(entries(acc))
1

entries(metadata_accumulator)

@spec entries(t()) :: [entry()]

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"}]}]

mutations_since(metadata_accumulator, since_version)

@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 query
  • since_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"}]}]

new()

@spec new() :: t()

Creates a new empty metadata accumulator.

Examples

iex> entries(new())
[]

prune_before(accumulator, before_version)

@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 prune
  • before_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