FerricStore.ResourceLimits behaviour (ferricstore v0.7.2)

Copy Markdown View Source

Stable resource-limit contract for FerricStore control planes and write paths.

The public management commands use set_limit/3, get_limit/2, and usage/2. Internal enforcement points can use check/4, reserve/4, release/2, and record_activity/2 without coupling storage code to any specific limit backend.

Summary

Types

amount()

@type amount() :: non_neg_integer()

command()

@type command() :: binary()

command_args()

@type command_args() :: [term()]

limit_spec()

@type limit_spec() :: map()

reservation()

@type reservation() :: term()

resource()

@type resource() :: atom() | binary()

result()

@type result() :: :ok | {:ok, term()} | {:error, term()}

scope()

@type scope() :: binary() | map()

Callbacks

check(scope, resource, amount, keyword)

@callback check(scope(), resource(), amount(), keyword()) :: :ok | {:error, term()}

check_command(command, command_args, list, keyword)

@callback check_command(command(), command_args(), [binary()], keyword()) ::
  :ok | {:error, term()}

get_limit(scope, keyword)

@callback get_limit(
  scope(),
  keyword()
) :: result()

record_activity(list, keyword)

@callback record_activity(
  [binary()],
  keyword()
) :: :ok

release(reservation, keyword)

@callback release(
  reservation(),
  keyword()
) :: :ok | {:error, term()}

reserve(scope, resource, amount, keyword)

@callback reserve(scope(), resource(), amount(), keyword()) ::
  {:ok, reservation()} | {:error, term()}

set_limit(scope, limit_spec, keyword)

@callback set_limit(scope(), limit_spec(), keyword()) :: result()

usage(scope, keyword)

@callback usage(
  scope(),
  keyword()
) :: result()

Functions

check(scope, resource, amount, opts \\ [])

@spec check(scope(), resource(), amount(), keyword()) :: :ok | {:error, term()}

check_command(command, args, keys, opts \\ [])

@spec check_command(command(), command_args(), [binary()], keyword()) ::
  :ok | {:error, term()}

error_message(reason)

@spec error_message(term()) :: binary()

get_limit(scope, opts \\ [])

@spec get_limit(
  scope(),
  keyword()
) :: result()

record_activity(keys, opts \\ [])

@spec record_activity(
  [binary()],
  keyword()
) :: :ok

release(reservation, opts \\ [])

@spec release(
  reservation(),
  keyword()
) :: :ok | {:error, term()}

reserve(scope, resource, amount, opts \\ [])

@spec reserve(scope(), resource(), amount(), keyword()) ::
  {:ok, reservation()} | {:error, term()}

set_limit(scope, limit_spec, opts \\ [])

@spec set_limit(scope(), limit_spec(), keyword()) :: result()

usage(scope, opts \\ [])

@spec usage(
  scope(),
  keyword()
) :: result()