mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
added get_random_pid/1 error handling
This commit is contained in:
parent
e9d104ec47
commit
ffe9f3c192
@ -140,9 +140,12 @@ sql_bloc(Host, F) -> sql_call(Host, {sql_bloc, F}).
|
|||||||
sql_call(Host, Msg) ->
|
sql_call(Host, Msg) ->
|
||||||
case get(?STATE_KEY) of
|
case get(?STATE_KEY) of
|
||||||
undefined ->
|
undefined ->
|
||||||
(?GEN_FSM):sync_send_event(ejabberd_odbc_sup:get_random_pid(Host),
|
case ejabberd_odbc_sup:get_random_pid(Host) of
|
||||||
{sql_cmd, Msg, now()},
|
none -> ?WARNING_MSG("SQL calling unknown host: ~p~n", [Host]);
|
||||||
?TRANSACTION_TIMEOUT);
|
Pid ->
|
||||||
|
(?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, now()},
|
||||||
|
?TRANSACTION_TIMEOUT)
|
||||||
|
end;
|
||||||
_State -> nested_op(Msg)
|
_State -> nested_op(Msg)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -82,8 +82,10 @@ get_pids(Host) ->
|
|||||||
[R#sql_pool.pid || R <- Rs].
|
[R#sql_pool.pid || R <- Rs].
|
||||||
|
|
||||||
get_random_pid(Host) ->
|
get_random_pid(Host) ->
|
||||||
Pids = get_pids(Host),
|
case get_pids(Host) of
|
||||||
lists:nth(erlang:phash(now(), length(Pids)), Pids).
|
[] -> none;
|
||||||
|
Pids -> lists:nth(erlang:phash(now(), length(Pids)), Pids)
|
||||||
|
end.
|
||||||
|
|
||||||
add_pid(Host, Pid) ->
|
add_pid(Host, Pid) ->
|
||||||
F = fun () ->
|
F = fun () ->
|
||||||
|
Loading…
Reference in New Issue
Block a user