25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

* src/odbc/ejabberd_odbc.erl: Restart the database connection when it's lost or it reaches timeout. Set transaction isolation level to SERIALIZABLE when establishing connection.

SVN Revision: 1510
This commit is contained in:
Jérôme Sautret 2008-08-04 13:41:16 +00:00
parent bc8fd0607b
commit 60308df929

View File

@ -166,13 +166,27 @@ init([Host]) ->
%% {stop, Reason, State} (terminate/2 is called) %% {stop, Reason, State} (terminate/2 is called)
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_call({sql_query, Query}, _From, State) -> handle_call({sql_query, Query}, _From, State) ->
Reply = sql_query_internal(State, Query), case sql_query_internal(State, Query) of
{reply, Reply, State}; % error returned by MySQL driver
{error, "query timed out"} = Reply ->
{stop, timeout, Reply, State};
% error returned by MySQL driver
{error, "Failed sending data on socket"++_} = Reply ->
{stop, closed, Reply, State};
Reply ->
{reply, Reply, State}
end;
handle_call({sql_transaction, F}, _From, State) -> handle_call({sql_transaction, F}, _From, State) ->
Reply = execute_transaction(State, F, ?MAX_TRANSACTION_RESTARTS), case execute_transaction(State, F, ?MAX_TRANSACTION_RESTARTS) of
{reply, Reply, State}; % error returned by MySQL driver
{error, "query timed out"} ->
{stop, timeout, State};
% error returned by MySQL driver
{error, "Failed sending data on socket"++_} = Reply ->
{stop, closed, Reply, State};
Reply ->
{reply, Reply, State}
end;
handle_call(_Request, _From, State) -> handle_call(_Request, _From, State) ->
Reply = ok, Reply = ok,
{reply, Reply, State}. {reply, Reply, State}.
@ -309,6 +323,11 @@ mysql_connect(Server, Port, DB, Username, Password) ->
{ok, Ref} -> {ok, Ref} ->
erlang:monitor(process, Ref), erlang:monitor(process, Ref),
mysql_conn:fetch(Ref, ["set names 'utf8';"], self()), mysql_conn:fetch(Ref, ["set names 'utf8';"], self()),
% needed to ensure the order of queries, specifically at
% roster subscription time (this can also be set-up in the
% MySQL configuration, but not at the database level):
mysql_conn:fetch(Ref, ["SET SESSION TRANSACTION ISOLATION LEVEL "
"SERIALIZABLE;"], self()),
{ok, #state{db_ref = Ref, db_type = mysql}}; {ok, #state{db_ref = Ref, db_type = mysql}};
{error, Reason} -> {error, Reason} ->
?ERROR_MSG("MySQL connection failed: ~p~n", [Reason]), ?ERROR_MSG("MySQL connection failed: ~p~n", [Reason]),