]> granicus.if.org Git - ejabberd/commitdiff
Set 'sql_pool_size' to 1 by default for sqlite
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 21 Nov 2016 18:34:56 +0000 (21:34 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 21 Nov 2016 18:34:56 +0000 (21:34 +0300)
src/ejabberd_sql_sup.erl

index 682414557e83b50bcb88ec42d6f018012171d4c8..29099fce3f261edec51fa01bf951ac14d6a1b5e9 100644 (file)
@@ -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).