Skip to content

Commit

Permalink
add entry docs of mnesia information, based on #28
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Mar 6, 2024
1 parent 2e8edda commit aa6f719
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 6 deletions.
25 changes: 25 additions & 0 deletions lib/modules/mnesia_assistant/mnesia_assistant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ defmodule MnesiaAssistant do

def unsubscribe(what), do: Mnesia.unsubscribe(what)

@doc """
When tracing a system of Mnesia applications it is useful to be able to
interleave Mnesia own events with `application-related` events that give
information about the application context.
Whenever the application begins a new and demanding Mnesia task,
or if it enters a new interesting phase in its execution, it can be a good idea
to use mnesia:report_event/1. Event can be any term and generates
a `{mnesia_user, Event}` event for any processes that subscribe
to Mnesia system events. for more information read `subscribe/1` document.
### Example:
```elixir
MnesiaAssistant.report_event(event)
```
"""
def report_event(event), do: Mnesia.report_event(event)

@doc """
The `:mnesia.change_config/2` function in Mnesia, the distributed database management
system in Erlang/OTP, is used to dynamically change the configuration parameters
Expand All @@ -182,6 +201,12 @@ defmodule MnesiaAssistant do
* `config`: --> extra_db_nodes | dc_dump_limit
* `value`: --> [node()] | number()
### Example
```elixir
MnesiaAssistant.change_config(config, value)
```
"""
def change_config(config, value) when config in [:extra_db_nodes, :dc_dump_limit],
do: Mnesia.change_config(config, value)
Expand Down
92 changes: 86 additions & 6 deletions lib/modules/mnesia_assistant/operation/information.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule MnesiaAssistant.Information do
@moduledoc """
This particular module is actually a set of functions in `Mnesia` that are designed
to supply the user with the information that they require regarding the system.
"""
alias :mnesia, as: Mnesia
@debug_level_types [:none, :verbose, :debug, :trace, false, true]
Expand Down Expand Up @@ -42,34 +43,113 @@ defmodule MnesiaAssistant.Information do
]

@doc """
This function is actually a combination of two functions
in mnesia(`:mnesia.info()`, `:mnesia.schema()`).
### Example:
```elixir
MnesiaAssistant.Information.info()
# OR
MnesiaAssistant.Information.info({:system, type})
# OR
MnesiaAssistant.Information.info(type)
```
All types you can use:
```
[
:all,
:access_module,
:auto_repair,
:backup_module,
:checkpoints,
:event_module,
:db_nodes,
:debug,
:directory,
:dump_log_load_regulation,
:dump_log_time_threshold,
:dump_log_update_in_place,
:dump_log_write_threshold,
:extra_db_nodes,
:fallback_activated,
:held_locks,
:is_running,
:local_tables,
:lock_queue,
:log_version,
:master_node_tables,
:protocol_version,
:running_db_nodes,
:schema_location,
:subscribers,
:tables,
:transactions,
:transaction_failures,
:transaction_commits,
:transaction_restarts,
:transaction_log_writes,
:use_dir,
:version,
:schema
]
```
"""
def info(), do: Mnesia.info()

@doc """
Read `info/0` document.
"""
def info({:system, type}) when type in @system_types, do: Mnesia.system_info(type)

def info(type) when type in @system_types, do: Mnesia.system_info(type)

def info(:schema), do: Mnesia.schema()

@doc """
Read `info/0` document.
"""
def system_info(type) when is_atom(type), do: Mnesia.system_info(type)

@doc """
If the application detects a communication failure (in a potentially partitioned network)
that can have caused an inconsistent database, it can use the function
`mnesia:set_master_nodes(Tab, MasterNodes)` to define from which nodes
each table is to be loaded. At startup, the Mnesia normal table load algorithm is
bypassed and the table is loaded from one of the master nodes defined for the table,
regardless of when and if Mnesia terminated on other nodes. MasterNodes can only
contain nodes where the table has a replica. If the MasterNodes list is empty,
the master node recovery mechanism for the particular table is reset,
and the normal load mechanism is used at the next restart.
> The master node setting is always local. It can be changed regardless
> if Mnesia is started or not.
The database can also become inconsistent if configuration
parameter `max_wait_for_decision` is used or if `mnesia:force_load_table/1` is used.
### Example:
```elixir
MnesiaAssistant.Information.set_debug_level(level)
```
All level you can use: `[:none, :verbose, :debug, :trace, false, true]`
"""
def set_debug_level(level) when level in @debug_level_types,
do: Mnesia.set_debug_level(level)

@doc """
Ensures that the local transaction log file is synced to disk.
On a single node system, data written to disk tables since the
last dump can be lost if there is a power outage.
"""
def report_event(event), do: Mnesia.report_event(event)

@doc """
### Example:
```elixir
MnesiaAssistant.Information.sync_log()
```
"""
def sync_log(), do: Mnesia.sync_log()
end

0 comments on commit aa6f719

Please sign in to comment.