[erlang-questions] Replicated Mnesia table on dynamic nodes - how?
Jacek Furmankiewicz
jacek99@REDACTED
Tue Jul 7 21:15:05 CEST 2009
OK, so I created something like this to transparently handle creating or
connecting to an existing Mnesia cluster (depending if node is first one or
not).
Does it look OK to you or did I miss something?
*start_mnesia() ->
mnesia:start(),
DbNodes = mnesia:system_info(running_db_nodes),
error_logger:info_msg("Running Mnesia database nodes:: ~p~n",[DbNodes]),
%% register this node with Mnesia, handle if already part of it
case lists:any(fun(X) -> node() =:= X end, DbNodes) of
true ->
error_logger:info_msg("Current node already registered with
Mnesia.~n");
false ->
error_logger:info_msg("Current node being registered with
Mnesia.~n"),
mnesia:change_config (extra_db_nodes, [node()])
end,
%% ensure local schema is disk-based
case mnesia:change_table_copy_type(schema, node(), disc_copies) of
{atomic,ok} ->
error_logger:info_msg("Successfully modified Mnesia schema to be
disk-based.~n");
{aborted,{already_exists,schema,_Node,,disc_copies}} ->
error_logger:info_msg("Disk-based Mnesia schema found.~n");
Error ->
error_logger:error_msg("Unable to change Mnesia schema to
disc-based: ~p~n",[Error]),
init:halt(1)
end,
ok.*
More information about the erlang-questions
mailing list