<html><head><meta http-equiv="Content-Type" content="text/html charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I think I find the cause of this issue.</div><div class=""><br class=""></div><div class="">I put 'mnesia' into applications:</div><div class=""><div class="">                {applications, [</div><div class="">                                 kernel,</div><div class="">                                 stdlib,</div><div class="">                                 mnesia,</div><div class="">                                 cowboy,</div><div class="">                                 jsx</div><div class="">                                ]},</div></div><div class="">The mnesia application started automatically because of this configuration.</div><div class="">mnesia:create_schema([node()]) failed because of this.</div><div class=""><br class=""></div><div class="">I removed 'mnesia' from applications, the disc_copies works fine then.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Yao</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">在 2020年10月31日,22:32,Yao Bao <<a href="mailto:by@meetlost.com" class="">by@meetlost.com</a>> 写道:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hello,<div class=""><br class=""></div><div class="">I have a web application which uses mnesia as the database.</div><div class=""><br class=""></div><div class="">Everything works fine when I use ram_copies.</div><div class="">However, I would like to use disc_copies for production. Then, I encounter an error when I start the database:</div><div class="">==== begin ====</div><div class="">X = mnesia:create_schema([node()])</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">X = {error,{nonode@nohost,{already_exists,nonode@nohost}}}</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Times; font-size: 14px;" class="">==== end ====</span></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">The output of <span style="font-family: Menlo; font-size: 11px;" class="">mnesia:info/0 is (from `$ rebar3 shell`):</span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">==== begin ====</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">---> Processes holding locks <--- </span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">---> Processes waiting for locks <--- </span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">---> Participant transactions <--- </span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">---> Coordinator transactions <---</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">---> Uncertain transactions <--- </span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">---> Active tables <--- </span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">schema         : with 1        records occupying 428      words of mem</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">===> System info in version "4.18", debug level = none <===</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">opt_disc. Directory "/Users/by/projects/mlchat_server/db_data" is NOT used.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">use fallback at restart = false</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">running db nodes   = [nonode@nohost]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">stopped db nodes   = [] </span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">master node tables = []</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">remote             = []</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">ram_copies         = [schema]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">disc_copies        = []</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">disc_only_copies   = []</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">[{nonode@nohost,ram_copies}] = [schema]</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">2 transactions committed, 1 aborted, 0 restarted, 0 logged to disc</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">0 held locks, 0 in queue; 0 local transactions, 0 remote</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">0 transactions waits for other nodes: []</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">ok</span></div></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">==== end ====</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">The "sys.config" for mnesia is:</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">{mnesia, [{dir, "./db_data"}]}</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">The documentation says:</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span class="code" style="font-family: mono, Courier, monospace; background-color: rgb(243, 243, 243); color: rgb(26, 26, 26); font-size: 16px; font-variant-ligatures: normal; orphans: 2; widows: 2;">mnesia:create_schema/1</span><span style="color: rgb(26, 26, 26); font-family: sans-serif; font-size: 16px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(254, 254, 254);" class=""> fails if any of the Erlang nodes given as </span><span class="code" style="font-family: mono, Courier, monospace; background-color: rgb(243, 243, 243); color: rgb(26, 26, 26); font-size: 16px; font-variant-ligatures: normal; orphans: 2; widows: 2;">DiscNodes</span><span style="color: rgb(26, 26, 26); font-family: sans-serif; font-size: 16px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(254, 254, 254);" class=""> are not alive, if Mnesia is running on any of the nodes, or if any of the nodes already have a schema.</span></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(26, 26, 26); font-family: sans-serif; font-size: 16px; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(254, 254, 254);" class=""><br class=""></span></div><div style="orphans: 2; widows: 2; margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Here is the code to start the database:</div><div style="orphans: 2; widows: 2; margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class="">start() -></div><div style="margin: 0px; line-height: normal;" class="">    X = mnesia:create_schema([node()]),</div><div style="margin: 0px; line-height: normal;" class="">    Y = mnesia:start(),</div><div style="margin: 0px; line-height: normal;" class="">    Z = mnesia:create_table(chat_room,</div><div style="margin: 0px; line-height: normal;" class="">                        [</div><div style="margin: 0px; line-height: normal;" class="">                         {type, ordered_set},</div><div style="margin: 0px; line-height: normal;" class="">                         {disc_copies, [node()]}, %% If I comment out this line, everything works fine.</div><div style="margin: 0px; line-height: normal;" class="">                         {attributes, record_info(fields, chat_room)}</div><div style="margin: 0px; line-height: normal;" class="">                        ]),</div><div style="margin: 0px; line-height: normal;" class="">    io:format("==== X: ~p, Y: ~p, Z: ~p~n", [X, Y, Z]).</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">And here is the output:</div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">1> ==== X: {error,{nonode@nohost,{already_exists,nonode@nohost}}}, Y: ok, Z: {aborted,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                                                                           {bad_type,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                                                                            chat_room,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                                                                            disc_copies,</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">                                                                            nonode@nohost}}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class="">I guess my usage for mnesia might be wrong, but I have no clue.</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div></div></div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Cheers,</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class="">Yao</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);" class=""><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>