Bedrock.DataPlane.Materializer.Olivine.IndexUpdate (bedrock v0.6.0)

View Source

Tracks mutation state during index updates.

Mutation Processing

Mutations are distributed to pages based on key ranges:

  1. Key Distribution: Use Tree.page_for_key/2 to find target page
  2. Batch Processing: Group operations by page_id for efficiency
  3. Page Operations: Apply all operations to a page at once
  4. Automatic Splitting: Split pages exceeding 256 keys
  5. Chain Maintenance: Update page chains when pages are added/removed

Process Flow

  1. apply_set_mutation/5: Determines target page, stores value, queues operation
  2. apply_clear_mutation/3: Queues clear operation for existing key
  3. apply_range_clear_mutation/4: Handles range clears across multiple pages
  4. process_pending_operations/1: Applies all queued operations
  5. finish/1: Returns final index and page allocator state

Page 0 Protection

Page 0 is never deleted, only updated. When page 0 becomes empty, it remains in the index to preserve the leftmost chain entry point.

Summary

Functions

Applies mutations to this IndexUpdate, returning the updated IndexUpdate.

Finishes the IndexUpdate, returning the final Index, Database, IdAllocator, and key change counts.

Creates an IndexUpdate for mutation tracking from an Index, version, and id allocator. Statistics tracking is disabled by default for maximum performance.

Process all pending operations for each modified page using sorted merge.

Types

t()

@type t() :: %Bedrock.DataPlane.Materializer.Olivine.IndexUpdate{
  database: Bedrock.DataPlane.Materializer.Olivine.Database.t(),
  id_allocator: Bedrock.DataPlane.Materializer.Olivine.IdAllocator.t(),
  index: Bedrock.DataPlane.Materializer.Olivine.Index.t(),
  keys_added: non_neg_integer(),
  keys_changed: non_neg_integer(),
  keys_removed: non_neg_integer(),
  modified_page_ids:
    MapSet.t(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()),
  pending_operations: %{
    required(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()) => %{
      required(Bedrock.key()) => {:set, Bedrock.version()} | :clear
    }
  },
  track_statistics: boolean(),
  version: Bedrock.version()
}

Functions

apply_mutations(index_update, mutations)

@spec apply_mutations(
  t(),
  Enumerable.t(Bedrock.Internal.TransactionBuilder.Tx.mutation())
) :: t()

Applies mutations to this IndexUpdate, returning the updated IndexUpdate.

finish(index_update)

Finishes the IndexUpdate, returning the final Index, Database, IdAllocator, and key change counts.

new(index, version, id_allocator, database)

Creates an IndexUpdate for mutation tracking from an Index, version, and id allocator. Statistics tracking is disabled by default for maximum performance.

process_pending_operations(index_update)

@spec process_pending_operations(t()) :: t()

Process all pending operations for each modified page using sorted merge.