Bedrock.DataPlane.Log.Shale.Segment (bedrock v0.6.0)

View Source

Represents a segment of the Shale transaction log.

Summary

Types

t()

@type t() :: %Bedrock.DataPlane.Log.Shale.Segment{
  min_version: Bedrock.version(),
  path: String.t(),
  previous_version: Bedrock.version(),
  transactions: nil | [Bedrock.DataPlane.Transaction.encoded()]
}

Functions

allocate_from_recycler(segment_recycler, path, version, previous_version)

@spec allocate_from_recycler(
  Bedrock.DataPlane.Log.Shale.SegmentRecycler.server(),
  String.t(),
  Bedrock.version(),
  Bedrock.version()
) :: {:ok, t()} | {:error, :allocation_failed}

allocate_from_recycler!(segment_recycler, path, version, previous_version)

decode_file_name(arg)

@spec decode_file_name(String.t()) :: pos_integer()

encode_file_name(n)

@spec encode_file_name(pos_integer()) :: String.t()

ensure_transactions_are_loaded(segment)

@spec ensure_transactions_are_loaded(t()) :: t()

file_prefix()

@spec file_prefix() :: String.t()

from_path(path_to_file)

@spec from_path(path_to_file :: String.t()) ::
  {:ok, t()}
  | {:error,
     {:wal_format, String.t(), :unsupported_wal_format | :invalid_wal_format}}
  | {:error, {:wal_io, String.t(), File.posix()}}

Create a new segment from the given file path.

The header read itself is the existence check — no File.exists?/1 precheck, no check-then-open race. Failures keep their nature: bad bytes are {:wal_format, path, reason} and never retried as resource trouble; open/read failures are {:wal_io, path, posix} with their real POSIX cause, never mislabeled as corruption.

last_version(map)

@spec last_version(t()) :: Bedrock.version() | nil

oldest_version(map)

@spec oldest_version(t()) :: Bedrock.version()

return_to_recycler(segment, segment_recycler)

@spec return_to_recycler(t(), Bedrock.DataPlane.Log.Shale.SegmentRecycler.server()) ::
  :ok

transactions(segment)

@spec transactions(t()) :: [Bedrock.DataPlane.Transaction.encoded()]