Avoid excessive logging of SQL failures

This commit is contained in:
Evgeniy Khramtsov 2017-12-17 19:46:55 +03:00
parent 515f8b22c0
commit 5b42fc1d0d
13 changed files with 54 additions and 93 deletions

View File

@ -71,8 +71,7 @@ set_password(User, Server, Password) ->
case ejabberd_sql:sql_transaction(Server, F) of
{atomic, _} ->
ok;
{aborted, Reason} ->
?ERROR_MSG("failed to write to SQL table: ~p", [Reason]),
{aborted, _} ->
{error, db_failure}
end.
@ -115,9 +114,7 @@ get_password(User, Server) ->
iterationcount = IterationCount}};
{selected, []} ->
error;
Err ->
?ERROR_MSG("Failed to read password for user ~s@~s: ~p",
[User, Server, Err]),
_ ->
error
end.
@ -125,9 +122,7 @@ remove_user(User, Server) ->
case del_user(Server, User) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete user ~s@~s: ~p",
[User, Server, Err]),
_ ->
{error, db_failure}
end.

View File

@ -57,9 +57,7 @@ store(R) ->
"expire=%(Expire)d"]) of
ok ->
ok;
Err ->
?ERROR_MSG("Failed to write to SQL 'oauth_token' table: ~p",
[Err]),
_ ->
{error, db_failure}
end.

View File

@ -61,8 +61,7 @@ register_route(Domain, ServerHost, LocalHint, _, Pid) ->
"local_hint=%(LocalHintS)s"]) of
ok ->
ok;
Err ->
?ERROR_MSG("failed to update 'route' table: ~p", [Err]),
_ ->
{error, db_failure}
end.
@ -75,8 +74,7 @@ unregister_route(Domain, _, Pid) ->
"and pid=%(PidS)s and node=%(Node)s")) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete from 'route' table: ~p", [Err]),
_ ->
{error, db_failure}
end.
@ -90,8 +88,7 @@ find_routes(Domain) ->
fun(Row) ->
row_to_route(Domain, Row)
end, Rows)};
Err ->
?ERROR_MSG("failed to select from 'route' table: ~p", [Err]),
_ ->
{error, db_failure}
end.
@ -101,8 +98,7 @@ get_all_routes() ->
?SQL("select @(domain)s from route where domain <> server_host")) of
{selected, Domains} ->
{ok, [Domain || {Domain} <- Domains]};
Err ->
?ERROR_MSG("failed to select from 'route' table: ~p", [Err]),
_ ->
{error, db_failure}
end.

View File

@ -80,8 +80,7 @@ set_session(#session{sid = {Now, Pid}, usr = {U, LServer, R},
"info=%(InfoS)s"]) of
ok ->
ok;
Err ->
?ERROR_MSG("failed to update 'sm' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -93,8 +92,7 @@ delete_session(#session{usr = {_, LServer, _}, sid = {Now, Pid}}) ->
?SQL("delete from sm where usec=%(TS)d and pid=%(PidS)s")) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete from 'sm' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -117,8 +115,7 @@ get_sessions(LServer) ->
catch _:{bad_node, _} -> []
end
end, Rows);
Err ->
?ERROR_MSG("failed to select from 'sm' table: ~p", [Err]),
_Err ->
[]
end.
@ -135,8 +132,7 @@ get_sessions(LUser, LServer) ->
catch _:{bad_node, _} -> []
end
end, Rows)};
Err ->
?ERROR_MSG("failed to select from 'sm' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.

View File

@ -158,18 +158,24 @@ sql_call(Host, Msg) ->
case ejabberd_sql_sup:get_random_pid(Host) of
none -> {error, <<"Unknown Host">>};
Pid ->
p1_fsm:sync_send_event(Pid,{sql_cmd, Msg,
p1_time_compat:monotonic_time(milli_seconds)},
query_timeout(Host))
sync_send_event(Pid,{sql_cmd, Msg,
p1_time_compat:monotonic_time(milli_seconds)},
query_timeout(Host))
end;
_State -> nested_op(Msg)
end.
keep_alive(Host, PID) ->
p1_fsm:sync_send_event(PID,
{sql_cmd, {sql_query, ?KEEPALIVE_QUERY},
p1_time_compat:monotonic_time(milli_seconds)},
query_timeout(Host)).
sync_send_event(PID,
{sql_cmd, {sql_query, ?KEEPALIVE_QUERY},
p1_time_compat:monotonic_time(milli_seconds)},
query_timeout(Host)).
sync_send_event(Pid, Msg, Timeout) ->
try p1_fsm:sync_send_event(Pid, Msg, Timeout)
catch _:{Reason, {p1_fsm, _, _}} ->
{error, Reason}
end.
-spec sql_query_t(sql_query()) -> sql_query_result().
@ -270,6 +276,7 @@ sqlite_file(Host) ->
%%% Callback functions from gen_fsm
%%%----------------------------------------------------------------------
init([Host, StartInterval]) ->
process_flag(trap_exit, true),
case ejabberd_config:get_option({sql_keepalive_interval, Host}) of
undefined ->
ok;
@ -1077,6 +1084,8 @@ query_timeout(LServer) ->
timer:seconds(
ejabberd_config:get_option({sql_query_timeout, LServer}, 60)).
check_error({error, Why} = Err, _Query) when Why == killed ->
Err;
check_error({error, Why} = Err, #sql_query{} = Query) ->
?ERROR_MSG("SQL query '~s' at ~p failed: ~p",
[Query#sql_query.hash, Query#sql_query.loc, Why]),

View File

@ -86,7 +86,7 @@ init([Host]) ->
get_pids(Host) ->
Rs = mnesia:dirty_read(sql_pool, Host),
[R#sql_pool.pid || R <- Rs].
[R#sql_pool.pid || R <- Rs, is_process_alive(R#sql_pool.pid)].
get_random_pid(Host) ->
case get_pids(Host) of

View File

@ -59,8 +59,7 @@ open_session(SID, Pid) ->
"pid=%(PidS)s"]) of
ok ->
ok;
Err ->
?ERROR_MSG("failed to update 'bosh' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -69,8 +68,7 @@ close_session(SID) ->
?MYNAME, ?SQL("delete from bosh where sid=%(SID)s")) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete from 'bosh' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -84,8 +82,7 @@ find_session(SID) ->
end;
{selected, []} ->
{error, notfound};
Err ->
?ERROR_MSG("failed to select 'bosh' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.

View File

@ -63,9 +63,7 @@ caps_write(LServer, NodePair, Features) ->
sql_write_features_t(NodePair, Features)) of
{atomic, _} ->
ok;
{aborted, Reason} ->
?ERROR_MSG("Failed to write to SQL 'caps_features' table: ~p",
[Reason]),
{aborted, _Reason} ->
{error, db_failure}
end.

View File

@ -48,8 +48,7 @@ enable(LUser, LServer, LResource, NS) ->
"node=%(NodeS)s"]) of
ok ->
ok;
Err ->
?ERROR_MSG("failed to update 'carboncopy' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -60,8 +59,7 @@ disable(LUser, LServer, LResource) ->
"and %(LServer)H and resource=%(LResource)s")) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete from 'carboncopy' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -73,8 +71,7 @@ list(LUser, LServer) ->
{selected, Rows} ->
{ok, [{Resource, NS, binary_to_atom(Node, latin1)}
|| {Resource, NS, Node} <- Rows]};
Err ->
?ERROR_MSG("failed to select from 'carboncopy' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.

View File

@ -51,9 +51,7 @@ get_last(LUser, LServer) ->
error;
{selected, [{TimeStamp, Status}]} ->
{ok, {TimeStamp, Status}};
Reason ->
?ERROR_MSG("failed to get last for user ~s@~s: ~p",
[LUser, LServer, Reason]),
_Reason ->
{error, db_failure}
end.
@ -65,9 +63,7 @@ store_last_info(LUser, LServer, TimeStamp, Status) ->
"state=%(Status)s"]) of
ok ->
ok;
Err ->
?ERROR_MSG("failed to store last activity for ~s@~s: ~p",
[LUser, LServer, Err]),
_Err ->
{error, db_failure}
end.

View File

@ -187,12 +187,10 @@ get_rooms(LServer, Host) ->
#muc_room{name_host = {Room, Host},
opts = mod_muc:opts_to_binary(OptsD2)}
end, RoomOpts);
Err ->
?ERROR_MSG("failed to get rooms subscribers: ~p", [Err]),
_Err ->
[]
end;
Err ->
?ERROR_MSG("failed to get rooms: ~p", [Err]),
_Err ->
[]
end.
@ -266,7 +264,6 @@ register_online_room(ServerHost, Room, Host, Pid) ->
ok ->
ok;
Err ->
?ERROR_MSG("failed to update 'muc_online_room': ~p", [Err]),
Err
end.
@ -290,8 +287,7 @@ find_online_room(ServerHost, Room, Host) ->
end;
{selected, []} ->
error;
Err ->
?ERROR_MSG("failed to select 'muc_online_room': ~p", [Err]),
_Err ->
error
end.
@ -302,8 +298,7 @@ count_online_rooms(ServerHost, Host) ->
"where host=%(Host)s")) of
{selected, [{Num}]} ->
Num;
Err ->
?ERROR_MSG("failed to select 'muc_online_room': ~p", [Err]),
_Err ->
0
end.
@ -319,8 +314,7 @@ get_online_rooms(ServerHost, Host, _RSM) ->
catch _:{bad_node, _} -> []
end
end, Rows);
Err ->
?ERROR_MSG("failed to select 'muc_online_room': ~p", [Err]),
_Err ->
[]
end.
@ -340,7 +334,6 @@ register_online_user(ServerHost, {U, S, R}, Room, Host) ->
ok ->
ok;
Err ->
?ERROR_MSG("failed to update 'muc_online_users': ~p", [Err]),
Err
end.
@ -359,8 +352,7 @@ count_online_rooms_by_user(ServerHost, U, S) ->
"username=%(U)s and server=%(S)s")) of
{selected, [{Num}]} ->
Num;
Err ->
?ERROR_MSG("failed to select 'muc_online_users': ~p", [Err]),
_Err ->
0
end.
@ -371,8 +363,7 @@ get_online_rooms_by_user(ServerHost, U, S) ->
"username=%(U)s and server=%(S)s")) of
{selected, Rows} ->
Rows;
Err ->
?ERROR_MSG("failed to select 'muc_online_users': ~p", [Err]),
_Err ->
[]
end.
@ -424,8 +415,7 @@ get_subscribed_rooms(LServer, Host, Jid) ->
" and host=%(Host)s")) of
{selected, Subs} ->
[jid:make(Room, Host, <<>>) || {Room} <- Subs];
Error ->
?ERROR_MSG("Error when fetching subscribed rooms ~p", [Error]),
_Error ->
[]
end.

View File

@ -69,7 +69,6 @@ register_stream(SID, Pid) ->
{atomic, _} ->
ok;
{aborted, Reason} ->
?ERROR_MSG("failed to register stream: ~p", [Reason]),
{error, Reason}
end.
@ -82,7 +81,6 @@ unregister_stream(SID) ->
{atomic, _} ->
ok;
{aborted, Reason} ->
?ERROR_MSG("failed to unregister stream: ~p", [Reason]),
{error, Reason}
end.
@ -133,7 +131,6 @@ activate_stream(SID, IJID, MaxConnections, _Node) ->
{aborted, {limit, _, _} = Limit} ->
{error, Limit};
{aborted, Reason} ->
?ERROR_MSG("failed to activate bytestream: ~p", [Reason]),
{error, Reason}
end.

View File

@ -57,8 +57,7 @@ store_session(LUser, LServer, NowTS, PushJID, Node, XData) ->
"xml=%(XML)s"]) of
ok ->
{ok, {NowTS, PushLJID, Node, XData}};
Err ->
?ERROR_MSG("Failed to update 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -77,8 +76,7 @@ lookup_session(LUser, LServer, PushJID, Node) ->
{ok, {NowTS, PushLJID, Node, XData}};
{selected, []} ->
{error, notfound};
Err ->
?ERROR_MSG("Failed to select from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -95,8 +93,7 @@ lookup_session(LUser, LServer, NowTS) ->
{ok, {NowTS, PushLJID, Node, XData}};
{selected, []} ->
{error, notfound};
Err ->
?ERROR_MSG("Failed to select from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -115,8 +112,7 @@ lookup_sessions(LUser, LServer, PushJID) ->
XData = decode_xdata(XML, LUser, LServer),
{NowTS, PushLJID, Node, XData}
end, Rows)};
Err ->
?ERROR_MSG("Failed to select from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -134,8 +130,7 @@ lookup_sessions(LUser, LServer) ->
PushLJID = jid:tolower(jid:decode(Service)),
{NowTS, PushLJID,Node, XData}
end, Rows)};
Err ->
?ERROR_MSG("Failed to select from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -153,8 +148,7 @@ lookup_sessions(LServer) ->
PushLJID = jid:tolower(jid:decode(Service)),
{NowTS, PushLJID, Node, XData}
end, Rows)};
Err ->
?ERROR_MSG("Failed to select from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -166,8 +160,7 @@ delete_session(LUser, LServer, NowTS) ->
"username=%(LUser)s and %(LServer)H and timestamp=%(TS)d")) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.
@ -179,8 +172,7 @@ delete_old_sessions(LServer, Time) ->
"and %(LServer)H")) of
{updated, _} ->
ok;
Err ->
?ERROR_MSG("failed to delete from 'push_session' table: ~p", [Err]),
_Err ->
{error, db_failure}
end.