View Source ProcessHub.Service.DeclaredChildren.Store (ProcessHub v0.8.0)

Local persistence of the declared list: the DETS-backed store beside the registry file, one row per declared child plus a version row, the seeded marker, the park flag, and the hand-off to the remote-manifest shipper. Every write goes through persist/4, so the seeded marker is maintained in one place, and reads come from the store's in-memory side.

Summary

Types

The manifest without its entries: what the version row holds.

Functions

Lifts the park flag.

Every stored entry, as %{child_id => spec}.

The stored spec of child_id, or nil when it is not declared.

The stored version row, or nil when no list was ever stored.

Opens the list's store; returns the :declared_backend entry for the hub's storage map, and :declared_path when the list is kept on disk. Called by the initializer when the feature gate is on.

Persists a batch: puts ([{child_id, spec}]) and removes (child ids) under the version row meta, in one synced write.

Reads the persisted manifest: {:ok, manifest | nil} (missing and malformed both read as absent), or an error for a format newer than this release. A list stored whole by an earlier release is rewritten one row per child.

Returns whether the hub has ever stored a list (marker survives rotation).

Sets the park flag the reconcile and mutations check.

Tells the remote shipper the list reached version; it reads the list itself when it ships. A no-op without a remote.

Persists manifest in full: the version row, and only the entries that differ from the stored ones. Removed children are dropped.

Types

@type meta() :: %{
  format: pos_integer(),
  version: non_neg_integer(),
  mutated_by: node()
}

The manifest without its entries: what the version row holds.

Functions

@spec clear_parked(ProcessHub.Hub.t()) :: :ok | boolean()

Lifts the park flag.

@spec entries(ProcessHub.Hub.t()) :: %{
  required(ProcessHub.child_id()) => ProcessHub.child_spec()
}

Every stored entry, as %{child_id => spec}.

The stored spec of child_id, or nil when it is not declared.

@spec meta(ProcessHub.Hub.t()) :: meta() | nil

The stored version row, or nil when no list was ever stored.

Link to this function

open(hub_id, registry_backend)

View Source
@spec open(ProcessHub.hub_id(), term()) :: %{
  :declared_backend => {module(), term()},
  optional(:declared_path) => String.t()
}

Opens the list's store; returns the :declared_backend entry for the hub's storage map, and :declared_path when the list is kept on disk. Called by the initializer when the feature gate is on.

The list is only as durable as the registry: a hub whose registry keeps nothing on disk gets an in-memory list too.

Link to this function

persist(hub, meta, puts, removes)

View Source
@spec persist(
  ProcessHub.Hub.t(),
  meta(),
  [{ProcessHub.child_id(), ProcessHub.child_spec()}],
  [
    ProcessHub.child_id()
  ]
) :: :ok | {:error, term()}

Persists a batch: puts ([{child_id, spec}]) and removes (child ids) under the version row meta, in one synced write.

Each child is its own row, so a batch costs its own size rather than the whole list's. A removal is written as a tombstone in that same write, so the version and every change of the batch land together, and the tombstone row is dropped after the sync.

@spec read(ProcessHub.Hub.t()) ::
  {:ok, ProcessHub.Service.DeclaredChildren.manifest() | nil} | {:error, term()}

Reads the persisted manifest: {:ok, manifest | nil} (missing and malformed both read as absent), or an error for a format newer than this release. A list stored whole by an earlier release is rewritten one row per child.

@spec seeded?(ProcessHub.Hub.t()) :: boolean()

Returns whether the hub has ever stored a list (marker survives rotation).

@spec set_parked(ProcessHub.Hub.t()) :: :ok | boolean()

Sets the park flag the reconcile and mutations check.

@spec ship(ProcessHub.Hub.t(), non_neg_integer()) :: :ok

Tells the remote shipper the list reached version; it reads the list itself when it ships. A no-op without a remote.

@spec write(ProcessHub.Hub.t(), ProcessHub.Service.DeclaredChildren.manifest()) ::
  :ok | {:error, term()}

Persists manifest in full: the version row, and only the entries that differ from the stored ones. Removed children are dropped.