Bedrock.Internal.TransactionBuilder.LayoutIndex (bedrock v0.7.0)

View Source

A partial, coalescing shard-lookup index: a gb_tree of end_key => {start_key, value} accumulated one covering entry at a time from proxy-served by-key routing fetches (FDB's locationCache shape - built from GetKeyServerLocations answers, never a bulk dump).

Entries are exact shard ranges keyed by exclusive end_key. Today the only shard-boundary writer is recovery's per-epoch rewrite, so entries fetched into one index are disjoint (the lookup's correctness depends on this) and re-inserting a shard is idempotent. Coarse invalidation - the whole index dropped on a wiring push or a routing-shaped read failure, never patched - keeps epochs from mixing; an in-flight cache cast can land after an invalidation, and that stale entry self-heals through the same invalidate-on-failure loop. LIABILITY (bedrock-q67.21): when the Distributor mutates boundaries mid-epoch, superseded ranges can coexist with their replacements in a live index - the insert must become overlap-aware (or eviction per-range) before that lands.

Lookups are a single O(log n) ceiling search; a key no fetched entry covers returns :not_cached, which the owner resolves through its routing fetch.

Summary

Types

A callable materializer ref: a pid or a {otp_name, node} tuple.

t()

Functions

Inserts one covering entry: the shard [start_key, end_key) and the value cached for it (callable refs in the transaction builder, raw keyspace refs in the Link's node-wide cache).

Looks up the cached covering entry for a key: {:ok, {key_range, value}} or :not_cached when no fetched entry covers it. O(log n).

An empty index; entries accumulate per fetched covering entry.

Types

server_ref()

@type server_ref() :: pid() | {atom(), node()}

A callable materializer ref: a pid or a {otp_name, node} tuple.

t()

@type t() :: %Bedrock.Internal.TransactionBuilder.LayoutIndex{
  tree:
    :gb_trees.tree(
      binary(),
      {binary(), term()}
    )
}

Functions

insert(t, start_key, end_key, value)

@spec insert(t(), Bedrock.key(), Bedrock.key(), term()) :: t()

Inserts one covering entry: the shard [start_key, end_key) and the value cached for it (callable refs in the transaction builder, raw keyspace refs in the Link's node-wide cache).

lookup_key(layout_index, key)

@spec lookup_key(t(), binary()) :: {:ok, {Bedrock.key_range(), term()}} | :not_cached

Looks up the cached covering entry for a key: {:ok, {key_range, value}} or :not_cached when no fetched entry covers it. O(log n).

new()

@spec new() :: t()

An empty index; entries accumulate per fetched covering entry.