Mnemosyne.GraphBackends.Persistence.DETS (mnemosyne v0.3.0)

Copy Markdown View Source

DETS-backed persistence for the InMemory graph backend.

Stores nodes as {node_id, node_struct} records. Secondary indexes are rebuilt on load via Graph.put_node/2. Ingestion records are kept separately as {{:ingestion, source_id}, record} rows.

Summary

Functions

Persists a new ingestion with its graph and metadata changes.

Removes nodes by ID from DETS and strips any back-references to those IDs from every surviving node's link sets. Without the strip pass, surviving rows retain dangling references that re-materialize on reload.

Removes metadata entries by node ID from DETS.

Opens the DETS file at the configured path, returning a handle map.

Reads all records from DETS and rebuilds a graph, metadata map, and ingestion map.

Persists changeset additions and links to DETS.

Persists metadata entries as {{:meta, id}, metadata} records.

Functions

commit_ingestion(record, changeset, map)

@spec commit_ingestion(
  Mnemosyne.GraphBackend.ingestion_record(),
  Mnemosyne.Graph.Changeset.t(),
  map()
) :: :ok | {:error, term()}

Persists a new ingestion with its graph and metadata changes.

The ingestion row is written last as the commit marker and the table is then synchronized. DETS has no transactions, so a write failure before the marker may leave partial graph or metadata rows for a later load.

delete(node_ids, arg2)

@spec delete([String.t()], map()) :: :ok | {:error, term()}

Removes nodes by ID from DETS and strips any back-references to those IDs from every surviving node's link sets. Without the strip pass, surviving rows retain dangling references that re-materialize on reload.

delete_metadata(node_ids, map)

@spec delete_metadata([String.t()], map()) :: :ok | {:error, term()}

Removes metadata entries by node ID from DETS.

init(opts)

@spec init(keyword()) :: {:ok, map()} | {:error, term()}

Opens the DETS file at the configured path, returning a handle map.

load(map)

@spec load(map()) :: {:ok, Mnemosyne.Graph.t(), map(), map()} | {:error, term()}

Reads all records from DETS and rebuilds a graph, metadata map, and ingestion map.

Node records are stored as {id, node} tuples, metadata records as {{:meta, id}, metadata} tuples, and ingestion records as {{:ingestion, source_id}, record} tuples.

save(changeset, map)

@spec save(Mnemosyne.Graph.Changeset.t(), map()) :: :ok | {:error, term()}

Persists changeset additions and links to DETS.

save_metadata(entries, map)

@spec save_metadata(%{required(String.t()) => struct()}, map()) ::
  :ok | {:error, term()}

Persists metadata entries as {{:meta, id}, metadata} records.