View Source ProcessHub.Service.Storage.DetsFile (ProcessHub v0.8.0)

On-disk DETS file management shared by the DETS-file storage backends (ProcessHub.Service.Storage.Dets and ProcessHub.Service.Storage.DurableEts).

Covers path resolution, corruption rotation, and the durable-medium read. It is specific to persisting through a DETS file; in-memory or remote backends do not use it.

Summary

Functions

The on-disk path in opts, or nil when none was given.

Syncs table unless the write asked for sync: false (a group commit syncs later).

Folds table into its non-expired {key, value} rows.

Returns the on-disk path the backend was configured with, or raises.

Rotates a corrupt DETS file aside, logs at ERROR, and reopens a fresh file.

Functions

@spec configured_path(keyword()) :: String.t() | nil

The on-disk path in opts, or nil when none was given.

The single place backend options are read for a file location, so "was this backend told where to write?" is answered the same way everywhere.

Link to this function

maybe_sync(table, write_opts)

View Source
@spec maybe_sync(
  atom(),
  keyword()
) :: :ok | {:error, term()}

Syncs table unless the write asked for sync: false (a group commit syncs later).

@spec read_durable(atom()) :: {:ok, [{term(), term()}]} | {:error, term()}

Folds table into its non-expired {key, value} rows.

This is the read_durable/1 implementation shared by both DETS-file backends: it reads the file only, never the live in-memory view either backend keeps beside it. An unreadable file returns {:error, reason} — never an empty set, which callers would mistake for "everything was deliberately removed".

Link to this function

resolve_path(hub_id, opts)

View Source
@spec resolve_path(
  atom(),
  keyword()
) :: String.t()

Returns the on-disk path the backend was configured with, or raises.

There is no default: a library cannot know a location its host owns, and the one it used to pick sat in its own priv, where the host could not reach it.

Link to this function

rotate_and_reopen(hub_id, path, reason)

View Source
@spec rotate_and_reopen(atom(), String.t(), term()) ::
  {{:ok, atom()} | {:error, term()}, boolean()}

Rotates a corrupt DETS file aside, logs at ERROR, and reopens a fresh file.