Can not use mnesia disc_copies

Yao Bao by@REDACTED
Tue Nov 3 15:24:00 CET 2020


I think I find the cause of this issue.

I put 'mnesia' into applications:
                {applications, [
                                 kernel,
                                 stdlib,
                                 mnesia,
                                 cowboy,
                                 jsx
                                ]},
The mnesia application started automatically because of this configuration.
mnesia:create_schema([node()]) failed because of this.

I removed 'mnesia' from applications, the disc_copies works fine then.

Cheers,
Yao

> 在 2020年10月31日,22:32,Yao Bao <by@REDACTED> 写道:
> 
> Hello,
> 
> I have a web application which uses mnesia as the database.
> 
> Everything works fine when I use ram_copies.
> However, I would like to use disc_copies for production. Then, I encounter an error when I start the database:
> ==== begin ====
> X = mnesia:create_schema([node()])
> X = {error,{nonode@REDACTED,{already_exists,nonode@REDACTED}}}
> ==== end ====
> 
> The output of mnesia:info/0 is (from `$ rebar3 shell`):
> ==== begin ====
> ---> Processes holding locks <--- 
> ---> Processes waiting for locks <--- 
> ---> Participant transactions <--- 
> ---> Coordinator transactions <---
> ---> Uncertain transactions <--- 
> ---> Active tables <--- 
> schema         : with 1        records occupying 428      words of mem
> ===> System info in version "4.18", debug level = none <===
> opt_disc. Directory "/Users/by/projects/mlchat_server/db_data" is NOT used.
> use fallback at restart = false
> running db nodes   = [nonode@REDACTED]
> stopped db nodes   = [] 
> master node tables = []
> remote             = []
> ram_copies         = [schema]
> disc_copies        = []
> disc_only_copies   = []
> [{nonode@REDACTED,ram_copies}] = [schema]
> 2 transactions committed, 1 aborted, 0 restarted, 0 logged to disc
> 0 held locks, 0 in queue; 0 local transactions, 0 remote
> 0 transactions waits for other nodes: []
> ok
> ==== end ====
> 
> The "sys.config" for mnesia is:
> {mnesia, [{dir, "./db_data"}]}
> 
> The documentation says:
> mnesia:create_schema/1 fails if any of the Erlang nodes given as DiscNodes are not alive, if Mnesia is running on any of the nodes, or if any of the nodes already have a schema.
> 
> Here is the code to start the database:
> start() ->
>     X = mnesia:create_schema([node()]),
>     Y = mnesia:start(),
>     Z = mnesia:create_table(chat_room,
>                         [
>                          {type, ordered_set},
>                          {disc_copies, [node()]}, %% If I comment out this line, everything works fine.
>                          {attributes, record_info(fields, chat_room)}
>                         ]),
>     io:format("==== X: ~p, Y: ~p, Z: ~p~n", [X, Y, Z]).
> 
> And here is the output:
> 1> ==== X: {error,{nonode@REDACTED,{already_exists,nonode@REDACTED}}}, Y: ok, Z: {aborted,
>                                                                            {bad_type,
>                                                                             chat_room,
>                                                                             disc_copies,
>                                                                             nonode@REDACTED}}
> 
> I guess my usage for mnesia might be wrong, but I have no clue.
> 
> Cheers,
> Yao
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20201103/aa2a25f1/attachment.htm>


More information about the erlang-questions mailing list