diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-12-17 19:46:55 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-12-17 19:46:55 +0300 |
commit | 5b42fc1d0d6be7d83ed80deaa3f8cdf0ab11a61f (patch) | |
tree | e031ad72cc001d8be0504851deb7f6feb8dd1116 /src | |
parent | Rewrite ejabberd system monitor (diff) |
Avoid excessive logging of SQL failures
Diffstat (limited to '')
-rw-r--r-- | src/ejabberd_auth_sql.erl | 11 | ||||
-rw-r--r-- | src/ejabberd_oauth_sql.erl | 4 | ||||
-rw-r--r-- | src/ejabberd_router_sql.erl | 12 | ||||
-rw-r--r-- | src/ejabberd_sm_sql.erl | 12 | ||||
-rw-r--r-- | src/ejabberd_sql.erl | 23 | ||||
-rw-r--r-- | src/ejabberd_sql_sup.erl | 2 | ||||
-rw-r--r-- | src/mod_bosh_sql.erl | 9 | ||||
-rw-r--r-- | src/mod_caps_sql.erl | 4 | ||||
-rw-r--r-- | src/mod_carboncopy_sql.erl | 9 | ||||
-rw-r--r-- | src/mod_last_sql.erl | 8 | ||||
-rw-r--r-- | src/mod_muc_sql.erl | 26 | ||||
-rw-r--r-- | src/mod_proxy65_sql.erl | 3 | ||||
-rw-r--r-- | src/mod_push_sql.erl | 24 |
13 files changed, 54 insertions, 93 deletions
diff --git a/src/ejabberd_auth_sql.erl b/src/ejabberd_auth_sql.erl index 3f328c4a..af4ad282 100644 --- a/src/ejabberd_auth_sql.erl +++ b/src/ejabberd_auth_sql.erl @@ -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. diff --git a/src/ejabberd_oauth_sql.erl b/src/ejabberd_oauth_sql.erl index 14eaca6a..61e9986a 100644 --- a/src/ejabberd_oauth_sql.erl +++ b/src/ejabberd_oauth_sql.erl @@ -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. diff --git a/src/ejabberd_router_sql.erl b/src/ejabberd_router_sql.erl index c0264da3..d0ab98a6 100644 --- a/src/ejabberd_router_sql.erl +++ b/src/ejabberd_router_sql.erl @@ -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. diff --git a/src/ejabberd_sm_sql.erl b/src/ejabberd_sm_sql.erl index 55e21040..2dd884cd 100644 --- a/src/ejabberd_sm_sql.erl +++ b/src/ejabberd_sm_sql.erl @@ -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. diff --git a/src/ejabberd_sql.erl b/src/ejabberd_sql.erl index 8d30cf63..c4bf3a73 100644 --- a/src/ejabberd_sql.erl +++ b/src/ejabberd_sql.erl @@ -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]), diff --git a/src/ejabberd_sql_sup.erl b/src/ejabberd_sql_sup.erl index f7793eb2..759f8128 100644 --- a/src/ejabberd_sql_sup.erl +++ b/src/ejabberd_sql_sup.erl @@ -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 diff --git a/src/mod_bosh_sql.erl b/src/mod_bosh_sql.erl index 621e9d31..d732521a 100644 --- a/src/mod_bosh_sql.erl +++ b/src/mod_bosh_sql.erl @@ -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. diff --git a/src/mod_caps_sql.erl b/src/mod_caps_sql.erl index 5d4c1e93..3fa18f16 100644 --- a/src/mod_caps_sql.erl +++ b/src/mod_caps_sql.erl @@ -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. diff --git a/src/mod_carboncopy_sql.erl b/src/mod_carboncopy_sql.erl index 1b8e1e11..cda8c60d 100644 --- a/src/mod_carboncopy_sql.erl +++ b/src/mod_carboncopy_sql.erl @@ -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. diff --git a/src/mod_last_sql.erl b/src/mod_last_sql.erl index f0889e4e..0c86c72c 100644 --- a/src/mod_last_sql.erl +++ b/src/mod_last_sql.erl @@ -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. diff --git a/src/mod_muc_sql.erl b/src/mod_muc_sql.erl index 8aa6071c..0cb09775 100644 --- a/src/mod_muc_sql.erl +++ b/src/mod_muc_sql.erl @@ -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. diff --git a/src/mod_proxy65_sql.erl b/src/mod_proxy65_sql.erl index 18f8db14..715289db 100644 --- a/src/mod_proxy65_sql.erl +++ b/src/mod_proxy65_sql.erl @@ -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. diff --git a/src/mod_push_sql.erl b/src/mod_push_sql.erl index c82d9fc0..2a1d588e 100644 --- a/src/mod_push_sql.erl +++ b/src/mod_push_sql.erl @@ -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. |