Re: Can not use mnesia disc_copies

Yao Bao <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <[email protected]>
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 <[email protected]> 写道:
> 
> 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@nohost,{already_exists,nonode@nohost}}}
> ==== 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@nohost]
> stopped db nodes   = [] 
> master node tables = []
> remote             = []
> ram_copies         = [schema]
> disc_copies        = []
> disc_only_copies   = []
> [{nonode@nohost,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@nohost,{already_exists,nonode@nohost}}}, Y: ok, Z: {aborted,
>                                                                            {bad_type,
>                                                                             chat_room,
>                                                                             disc_copies,
>                                                                             nonode@nohost}}
> 
> I guess my usage for mnesia might be wrong, but I have no clue.
> 
> Cheers,
> Yao
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.