Tank.Store (Tank v0.1.0)

Copy Markdown View Source

The desired-state store seam: Tank's view of the [:tank, :pods, …] subtree of a Khepri store.

Bring-your-own-or-default

Tank is a library, so it never owns a store's cluster lifecycle. Which side starts Khepri is chosen by the :data_dir option:

  • :data_dir set — Tank boots a default store at that directory and owns it (standalone, dev, tests).
  • :data_dir nil — the store named by :store_id is assumed to be started by the consumer; Tank only attaches its projection.

Either way Tank registers a khepri_projection mirroring [:tank, :pods, **] into the ETS table :tank_pods, so list_pods/0 is a fast local read (the substrate the reconciler will watch). Single-pod reads go straight to Khepri so they are authoritative.

Pods are stored as %Tank.Pod{} structs at [:tank, :pods, name].

Summary

Functions

Supervisor child spec for the store seam.

Write a pod only if it does not already exist (the create-if-absent seed path). Returns {:error, :exists} if a pod with that name is already stored.

Delete a pod by name. Deleting a missing pod is a no-op :ok.

Fetch a single pod by name (authoritative read straight from Khepri).

List all stored pods via the ETS projection — a fast local read. Eventually consistent with writes (the reconciler is level-triggered, so that is fine).

Write (create or overwrite) the desired state of a pod.

Start the store seam. See the moduledoc for :store_id / :data_dir.

Functions

child_spec(init_arg)

Supervisor child spec for the store seam.

create_pod(pod)

@spec create_pod(Tank.Pod.t()) :: :ok | {:error, :exists | term()}

Write a pod only if it does not already exist (the create-if-absent seed path). Returns {:error, :exists} if a pod with that name is already stored.

delete_pod(name)

@spec delete_pod(String.t()) :: :ok | {:error, term()}

Delete a pod by name. Deleting a missing pod is a no-op :ok.

get_pod(name)

@spec get_pod(String.t()) :: {:ok, Tank.Pod.t()} | {:error, :not_found}

Fetch a single pod by name (authoritative read straight from Khepri).

list_pods()

@spec list_pods() :: [Tank.Pod.t()]

List all stored pods via the ETS projection — a fast local read. Eventually consistent with writes (the reconciler is level-triggered, so that is fine).

put_pod(pod)

@spec put_pod(Tank.Pod.t()) :: :ok | {:error, term()}

Write (create or overwrite) the desired state of a pod.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the store seam. See the moduledoc for :store_id / :data_dir.