Bedrock.DataPlane.Materializer.Olivine.IndexDatabase (bedrock v0.5.3)
View SourceAppend-only file-based storage for Olivine index version blocks.
File Format
Each record represents a version block containing modified pages:
[Header: 16 bytes]
- magic: 0x4F4C5644 (4 bytes) - "OLVD"
- version: (8 bytes) - commit version (binary)
- payload_size: (4 bytes) - size of payload
[Payload: variable bytes]
- :erlang.term_to_binary({previous_version, pages_map}, [:compressed])
[Footer: 4 bytes]
- payload_size: (4 bytes) - repeated for backward scanRecovery
The durable version is the version of the last complete record in the file. Recovery reads the last 20 bytes (footer + header start) to extract it.
Reading
Page blocks are loaded by scanning backward from EOF until the target version is found. This supports the iterative page chain loading pattern.
Summary
Functions
Builds a snapshot record as iodata without writing to a file. Used by CompactionWriter implementations to get the index bytes. The previous_version equals version (self-loop) to terminate the chain.
Load the page block for a given version, returning the pages and the next version in the chain. Returns {pages_map, next_version} where next_version is the previous version that forms a chain.
Writes a snapshot block to a file descriptor. Used during compaction to create a single version block with all current pages. The previous_version equals version (self-loop) to terminate the chain.
Types
@type t() :: %Bedrock.DataPlane.Materializer.Olivine.IndexDatabase{ durable_version: Bedrock.version(), file: :file.fd(), file_name: [char()], file_offset: non_neg_integer(), last_block_empty: boolean(), last_block_offset: non_neg_integer(), last_block_previous_version: Bedrock.version() | nil }
Functions
@spec build_snapshot_record(Bedrock.version(), %{ required(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()) => {Bedrock.DataPlane.Materializer.Olivine.Index.Page.t(), Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()} }) :: iodata()
Builds a snapshot record as iodata without writing to a file. Used by CompactionWriter implementations to get the index bytes. The previous_version equals version (self-loop) to terminate the chain.
@spec close(t()) :: :ok
@spec durable_version(t()) :: Bedrock.version()
@spec flush( t(), new_durable_version :: Bedrock.version(), previous_durable_version :: Bedrock.version(), collected_pages :: [ %{ required(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()) => {Bedrock.DataPlane.Materializer.Olivine.Index.Page.t(), Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()} } ] ) :: {:ok, t()} | {:error, {:index_file_write_failed, File.posix()}} | {:error, {:index_file_truncate_failed, File.posix()}} | {:error, {:index_file_sync_failed, File.posix()}}
@spec load_durable_version(t()) :: {:ok, Bedrock.version()} | {:error, :not_found}
@spec load_page_block(t(), Bedrock.version()) :: {:ok, %{ required(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()) => {Bedrock.DataPlane.Materializer.Olivine.Index.Page.t(), Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()} }, Bedrock.version() | nil} | {:error, :not_found}
Load the page block for a given version, returning the pages and the next version in the chain. Returns {pages_map, next_version} where next_version is the previous version that forms a chain.
@spec load_pages_from_version(t(), Bedrock.version()) :: %{ required(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()) => {Bedrock.DataPlane.Materializer.Olivine.Index.Page.t(), Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()} }
@spec open(otp_name :: atom(), file_path :: String.t()) :: {:ok, t()} | {:error, :system_limit | :badarg | File.posix()}
@spec sync(t()) :: :ok
@spec write_snapshot_block(:file.fd(), Bedrock.version(), %{ required(Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()) => {Bedrock.DataPlane.Materializer.Olivine.Index.Page.t(), Bedrock.DataPlane.Materializer.Olivine.Index.Page.id()} }) :: :ok
Writes a snapshot block to a file descriptor. Used during compaction to create a single version block with all current pages. The previous_version equals version (self-loop) to terminate the chain.