Mnesiac v0.3.2 Mnesiac.Store behaviour View Source

This module defines a mnesiac store and contains overridable callbacks.

Link to this section Summary

Callbacks

This function is called by mnesiac when it joins a mnesia cluster and data for this store is found on the remote node in the cluster that is being connected to.

Default Implementation

def copy_store do
  for type <- [:ram_copies, :disc_copies, :disc_only_copies] do
    value = Keyword.get(store_options(), type, [])

This function is called by mnesiac either when it has no existing data to use or copy and will initialise a table

Default Implementation

def init_store do
      :mnesia.create_table(__MODULE__, store_options())
end

This function is called by mnesiac when it has detected data for a table on both the local node and the remote node of the cluster it is connecting to.

Default Implementation

Note: The default implementation for this function is to do nothing.

def resolve_conflict(cluster_node) do
  Logger.info("[mnesiac:nonode@nohost] Mnesiac.Store: data found on both sides, copy aborted.")
  :ok
end

This function returns ths store's configuration as a keyword list. For more information on the options supported here, see mnesia's documenatation. Note: Defining record_name in store_options() will set the mnesia table name to the same.

Examples

iex> store_options()
[attributes: [...], index: [:topic_id], disc_copies: [node()]]

Link to this section Callbacks

Link to this callback

copy_store() View Source (optional)
copy_store() :: term()

This function is called by mnesiac when it joins a mnesia cluster and data for this store is found on the remote node in the cluster that is being connected to.

Default Implementation

def copy_store do
  for type <- [:ram_copies, :disc_copies, :disc_only_copies] do
    value = Keyword.get(store_options(), type, [])

    if Enum.member?(value, node()) do
      :mnesia.add_table_copy(__MODULE__, node(), type)
    end
  end
end
Link to this callback

init_store() View Source (optional)
init_store() :: term()

This function is called by mnesiac either when it has no existing data to use or copy and will initialise a table

Default Implementation

def init_store do
      :mnesia.create_table(__MODULE__, store_options())
end
Link to this callback

resolve_conflict(node) View Source (optional)
resolve_conflict(node()) :: term()

This function is called by mnesiac when it has detected data for a table on both the local node and the remote node of the cluster it is connecting to.

Default Implementation

Note: The default implementation for this function is to do nothing.

def resolve_conflict(cluster_node) do
  Logger.info("[mnesiac:nonode@nohost] Mnesiac.Store: data found on both sides, copy aborted.")
  :ok
end
Link to this callback

store_options() View Source
store_options() :: term()

This function returns ths store's configuration as a keyword list. For more information on the options supported here, see mnesia's documenatation. Note: Defining record_name in store_options() will set the mnesia table name to the same.

Examples

iex> store_options()
[attributes: [...], index: [:topic_id], disc_copies: [node()]]