diff --git a/src/ejabberd_sql_sup.erl b/src/ejabberd_sql_sup.erl index 682414557..29099fce3 100644 --- a/src/ejabberd_sql_sup.erl +++ b/src/ejabberd_sql_sup.erl @@ -61,10 +61,6 @@ start_link(Host) -> ?MODULE, [Host]). init([Host]) -> - PoolSize = ejabberd_config:get_option( - {sql_pool_size, Host}, - fun(I) when is_integer(I), I>0 -> I end, - ?DEFAULT_POOL_SIZE), StartInterval = ejabberd_config:get_option( {sql_start_interval, Host}, fun(I) when is_integer(I), I>0 -> I end, @@ -76,6 +72,7 @@ init([Host]) -> (mssql) -> mssql; (odbc) -> odbc end, odbc), + PoolSize = get_pool_size(Type, Host), case Type of sqlite -> check_sqlite_db(Host); @@ -117,6 +114,23 @@ remove_pid(Host, Pid) -> end, mnesia:ets(F). +-spec get_pool_size(atom(), binary()) -> pos_integer(). +get_pool_size(SQLType, Host) -> + PoolSize = ejabberd_config:get_option( + {sql_pool_size, Host}, + fun(I) when is_integer(I), I>0 -> I end, + case SQLType of + sqlite -> 1; + _ -> ?DEFAULT_POOL_SIZE + end), + if PoolSize > 1 andalso SQLType == sqlite -> + ?WARNING_MSG("it's not recommended to set sql_pool_size > 1 for " + "sqlite, because it may cause race conditions", []); + true -> + ok + end, + PoolSize. + transform_options(Opts) -> lists:foldl(fun transform_options/2, [], Opts).