[ejabberd] Disconnection from mysql database...

Adrian Almenar S. adrian at genexies.com
Tue Nov 28 19:17:52 MSK 2006


After some time trying to solve this problem, i have made some changes that
allow ejabberd using a load balanced mysql cluster to reconnect to another
database when 1 goes down. I have made this change on the code maybe it can
help a little bit fro future release.

By the way im no Erlang-Proficient programmer so any changes would be
welcome. ;)

Kind Regards,

Adrian Almenar


Index: odbc/ejabberd_odbc.erl
===================================================================
--- odbc/ejabberd_odbc.erl      (revision 683)
+++ odbc/ejabberd_odbc.erl      (working copy)
@@ -132,12 +132,18 @@
 %%          {stop, Reason, State}            (terminate/2 is called)
 %%----------------------------------------------------------------------
 handle_call({sql_query, Query}, _From, State) ->
-    Reply = sql_query_internal(State, Query),
-    {reply, Reply, State};
+    try Reply = sql_query_internal(State, Query),
+        {reply, Reply, State}
+    catch
+       error:ErrorMsg -> {stop, ErrorMsg, State}
+    end;

 handle_call({sql_transaction, F}, _From, State) ->
-    Reply = execute_transaction(State, F, ?MAX_TRANSACTION_RESTARTS),
-    {reply, Reply, State};
+    try Reply = execute_transaction(State, F, ?MAX_TRANSACTION_RESTARTS),
+        {reply, Reply, State}
+    catch
+       error:ErrorMsg -> {stop, ErrorMsg, State}
+    end;

 handle_call(_Request, _From, State) ->
     Reply = ok,
@@ -276,7 +282,7 @@
        {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),
+           timer:sleep(1000),
            {stop, mysql_connection_failed}
     end.


Kind Regards

-----Mensaje original-----
De: ejabberd-bounces at jabber.ru [mailto:ejabberd-bounces at jabber.ru] En nombre
de Adrian Almenar S.
Enviado el: martes, 31 de octubre de 2006 18:48
Para: ejabberd at jabber.ru
Asunto: [ejabberd] Disconnection from mysql database...

Hi everyone,

I've downloaded the latest release of ejabberd (1.1.2) and installed it on
Redhat ES4. Im actually having some problems with ejabberd because it gets
disconnected silently from the database and if it tries to access it again,
instead of establishing a new connection it will simply tell that cannot
connect.

This problem happens cause i have 2 mysql databases installed working in
clusterdb mode and load-balanced with keepalived. Keepalived has a 15 minute
persistence timeout but if in those 15 minutes the ejabberd server doesn't
talk to the database keepalived will drop the connection. Then ejabberd when
needs access to the DB connects again to the load balancer and sees the
connection was closed, it just fails, he doesn't try to connect again.

Is something im missing ?

I tried putting the persistence timeout to 60 minutes but this only will
delay the issue.

Any thoughts will be appreciated.

Kind Regards,

Adrian Almenar


_______________________________________________
ejabberd mailing list
ejabberd at jabber.ru
http://lists.jabber.ru/mailman/listinfo/ejabberd

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ejabberd.patch
Type: application/octet-stream
Size: 1329 bytes
Desc: not available
Url : http://lists.jabber.ru/pipermail/ejabberd/attachments/20061128/f95f4dad/ejabberd.obj


More information about the ejabberd mailing list