close mnesia

This commit is contained in:
anlicheng 2024-08-12 22:40:20 +08:00
parent 2062c5612c
commit 230eee53dc

View File

@ -17,7 +17,7 @@ start(_StartType, _StartArgs) ->
erlang:system_flag(fullsweep_after, 16), erlang:system_flag(fullsweep_after, 16),
%% %%
start_mnesia(), % start_mnesia(),
{ok, SupPid} = iot_sup:start_link(), {ok, SupPid} = iot_sup:start_link(),
%% udp服务 %% udp服务
@ -69,31 +69,31 @@ start_udp_server() ->
lager:debug("[iot_app] the udp server start at: ~p", [Port]). lager:debug("[iot_app] the udp server start at: ~p", [Port]).
%% %%
start_mnesia() -> %start_mnesia() ->
%% % %%
ok = mnesia:start(), % ok = mnesia:start(),
Tables = mnesia:system_info(tables), % Tables = mnesia:system_info(tables),
%
LoadTables = [totalizator], % LoadTables = [totalizator],
case lists:all(fun(Tab) -> lists:member(Tab, Tables) end, LoadTables) of % case lists:all(fun(Tab) -> lists:member(Tab, Tables) end, LoadTables) of
true -> % true ->
lager:debug("[iot_app] waiting for mnesia start: ~p", [LoadTables]), % lager:debug("[iot_app] waiting for mnesia start: ~p", [LoadTables]),
%% % %%
mnesia:wait_for_tables(LoadTables, infinity), % mnesia:wait_for_tables(LoadTables, infinity),
lager:debug("[iot_app] waiting for mnesia end"); % lager:debug("[iot_app] waiting for mnesia end");
false -> % false ->
lager:warning("[iot_app] tables: ~p not exists, recreate mnesia schema", [LoadTables]), % lager:warning("[iot_app] tables: ~p not exists, recreate mnesia schema", [LoadTables]),
%% schema % %% schema
mnesia:stop(), % mnesia:stop(),
mnesia:delete_schema([node()]), % mnesia:delete_schema([node()]),
%
%% schema % %% schema
ok = mnesia:create_schema([node()]), % ok = mnesia:create_schema([node()]),
ok = mnesia:start(), % ok = mnesia:start(),
%
%% % %%
%% id生成器 % %% id生成器
%% mnesia_id_generator:create_table(), % %% mnesia_id_generator:create_table(),
%% % %%
mnesia_totalizator:create_table() % mnesia_totalizator:create_table()
end. % end.