fix mnesia schema

This commit is contained in:
anlicheng 2025-05-19 17:56:47 +08:00
parent abedbd0f1e
commit 7705cd1f71
8 changed files with 27 additions and 9 deletions

View File

@ -169,7 +169,7 @@ handle_info({connect_reply, Reply}, State = #state{status = ?STATE_CONNECTING, t
case Reply of case Reply of
ok -> ok ->
AuthBin = auth_request(), AuthBin = auth_request(),
efka_transport:auth_request(TransportPid, AuthBin, 5000), efka_transport:auth_request(TransportPid, AuthBin, 50000),
{noreply, State#state{status = ?STATE_AUTH}}; {noreply, State#state{status = ?STATE_AUTH}};
{error, Reason} -> {error, Reason} ->
lager:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]), lager:debug("[efka_agent] connect failed, error: ~p, pid: ~p", [Reason, TransportPid]),
@ -293,7 +293,7 @@ handle_info({server_command, ?COMMAND_AUTH, <<Auth:8>>}, State = #state{transpor
{1, ?STATE_DENIED} -> {1, ?STATE_DENIED} ->
%% , %% ,
AuthRequestBin = auth_request(), AuthRequestBin = auth_request(),
efka_transport:auth_request(TransportPid, AuthRequestBin, 5000), efka_transport:auth_request(TransportPid, AuthRequestBin, 50000),
{noreply, State#state{status = ?STATE_AUTH}}; {noreply, State#state{status = ?STATE_AUTH}};
{0, _} -> {0, _} ->
%% %%

View File

@ -29,6 +29,7 @@ stop(_State) ->
%% %%
start_mnesia() -> start_mnesia() ->
%% %%
ensure_mnesia_schema(),
ok = mnesia:start(), ok = mnesia:start(),
Tables = mnesia:system_info(tables), Tables = mnesia:system_info(tables),
lager:debug("[efka_app] tables: ~p", [Tables]), lager:debug("[efka_app] tables: ~p", [Tables]),
@ -38,3 +39,20 @@ start_mnesia() ->
not lists:member(cache, Tables) andalso cache_model:create_table(), not lists:member(cache, Tables) andalso cache_model:create_table(),
not lists:member(task_log, Tables) andalso task_log_model:create_table(), not lists:member(task_log, Tables) andalso task_log_model:create_table(),
ok. ok.
-spec ensure_mnesia_schema() -> any().
ensure_mnesia_schema() ->
case mnesia:system_info(use_dir) of
true ->
lager:debug("[efka_app] mnesia schema exists"),
ok;
false ->
mnesia:stop(),
case mnesia:create_schema([node()]) of
ok -> ok;
{error, {_, {already_exists, _}}} -> ok;
Error ->
lager:debug("[iot_app] create mnesia schema failed with error: ~p", [Error]),
throw({init_schema, Error})
end
end.

View File

@ -19,7 +19,7 @@
create_table() -> create_table() ->
%% id生成器 %% id生成器
mnesia:create_table(cache, [ {atomic, ok} = mnesia:create_table(cache, [
{attributes, record_info(fields, cache)}, {attributes, record_info(fields, cache)},
{record_name, cache}, {record_name, cache},
{disc_copies, [node()]}, {disc_copies, [node()]},

View File

@ -15,7 +15,7 @@
create_table() -> create_table() ->
%% id生成器 %% id生成器
mnesia:create_table(id_generator, [ {atomic, ok} = mnesia:create_table(id_generator, [
{attributes, record_info(fields, id_generator)}, {attributes, record_info(fields, id_generator)},
{record_name, id_generator}, {record_name, id_generator},
{disc_copies, [node()]}, {disc_copies, [node()]},

View File

@ -20,7 +20,7 @@
create_table() -> create_table() ->
%% id生成器 %% id生成器
mnesia:create_table(service, [ {atomic, ok} = mnesia:create_table(service, [
{attributes, record_info(fields, service)}, {attributes, record_info(fields, service)},
{record_name, service}, {record_name, service},
{disc_copies, [node()]}, {disc_copies, [node()]},

View File

@ -19,7 +19,7 @@
create_table() -> create_table() ->
%% id生成器 %% id生成器
mnesia:create_table(task_log, [ {atomic, ok} = mnesia:create_table(task_log, [
{attributes, record_info(fields, task_log)}, {attributes, record_info(fields, task_log)},
{record_name, task_log}, {record_name, task_log},
{disc_copies, [node()]}, {disc_copies, [node()]},

View File

@ -3,7 +3,7 @@
{root_dir, "/tmp/efka/"}, {root_dir, "/tmp/efka/"},
{tcp_server, [ {tcp_server, [
{port, 18080} {port, 18088}
]}, ]},
{tls_server, [ {tls_server, [

View File

@ -1,4 +1,4 @@
-sname efka -name efka
-setcookie efka_cookie -setcookie efka_cookie