mnesia initialization

Oleksii Semilietov spylik@REDACTED
Fri Nov 8 03:44:42 CET 2019


Actually you need first to check does table exists on local node or not.
Instead of just create_table you should have some routine like

init_table(TableName, TableDef) ->
   AllTables = mnesia:system_info(tables),
   case lists:member(TableName, AllTables) of
       false ->
              mnesia:create_table(TableName, TableDef);
       true ->
             wait_table(TableName)
       end
   .
In wait_table you should implement mnesia loading table routine.

The great starting point how to wrap up mnesia routine is in

https://github.com/rabbitmq/rabbitmq-server/blob/6cbd36bd79dd72817ec1ebe4a01c0d8a4bc7d69e/src/rabbit_mnesia.erl
and in
https://github.com/rabbitmq/rabbitmq-server/blob/6cbd36bd79dd72817ec1ebe4a01c0d8a4bc7d69e/src/rabbit_table.erl


On Fri, 8 Nov 2019 at 07:58, Karlo Kuna <kuna.prime@REDACTED> wrote:

> Hi,
>
> I have problem with mnesia initialization,
>
> I have a db_init function that initializes db so that if tables do not
> exist they are created (ram with disc_copies). For example:
>
> db_init() ->
>     mnesia:create_table(some_record,[{attributes, record_info(fields,
> some_record)},
>                                                                 {type,
> bag}, {disc_copies, [node()]}]).
>
> I'm running this function on the app start to make sure the table exists
> and is ready.
> However half of the time it destroys old table returning {atomic, ok} and
> another half it returns with already_exists. Also, this happens in the
> regular fashion, if I have n starts of application, even starts would
> destroy data and even wold keeps old data. I know that I am missing
> something probably obvious here but if anyone has any insights on why is
> this happening and how to fix it I would greatly appreciate it.
>
> Thank You,
> Karlo.
>


-- 
Best regards,
Alex [Oleksii Semilietov]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20191108/eede7716/attachment.htm>


More information about the erlang-questions mailing list