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

Add ability to force alternative upsert implementation in mysql

This commit is contained in:
Paweł Chmielowski 2023-08-18 11:46:26 +02:00
parent b29f87a978
commit 00c76003cb
3 changed files with 19 additions and 4 deletions

View File

@ -143,6 +143,7 @@
-export([sm_use_cache/0, sm_use_cache/1]). -export([sm_use_cache/0, sm_use_cache/1]).
-export([sql_connect_timeout/0, sql_connect_timeout/1]). -export([sql_connect_timeout/0, sql_connect_timeout/1]).
-export([sql_database/0, sql_database/1]). -export([sql_database/0, sql_database/1]).
-export([sql_flags/0, sql_flags/1]).
-export([sql_keepalive_interval/0, sql_keepalive_interval/1]). -export([sql_keepalive_interval/0, sql_keepalive_interval/1]).
-export([sql_odbc_driver/0, sql_odbc_driver/1]). -export([sql_odbc_driver/0, sql_odbc_driver/1]).
-export([sql_password/0, sql_password/1]). -export([sql_password/0, sql_password/1]).
@ -964,6 +965,13 @@ sql_database() ->
sql_database(Host) -> sql_database(Host) ->
ejabberd_config:get_option({sql_database, Host}). ejabberd_config:get_option({sql_database, Host}).
-spec sql_flags() -> ['mysql_alternative_upsert'].
sql_flags() ->
sql_flags(global).
-spec sql_flags(global | binary()) -> ['mysql_alternative_upsert'].
sql_flags(Host) ->
ejabberd_config:get_option({sql_flags, Host}).
-spec sql_keepalive_interval() -> 'undefined' | pos_integer(). -spec sql_keepalive_interval() -> 'undefined' | pos_integer().
sql_keepalive_interval() -> sql_keepalive_interval() ->
sql_keepalive_interval(global). sql_keepalive_interval(global).

View File

@ -424,6 +424,8 @@ opt_type(sql_username) ->
econf:binary(); econf:binary();
opt_type(sql_prepared_statements) -> opt_type(sql_prepared_statements) ->
econf:bool(); econf:bool();
opt_type(sql_flags) ->
econf:list_or_single(econf:enum([mysql_alternative_upsert]), [sorted, unique]);
opt_type(trusted_proxies) -> opt_type(trusted_proxies) ->
econf:either(all, econf:list(econf:ip_mask())); econf:either(all, econf:list(econf:ip_mask()));
opt_type(use_cache) -> opt_type(use_cache) ->
@ -708,6 +710,7 @@ options() ->
{sql_start_interval, timer:seconds(30)}, {sql_start_interval, timer:seconds(30)},
{sql_username, <<"ejabberd">>}, {sql_username, <<"ejabberd">>},
{sql_prepared_statements, true}, {sql_prepared_statements, true},
{sql_flags, []},
{trusted_proxies, []}, {trusted_proxies, []},
{validate_stream, false}, {validate_stream, false},
{websocket_origin, []}, {websocket_origin, []},

View File

@ -1148,7 +1148,11 @@ get_db_version(#state{db_type = pgsql} = State) ->
?WARNING_MSG("Error getting pgsql version: ~p", [Res]), ?WARNING_MSG("Error getting pgsql version: ~p", [Res]),
State State
end; end;
get_db_version(#state{db_type = mysql} = State) -> get_db_version(#state{db_type = mysql, host = Host} = State) ->
DefaultUpsert = case lists:member(mysql_alternative_upsert, ejabberd_option:sql_flags(Host)) of
true -> 1;
_ -> 0
end,
case mysql_to_odbc(p1_mysql_conn:squery(State#state.db_ref, case mysql_to_odbc(p1_mysql_conn:squery(State#state.db_ref,
[<<"select version();">>], self(), [<<"select version();">>], self(),
[{timeout, 5000}, [{timeout, 5000},
@ -1160,10 +1164,10 @@ get_db_version(#state{db_type = mysql} = State) ->
V = ((bin_to_int(V1)*1000)+bin_to_int(V2))*1000+bin_to_int(V3), V = ((bin_to_int(V1)*1000)+bin_to_int(V2))*1000+bin_to_int(V3),
TypeA = binary_to_atom(Type, utf8), TypeA = binary_to_atom(Type, utf8),
Flags = case TypeA of Flags = case TypeA of
'MariaDB' -> 0; 'MariaDB' -> DefaultUpsert;
_ when V >= 5007026 andalso V < 8000000 -> 1; _ when V >= 5007026 andalso V < 8000000 -> 1;
_ when V >= 8000020 -> 1; _ when V >= 8000020 -> 1;
_ -> 0 _ -> DefaultUpsert
end, end,
State#state{db_version = {V, TypeA, Flags}}; State#state{db_version = {V, TypeA, Flags}};
{match, [V1, V2, V3]} -> {match, [V1, V2, V3]} ->
@ -1171,7 +1175,7 @@ get_db_version(#state{db_type = mysql} = State) ->
Flags = case V of Flags = case V of
_ when V >= 5007026 andalso V < 8000000 -> 1; _ when V >= 5007026 andalso V < 8000000 -> 1;
_ when V >= 8000020 -> 1; _ when V >= 8000020 -> 1;
_ -> 0 _ -> DefaultUpsert
end, end,
State#state{db_version = {V, unknown, Flags}}; State#state{db_version = {V, unknown, Flags}};
_ -> _ ->