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

View Source

A struct that represents a writer for a segment.

Summary

Types

t()

A Writer is a handle to a segment that can be used to write transcations to the segment. It is a stateful object that keeps track of the current write offset and the number of bytes remaining in the segment.

Types

t()

@type t() :: %Bedrock.DataPlane.Log.Shale.Writer{
  bytes_remaining: pos_integer(),
  fd: File.file_descriptor(),
  pwrite_fun: (File.file_descriptor(), non_neg_integer(), iodata() ->
                 :ok | {:error, File.posix()}),
  sync_fun: (File.file_descriptor() -> :ok | {:error, File.posix()}),
  write_offset: pos_integer()
}

A Writer is a handle to a segment that can be used to write transcations to the segment. It is a stateful object that keeps track of the current write offset and the number of bytes remaining in the segment.

Functions

append(writer, transaction, commit_version)

@spec append(t(), Bedrock.DataPlane.Transaction.encoded(), Bedrock.version()) ::
  {:ok, t()} | {:error, :segment_full} | {:error, File.posix()}

close(writer)

@spec close(writer :: t() | nil) :: :ok | {:error, File.posix()}

open(path_to_file, previous_version, opts \\ [])

@spec open(
  path_to_file :: String.t(),
  previous_version :: Bedrock.version(),
  opts :: keyword()
) ::
  {:ok, t()} | {:error, File.posix()}

sync(writer)

@spec sync(t()) :: :ok | {:error, File.posix()}

Persists an empty segment header and its replay cursor.