]> granicus.if.org Git - ejabberd/commitdiff
* src/odbc/ejabberd_odbc.erl: Added a way to retry database
authorMickaël Rémond <mickael.remond@process-one.net>
Fri, 13 Jan 2006 18:05:10 +0000 (18:05 +0000)
committerMickaël Rémond <mickael.remond@process-one.net>
Fri, 13 Jan 2006 18:05:10 +0000 (18:05 +0000)
connection connect for 5 minutes when the connection is lost. No further
connection is retry after 5 minutes (EJAB-22 & EJAB-25)
* src/odbc/ejabberd_odbc_sup.erl: likewise

SVN Revision: 485

ChangeLog
src/odbc/ejabberd_odbc.erl
src/odbc/ejabberd_odbc_sup.erl

index 5798f1c852d58f5249d879c6f6056cc59033685e..6bb7b3e48a4a4b0aadf1361cf2642fa3406943ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@
        * src/mod_vcard_odbc.erl: likewise.
        * src/odbc/mysql.sql: Fixed MySQL database creation script: Was
        not properly working with all MySQL version.
+       * src/odbc/ejabberd_odbc.erl: Added a way to retry database
+       connection connect for 5 minutes when the connection is lost. No
+       further connection is retry after. 
+       * src/odbc/ejabberd_odbc_sup.erl: likewise.
        
 2006-01-13  Alexey Shchepin  <alexey@sevcom.net>
 
index 1634ecf0f2b35e4b11028f3a78f04f187b2ba21e..2be88c6bf420f430a2e1a4b65631d1a3767cf5f0 100644 (file)
@@ -171,6 +171,11 @@ code_change(_OldVsn, State, _Extra) ->
 %%          {noreply, State, Timeout} |
 %%          {stop, Reason, State}            (terminate/2 is called)
 %%----------------------------------------------------------------------
+%% We receive the down signal when we loose the MySQL connection (we are
+%% monitoring the connection)
+%% => We exit and let the supervisor restart the connection.
+handle_info({'DOWN', _MonitorRef, process, _Pid, _Info}, State) ->
+    {stop, connection_dropped, State};
 handle_info(_Info, State) ->
     {noreply, State}.
 
@@ -185,7 +190,6 @@ terminate(_Reason, _State) ->
 %%%----------------------------------------------------------------------
 %%% Internal functions
 %%%----------------------------------------------------------------------
-
 sql_query_internal(State, Query) ->
     case State#state.db_type of
        odbc ->
@@ -223,6 +227,8 @@ odbc_connect(SQLServer) ->
        {error, Reason} ->
            ?ERROR_MSG("ODBC connection (~s) failed: ~p~n",
                       [SQLServer, Reason]),
+           %% If we can't connect we wait for 30 seconds before retrying
+           timer:sleep(30000),
            {stop, odbc_connection_failed}
     end.
 
@@ -237,6 +243,8 @@ pgsql_connect(Server, DB, Username, Password) ->
            {ok, #state{db_ref = Ref, db_type = pgsql}};
        {error, Reason} ->
            ?ERROR_MSG("PostgreSQL connection failed: ~p~n", [Reason]),
+           %% If we can't connect we wait for 30 seconds before retrying
+           timer:sleep(30000),
            {stop, pgsql_connection_failed}
     end.
 
@@ -271,9 +279,12 @@ mysql_connect(Server, DB, Username, Password) ->
     NoLogFun = fun(_Level,_Format,_Argument) -> ok end,
     case mysql_conn:start(Server, ?MYSQL_PORT, Username, Password, DB, NoLogFun) of
        {ok, Ref} ->
+           erlang:monitor(process, Ref),
            {ok, #state{db_ref = Ref, db_type = mysql}};
        {error, Reason} ->
            ?ERROR_MSG("MySQL connection failed: ~p~n", [Reason]),
+           %% If we can't connect we wait for 30 seconds before retrying
+           timer:sleep(30000),
            {stop, mysql_connection_failed}
     end.
 
index 6d294a448833b3eee663f4bee18e88d16e3031c3..7bb3a583ff2a3cdd86e53aca42fab58a0227ae8f 100644 (file)
@@ -25,7 +25,7 @@ start_link(Host) ->
 init([Host]) ->
     % TODO
     N = 10,
-    {ok, {{one_for_one, 10, 1},
+    {ok, {{one_for_one, 10, 6},
          lists:map(
            fun(I) ->
                    {I,