Erlang: create disk layout

If the Erlang application myapp requires mnesia to run, then it mnesiamust be included in the application resource file under the key applications, so if myapp is started, mnesia will start automatically - it node by default - opt_disc(OTP 18).

What if i want a discnode? I know that I can install -mnesia schema_location discon the command line, but this only works if the circuit already exists, which means that I have to do some initialization before starting myapp, is there an “OTP-ful” way without removing mnesiafrom applicationsso that avoid this initialization? The main goal is to turn init-then-start into start.

+4
source share
1 answer

This is incorrect from your post:

... mnesiashould be included in the application resource file in key applications, so if myapp is running, mnesia will start automatically.

Applications that you write as a value applicationsin a file .appdo not start automatically, but it says that they must be running before your application starts.


Imagine that we want to create an application foothat depends on mnesiawith some customization. One way is to run it in a file foo_app.erl:

-module(foo_app).
-behaviour(application).

-export([start/2, stop/1]).

start(_Type, _Args) ->
    mnesia:start().
    mnesia:change_table_copy_type(schema, node(), disc_copies),

    %% configure mnesia
    %% create your tables
    %% ...

    foo_sup:start_link().

stop(_State) ->
    ok.

Thus, he creates a scheme disc, whether it was created before or not.


. , mnesia applications foo.app.src ( foo.app), foo {error, {not_started, mnesia}}. , foo_app:start/2.

+5

Source: https://habr.com/ru/post/1624223/


All Articles