Bedrock.Directory (bedrock v0.5.2)

View Source

FoundationDB directory layer operations.

Directories provide a hierarchical namespace for organizing data within a FoundationDB database. Each directory corresponds to a unique prefix that can be used to create isolated keyspaces.

Based on the FoundationDB directory layer specification.

Summary

Functions

Creates a directory at the given path.

Creates or opens a directory at the given path.

Checks if a directory exists at the given path.

Returns the layer identifier of this directory, or nil if none.

Lists the immediate subdirectories of the given path.

Moves a directory from old_path to new_path.

Opens an existing directory at the given path.

Returns the path of this directory as a list of strings.

Removes a directory and all its subdirectories.

Removes a directory if it exists.

Creates a new directory layer.

Types

Functions

create(dir, path, opts \\ [])

@spec create(directory(), [String.t()], keyword()) ::
  {:ok, directory()}
  | {:error, :directory_already_exists}
  | {:error, :parent_directory_does_not_exist}
  | {:error, :invalid_path}

Creates a directory at the given path.

Returns {:ok, directory} if successful, or {:error, reason} if the directory already exists or the parent directory does not exist.

Options

  • :layer - Layer identifier for the directory (binary)
  • :prefix - Manual prefix assignment (binary)
  • :version - Version metadata for the directory (term)
  • :metadata - Additional metadata for the directory (term)

create_or_open(dir, path, opts \\ [])

@spec create_or_open(directory(), [String.t()], keyword()) ::
  {:ok, directory()}
  | {:error, :parent_directory_does_not_exist}
  | {:error, :invalid_path}

Creates or opens a directory at the given path.

If the directory exists, opens it. Otherwise, creates it.

Options

  • :layer - Layer identifier for the directory (binary)
  • :prefix - Manual prefix assignment (binary)
  • :version - Version metadata for the directory (term)
  • :metadata - Additional metadata for the directory (term)

do_create(layer, txn, path, opts)

@spec do_create(Bedrock.Directory.Layer.t(), term(), [String.t()], keyword()) ::
  {:ok, Bedrock.Directory.Node.t()} | {:error, atom()}

do_exists?(layer, path)

@spec do_exists?(Bedrock.Directory.Layer.t(), [String.t()]) :: boolean()

do_list(layer, txn, path)

@spec do_list(Bedrock.Directory.Layer.t(), term(), [String.t()]) ::
  {:ok, [String.t()]} | {:error, atom()}

do_move(layer, txn, old_path, new_path)

@spec do_move(Bedrock.Directory.Layer.t(), term(), [String.t()], [String.t()]) ::
  :ok | {:error, atom()}

do_open(layer, txn, path)

do_remove(layer, txn, path)

@spec do_remove(Bedrock.Directory.Layer.t(), term(), [String.t()]) ::
  :ok | {:error, atom()}

exists?(layer, path)

@spec exists?(directory(), [String.t()]) :: boolean()

Checks if a directory exists at the given path.

is_prefix_free?(layer, txn, prefix)

@spec is_prefix_free?(Bedrock.Directory.Layer.t(), term(), binary()) :: boolean()

layer(arg1)

@spec layer(directory()) :: binary() | nil

Returns the layer identifier of this directory, or nil if none.

list(dir, path \\ [])

@spec list(directory(), [String.t()]) :: {:ok, [String.t()]}

Lists the immediate subdirectories of the given path.

Returns a list of subdirectory names (strings).

move(layer, old_path, new_path)

@spec move(directory(), [String.t()], [String.t()]) ::
  :ok
  | {:error, :directory_does_not_exist}
  | {:error, :directory_already_exists}
  | {:error, :parent_directory_does_not_exist}

Moves a directory from old_path to new_path.

The directory and all its subdirectories are moved atomically.

open(layer, path)

@spec open(directory(), [String.t()]) ::
  {:ok, directory()}
  | {:error, :directory_does_not_exist}
  | {:error, :invalid_path}

Opens an existing directory at the given path.

Returns {:ok, directory} if successful, or {:error, :directory_does_not_exist} if the directory does not exist.

path(arg1)

@spec path(directory()) :: [String.t()]

Returns the path of this directory as a list of strings.

remove(layer, path)

@spec remove(directory(), [String.t()]) :: :ok | {:error, :directory_does_not_exist}

Removes a directory and all its subdirectories.

Returns an error if the directory does not exist.

remove_if_exists(layer, path)

@spec remove_if_exists(directory(), [String.t()]) :: :ok

Removes a directory if it exists.

Returns :ok whether the directory existed or not.

root(repo, opts \\ [])

@spec root(
  module(),
  keyword()
) :: Bedrock.Directory.Node.t()

Creates a new directory layer.

Arguments

  • repo - Module implementing Bedrock.Repo behaviour (required)

Options

  • :next_prefix_fn - Function for prefix allocation (default: uses HighContentionAllocator)
  • :node_keyspace - Custom node storage location
  • :content_keyspace - Custom content storage location

root?(arg1)

@spec root?([String.t()]) :: boolean()

to_keyspace(directory, opts \\ [])

@spec to_keyspace(
  directory(),
  opts :: [key_encoding: module(), value_encoding: module()]
) ::
  Bedrock.Keyspace.t()

Returns a Bedrock.Keyspace for this directory.

The keyspace can be used to store and retrieve data within this directory's keyspace.

validate_path(path)

@spec validate_path([String.t()] | String.t() | tuple() | term()) ::
  :ok
  | {:error,
     :invalid_path_format
     | :invalid_path_component
     | :empty_path_component
     | :invalid_directory_name
     | :reserved_prefix_in_path
     | :invalid_utf8_in_path
     | :null_byte_in_path}