Erlang:stop/start之后的表状态

Erlang:stop/start之后的表状态,erlang,mnesia,Erlang,Mnesia,这是我代码的相关部分 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])),

这是我代码的相关部分

 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[信息]记忆开始
14:36:44.168[信息]节点上已启动应用程序记忆cdapbroker@6371550eb22c
[{access\u mode,read\u write},{active\u replica,[]},{all\u nodes,['cdapbroker@6371550eb22c“]},{arity,10},{attributes,[appname,apptype,命名空间,healthcheckurl,metricsurl,url,connectionurl,serviceendpoints,creationtime]},{checkpoints,[]},{commit_work,[]},{cookie,{1489761297736523772,-576460752303422911,1},'cdapbroker@6371550eb22c'}},{cstruct,{cstruct,application,set,[],['cdapbroker@6371550eb22c“]、[]、[]、0、读写、false、[]、[]、false、应用程序、[appname、apptype、命名空间、healthcheckurl、metricsurl、url、connectionurl、serviceendpoints、creationtime]、[]、[]、[]、[]、{{1489761297736523772,-576460752303422911,1}”cdapbroker@6371550eb22c“},{2,0},[]},{光盘拷贝,['cdapbroker@6371550eb22c']},{disc_only_copies,[]},{external_copies,[]},{frag_properties,[]},{index_info,{index,set,[]},{load_force,false},{load_node,unknown},{load_order,0},{load_原因,unknown},{本地_内容,false},{多数,false},{节点,{主节点,[]},{内存,未定义},{节点,未知},{加载},未知},未知},{顺序,0},{加载},{原因,未知},{未知},{原因,未知},{本地},未知},{内容,应用程序记录集,{10},{,{size,undefined},{snmp,[]},{storage\u properties,[]},{storage\u type,disc\u copies},{subscribers,[]},{type,set},{user\u properties,[]},{version,{2,0},[]},{where\u to\u commit,[]},{where\u-to\u-read,where\u-to-write,[]},{where\u-to-write,[]},{wild\u-pattern,{application,{application,},{version,{version,{version,{version,{version,{version,{version,{2,0},{2,0},{2,0
14:36:44.169[信息]应用程序表已存在
14:36:44.178[错误]
堆栈跟踪错误:
应用程序\u主机:启动\u it\u旧/4行273
cdapbroker_应用程序:开始/2第65行
错误:{badmatch,{中止,{不存在,应用程序}
14:36:44.179[错误]0邻居的崩溃报告进程退出,原因为:{badmatch,{中止,{no_exists,application}}}}在application_master:init/4第134行
14:36:44.179[信息]应用程序cdapbroker退出,原因为:{badmatch,{中止,{no_exists,Application}
Eshell V8.2.1(使用^G中止)


我试图让我的表在停止-启动后保持,但我不理解上面的内容。

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

我必须补充:

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

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

我目前正在调查这是否与时间延迟有关。旁注:您可以创建如下“通配符”记录:
#application{u='}
,而不是在元组中输入确切数量的字段。@Legossia感谢您的提示!
ok = mnesia:wait_for_tables([application], 30000),