diff --git a/apps/mnesia_debug/src/mnesia_debug.erl b/apps/mnesia_debug/src/mnesia_debug.erl index 511a9d3..4f6c92c 100644 --- a/apps/mnesia_debug/src/mnesia_debug.erl +++ b/apps/mnesia_debug/src/mnesia_debug.erl @@ -100,11 +100,13 @@ create_schema(Nodes, Aliases) Alias :: alias(), Table :: table(), Properties :: proplists:proplist(), - Return :: table(). + Return :: ok + | {error, term()}. create_table(Alias, Table, Properties) -> ?LOG_DEBUG("~p",[{?MODULE, self(), create_table, [Alias, Table, Properties]}]), - throw({todo, ?MODULE, create_table, [Alias, Table, Properties]}). + % throw({todo, ?MODULE, create_table, [Alias, Table, Properties]}). + ok. %%-------------------------------------------------------------------- %% @doc Close an open and active table. This callback is called by @@ -128,7 +130,8 @@ create_table(Alias, Table, Properties) -> close_table(Alias, Table) -> ?LOG_DEBUG("~p",[{?MODULE, self(), close_table, [Alias, Table]}]), - throw({todo, ?MODULE, close_table, [Alias, Table]}). + % throw({todo, ?MODULE, close_table, [Alias, Table]}). + ok. %%-------------------------------------------------------------------- %% @doc Initialize the environment for the backend. This callback is @@ -156,11 +159,13 @@ init_backend() -> Table :: table(), Nodes :: nodes(), Properties :: proplists:proplist(), - Return :: ok. + Return :: ok + | {ok, Properties}. check_definition(Alias, Table, Nodes, Properties) -> ?LOG_DEBUG("~p",[{?MODULE, self(), check_definition, [Alias, Table, Nodes, Properties]}]), - throw({todo, ?MODULE, check_definition, [Alias, Table, Nodes, Properties]}). + % throw({todo, ?MODULE, check_definition, [Alias, Table, Nodes, Properties]}). + {ok, Properties}. %%-------------------------------------------------------------------- %% @doc Delete a key in an opened and active table. This callback is @@ -206,7 +211,8 @@ delete(Alias, Table, Key) -> delete_table(Alias, Table) -> ?LOG_DEBUG("~p",[{?MODULE, self(), delete_table, [Alias, Table]}]), - throw({todo, ?MODULE, delete_table, [Alias, Table]}). + %throw({todo, ?MODULE, delete_table, [Alias, Table]}). + ok. %%-------------------------------------------------------------------- %% @doc this callback is called by `mnesia_lib:db_fixtable/3'. diff --git a/apps/mnesia_debug/src/mnesia_debug_app.erl b/apps/mnesia_debug/src/mnesia_debug_app.erl new file mode 100644 index 0000000..e4585aa --- /dev/null +++ b/apps/mnesia_debug/src/mnesia_debug_app.erl @@ -0,0 +1,13 @@ +%%%=================================================================== +%%% @doc +%%% @end +%%%=================================================================== +-module(mnesia_debug_app). +-behavior(application). +-export([start/2, stop/1]). + +start(_StartType, _StartArgs) -> + mnesia_debug_sup:start_link(). + +stop(_State) -> + ok. diff --git a/apps/mnesia_debug/src/mnesia_debug_sup.erl b/apps/mnesia_debug/src/mnesia_debug_sup.erl new file mode 100644 index 0000000..c08d945 --- /dev/null +++ b/apps/mnesia_debug/src/mnesia_debug_sup.erl @@ -0,0 +1,19 @@ +%%%=================================================================== +%%% @doc +%%% @end +%%%=================================================================== +-module(mnesia_debug_sup). +-behaviour(supervisor). +-export([start_link/0]). +-export([init/1]). + +start_link() -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +init([]) -> + SupFlags = #{ strategy => one_for_all + , intensity => 0 + , period => 1 + }, + ChildSpecs = [], + {ok, {SupFlags, ChildSpecs}}. diff --git a/notes/0001-creating-custom-mnesia-backends-from-scratch/README.md b/notes/0001-creating-custom-mnesia-backends-from-scratch/README.md index ff8f0ce..522336d 100644 --- a/notes/0001-creating-custom-mnesia-backends-from-scratch/README.md +++ b/notes/0001-creating-custom-mnesia-backends-from-scratch/README.md @@ -85,7 +85,10 @@ mnesia:create_table( my_table , [{custom_mnesia_backend, [node()]} , {storage_properties, Storage}]). ``` - + + 8. Mnesia will call then `CustomModule:check_definition/4` function + callback and should check the properties of the table. + ## Backend Definition and Interfaces @@ -93,6 +96,17 @@ mnesia:create_table( my_table ### `Module:add_aliases/1` +Example of debugging message: + +```erlang +{ mnesia_debug +, <0.1032.0> +, add_aliases +, [[mnesia_backend_debug] + ] +} +``` + ### `Module:semantics/2` Based on `mnesia_rocksdb` implementation, `semantics/2` is needed to @@ -109,6 +123,138 @@ define which kind of plugins are supported by this backend. semantics(_Alias, any()) -> undefined. ``` +Example of debugging message: + +```erlang +{mnesia_debug,<0.1832.0>,semantics,[mnesia_backend_debug,index_types]} +{mnesia_debug,<0.1832.0>,semantics,[mnesia_backend_debug,storage]} +{mnesia_debug,<0.1832.0>,semantics,[mnesia_backend_debug,types]} +``` + +### `Module:check_definition/4` + +Example of debugging message, where `t3` is the name of table: + +```erlang +{ mnesia_debug +, <0.385.0> +, create_table +, [ mnesia_backend_debug + , t3 + , [ {name,t3} + , {type,set} + , {ram_copies,[]} + , {disc_copies,[]} + , {disc_only_copies,[]} + , {mnesia_backend_debug,[nonode@nohost]} + , {load_order,0} + , {access_mode,read_write} + , {majority,false} + , {index,[]} + , {snmp,[]} + , {local_content,false} + , {record_name,t3} + , {attributes,[key,val]} + , {user_properties,[]} + , {frag_properties,[]} + , {storage_properties,[{mnesia_backend_debug,[]}]} + , {cookie,{{1699140080964593704,-576460752303423483,1},nonode@nohost}} + , {version,{{2,0},[]}} + ] +]} +``` + +### `Module:close_table/2` + +Example of debugging message, where `t3` is the name of table: + +```erlang +{ mnesia_debug +, <0.1832.0> +, close_table +, [mnesia_backend_debug,t3] +} +``` + +Example of debugging message, where `t3` is the name of table: + +### `Module:delete_table/2` + +```erlang +{ mnesia_debug +, <0.2152.0> +, delete_table + , [mnesia_backend_debug,t3] +} +``` + +### `Module:create_table/3` + +Example of debugging message, where `t3` is the name of table: + +```erlang +{ mnesia_debug +, <0.385.0> +, create_table +, [ mnesia_backend_debug + , t3 + , [ {name,t3} + , {type,set} + , {ram_copies,[]} + , {disc_copies,[]} + , {disc_only_copies,[]} + , {mnesia_backend_debug,[nonode@nohost]} + , {load_order,0} + , {access_mode,read_write} + , {majority,false} + , {index,[]} + , {snmp,[]} + , {local_content,false} + , {record_name,t3} + , {attributes,[key,val]} + , {user_properties,[]} + , {frag_properties,[]} + , {storage_properties,[{mnesia_backend_debug,[]}]} + , {cookie,{{1699140992521145194,-576460752303422015,1},nonode@nohost}} + , {version,{{2,0},[]}} + ] +]} +``` + +### `Module:load_table/4` + +Example of debugging message, where `t3` is the name of table: + +```erlang +{ mnesia_debug +, <0.389.0> +, load_table +, [ mnesia_backend_debug + , t3 + , {dumper,create_table} + , [ {name,t3} + , {type,set} + , {ram_copies,[]} + , {disc_copies,[]} + , {disc_only_copies,[]} + , {mnesia_backend_debug,[nonode@nohost]} + , {load_order,0} + , {access_mode,read_write} + , {majority,false} + , {index,[]} + , {snmp,[]} + , {local_content,false} + , {record_name,t3} + , {attributes,[key,val]} + , {user_properties,[]} + , {frag_properties,[]} + , {storage_properties,[{mnesia_backend_debug,[]}]} + , {cookie,{{1699140992521145194,-576460752303422015,1},nonode@nohost}} + , {version,{{2,0},[]}} + ] +]} +``` + ## Backend Example - [ ] starting a custom backend with `mnesia_debug` backend (within