【问题标题】:Erlang: mnesia weird table state after stop/startErlang:停止/启动后的mnesia奇怪的表状态
【发布时间】:2017-03-18 01:18:54
【问题描述】:

这是我的代码的相关部分

 N = node(),

 %set MNesia dir
 application:set_env(mnesia, dir, "/var/mnesia/"),
 %dont check status here, OK if already exists
 %stop if running, can't create schema if it is
 mnesia:stop(),
 %erlang:display(mnesia:delete_schema([N])),
 mnesia:create_schema([N]),
 %start MNesia, assert it works
 ok = mnesia:start(), %start MNesia, bomb if alreay started, should not happen
 lager:info("Mnesia started"),

 %erlang:display(mnesia:delete_table(application)),
 case mnesia:create_table(application,  [{attributes, record_info(fields, application)}, {disc_copies, [N]}]) of
     {aborted,{already_exists,application}} ->
         lager:info("Application table already exists");
     {atomic,ok} -> 
         lager:info(io_lib:format("Created application table on ~s", [N]))
 end,

 erlang:display(mnesia:table_info(application, all)),

 {atomic, Apps} = mnesia:transaction(fun() -> mnesia:match_object(application, {application, '_', '_', '_', '_', '_', '_', '_'    , '_', '_'}, read) end),
 erlang:display(Apps),

当我第一次启动我的应用程序时,一切正常:

14:34:57.736 [info] Mnesia started
14:34:57.736 [info] Application mnesia started on node cdapbroker@6371550eb22c
[{access_mode,read_write},{active_replicas,['cdapbroker@6371550eb22c']},{all_nodes,['cdapbroker@6371550eb22c']},{arity,10},{attributes,[appname,apptype,namespace,healthcheckurl,metricsurl,url,connectionurl,serviceendpoints,creationtime]},{checkpoints,[]},{commit_work,[]},{cookie,{{1489761297736523772,-576460752303422911,1},'cdapbroker@6371550eb22c'}},{cstruct,{cstruct,application,set,[],['cdapbroker@6371550eb22c'],[],[],0,read_write,false,[],[],false,application,[appname,apptype,namespace,healthcheckurl,metricsurl,url,connectionurl,serviceendpoints,creationtime],[],[],[],{{1489761297736523772,-576460752303422911,1},'cdapbroker@6371550eb22c'},{{2,0},[]}}},{disc_copies,['cdapbroker@6371550eb22c']},{disc_only_copies,[]},{external_copies,[]},{frag_properties,[]},{index,[]},{index_info,{index,set,[]}},{load_by_force,false},{load_node,'cdapbroker@6371550eb22c'},{load_order,0},{load_reason,{dumper,create_table}},{local_content,false},{majority,false},{master_nodes,[]},{memory,298},{ram_copies,[]},{record_name,application},{record_validation,{application,10,set}},{size,0},{snmp,[]},{storage_properties,[]},{storage_type,disc_copies},{subscribers,[]},{type,set},{user_properties,[]},{version,{{2,0},[]}},{where_to_commit,[{'cdapbroker@6371550eb22c',disc_copies}]},{where_to_read,'cdapbroker@6371550eb22c'},{where_to_wlock,{['cdapbroker@6371550eb22c'],false}},{where_to_write,['cdapbroker@6371550eb22c']},{wild_pattern,{application,'_','_','_','_','_','_','_','_','_'}}]
14:34:57.802 [info] Created application table on cdapbroker@6371550eb22c
[]

当我停止然后再次启动我的应用程序时,它显示应用程序表的详细信息,但随后在下一行声称它不存在

14:36:44.168 [info] Mnesia started
14:36:44.168 [info] Application mnesia started on node cdapbroker@6371550eb22c
[{access_mode,read_write},{active_replicas,[]},{all_nodes,['cdapbroker@6371550eb22c']},{arity,10},{attributes,[appname,apptype,namespace,healthcheckurl,metricsurl,url,connectionurl,serviceendpoints,creationtime]},{checkpoints,[]},{commit_work,[]},{cookie,{{1489761297736523772,-576460752303422911,1},'cdapbroker@6371550eb22c'}},{cstruct,{cstruct,application,set,[],['cdapbroker@6371550eb22c'],[],[],0,read_write,false,[],[],false,application,[appname,apptype,namespace,healthcheckurl,metricsurl,url,connectionurl,serviceendpoints,creationtime],[],[],[],{{1489761297736523772,-576460752303422911,1},'cdapbroker@6371550eb22c'},{{2,0},[]}}},{disc_copies,['cdapbroker@6371550eb22c']},{disc_only_copies,[]},{external_copies,[]},{frag_properties,[]},{index,[]},{index_info,{index,set,[]}},{load_by_force,false},{load_node,unknown},{load_order,0},{load_reason,unknown},{local_content,false},{majority,false},{master_nodes,[]},{memory,undefined},{ram_copies,[]},{record_name,application},{record_validation,{application,10,set}},{size,undefined},{snmp,[]},{storage_properties,[]},{storage_type,disc_copies},{subscribers,[]},{type,set},{user_properties,[]},{version,{{2,0},[]}},{where_to_commit,[]},{where_to_read,nowhere},{where_to_write,[]},{wild_pattern,{application,'_','_','_','_','_','_','_','_','_'}}]
14:36:44.169 [info] Application table already exists
14:36:44.178 [error]
Error Stacktrace:
application_master:start_it_old/4 line 273
cdapbroker_app:start/2 line 65
error:{badmatch,{aborted,{no_exists,application}}}
14:36:44.179 [error] CRASH REPORT Process <0.145.0> with 0 neighbours exited with reason: {badmatch,{aborted,{no_exists,application}}} in application_master:init/4 line 134
14:36:44.179 [info] Application cdapbroker exited with reason: {badmatch,{aborted,{no_exists,application}}}

Eshell V8.2.1(使用 ^G 中止)

我试图让我的表在停止启动后仍然存在,但我不明白上述内容。

【问题讨论】:

  • 我目前正在调查这是否与时间延迟有关..
  • 附注:您可以像这样创建一个“通配符”记录:#application{_ = '_'},而不是在一个元组中放入确切数量的字段。
  • @legoscia 感谢您的提示!

标签: erlang mnesia


【解决方案1】:

这是一个时间问题。我认为 MNesia 错误可能更具体..

我必须补充:

ok = mnesia:wait_for_tables([application], 30000),

我猜当表创建时(第一次启动时),表立即可用,但在停止/启动后它还没有“准备好”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多