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

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

Types

t()

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

entry()

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

mutation()

t()

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

transaction_metadata()

@type transaction_metadata() :: {mutations :: [mutation()], committed? :: boolean()}

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

append(accumulator, version, transaction_metadata)

@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

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"}], true}])
iex> entries(acc)
[{<<0, 0, 0, 0, 0, 0, 0, 1>>, [{[{:set, <<0xFF, "a">>, "1"}], true}]}]

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

new()

@spec new() :: t()

Creates a new empty metadata accumulator.

Examples

iex> entries(new())
[]

prune_through(accumulator, through_version)

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