mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Make first sql reconnect wait shorter time
This commit is contained in:
parent
43f36205bd
commit
73167ef1bd
@ -74,6 +74,7 @@
|
|||||||
{db_ref :: undefined | pid(),
|
{db_ref :: undefined | pid(),
|
||||||
db_type = odbc :: pgsql | mysql | sqlite | odbc | mssql,
|
db_type = odbc :: pgsql | mysql | sqlite | odbc | mssql,
|
||||||
db_version :: undefined | non_neg_integer(),
|
db_version :: undefined | non_neg_integer(),
|
||||||
|
reconnect_count = 0 :: non_neg_integer(),
|
||||||
host :: binary(),
|
host :: binary(),
|
||||||
pending_requests :: p1_queue:queue(),
|
pending_requests :: p1_queue:queue(),
|
||||||
overload_reported :: undefined | integer()}).
|
overload_reported :: undefined | integer()}).
|
||||||
@ -375,7 +376,7 @@ connecting(connect, #state{host = Host} = State) ->
|
|||||||
State1 = State#state{db_ref = Ref,
|
State1 = State#state{db_ref = Ref,
|
||||||
pending_requests = PendingRequests},
|
pending_requests = PendingRequests},
|
||||||
State2 = get_db_version(State1),
|
State2 = get_db_version(State1),
|
||||||
{next_state, session_established, State2}
|
{next_state, session_established, State2#state{reconnect_count = 0}}
|
||||||
catch _:Reason ->
|
catch _:Reason ->
|
||||||
handle_reconnect(Reason, State)
|
handle_reconnect(Reason, State)
|
||||||
end;
|
end;
|
||||||
@ -467,15 +468,19 @@ print_state(State) -> State.
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
handle_reconnect(Reason, #state{host = Host} = State) ->
|
handle_reconnect(Reason, #state{host = Host, reconnect_count = RC} = State) ->
|
||||||
StartInterval = ejabberd_option:sql_start_interval(Host),
|
StartInterval0 = ejabberd_option:sql_start_interval(Host),
|
||||||
|
StartInterval = case RC of
|
||||||
|
0 -> erlang:min(5000, StartInterval0);
|
||||||
|
_ -> StartInterval0
|
||||||
|
end,
|
||||||
?WARNING_MSG("~p connection failed:~n"
|
?WARNING_MSG("~p connection failed:~n"
|
||||||
"** Reason: ~p~n"
|
"** Reason: ~p~n"
|
||||||
"** Retry after: ~B seconds",
|
"** Retry after: ~B seconds",
|
||||||
[State#state.db_type, Reason,
|
[State#state.db_type, Reason,
|
||||||
StartInterval div 1000]),
|
StartInterval div 1000]),
|
||||||
p1_fsm:send_event_after(StartInterval, connect),
|
p1_fsm:send_event_after(StartInterval, connect),
|
||||||
{next_state, connecting, State}.
|
{next_state, connecting, State#state{reconnect_count = RC + 1}}.
|
||||||
|
|
||||||
run_sql_cmd(Command, From, State, Timestamp) ->
|
run_sql_cmd(Command, From, State, Timestamp) ->
|
||||||
case current_time() >= Timestamp of
|
case current_time() >= Timestamp of
|
||||||
|
Loading…
Reference in New Issue
Block a user