fix mnesia

This commit is contained in:
anlicheng 2026-05-10 22:37:25 +08:00
parent 634a3ece75
commit e4934eb43b
2 changed files with 16 additions and 46 deletions

View File

@ -15,27 +15,19 @@ start(_StartType, _StartArgs) ->
erlang:system_flag(fullsweep_after, 16),
try
%% mnesia
ok = iot_mnesia:start(),
%% http服务 supervisor simulator API
start_http_server(),
%% ssl服务
start_ssl_server(),
case iot_sup:start_link() of
{ok, _Pid} = Ok ->
Ok;
Error ->
stop_started_services(),
Error
end
ok = iot_mnesia:start()
catch
Class:Reason:Stack ->
stop_started_services(),
logger:warning("[iot_app] start failed, class: ~p, reason: ~p, stack: ~p", [Class, Reason, Stack]),
{error, Reason}
end.
logger:warning("[iot_app] start failed, class: ~p, reason: ~p, stack: ~p", [Class, Reason, Stack])
end,
%% http服务 supervisor simulator API
start_http_server(),
%% ssl服务
start_ssl_server(),
iot_sup:start_link().
stop(_State) ->
stop_started_services(),

View File

@ -17,21 +17,21 @@
-spec init() -> ok | {error, term()}.
init() ->
with_result(fun() ->
ok = ensure_persistent_dir(),
_ = mnesia:stop(),
ok = create_schema_if_missing(),
ok = start_mnesia(),
ok = mnesia:delete_schema([node()]),
ok = mnesia:create_schema([node()]),
ok = ensure_persistent_dir(),
ok = mnesia:start(),
ok = create_tables(),
ok = wait_for_tables(),
ok = stop(),
ok
end).
-spec start() -> ok | {error, term()}.
start() ->
with_result(fun() ->
ok = mnesia:start(),
ok = ensure_persistent_dir(),
ok = start_mnesia(),
ok = wait_for_tables(),
ok = verify_tables(),
log_runtime_info(),
@ -52,28 +52,6 @@ ensure_persistent_dir() ->
throw({mnesia_dir_required, node()})
end.
-spec create_schema_if_missing() -> ok.
create_schema_if_missing() ->
case mnesia:create_schema([node()]) of
ok ->
ok;
{error, {_, {already_exists, _}}} ->
ok;
{error, Reason} ->
throw({create_schema_failed, Reason})
end.
-spec start_mnesia() -> ok.
start_mnesia() ->
case mnesia:start() of
ok ->
ok;
{error, {already_started, mnesia}} ->
ok;
{error, Reason} ->
throw({start_mnesia_failed, Reason})
end.
-spec create_tables() -> ok.
create_tables() ->
case efka_client_store:ensure_table() of