fix: bad return in retry prepare

This commit is contained in:
DDDHuang 2022-04-21 23:43:27 +08:00
parent 4b7a5bbf53
commit 9088752afa
2 changed files with 13 additions and 11 deletions

View File

@ -24,8 +24,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(MYSQL_HOST, "192.168.1.234"). -define(MYSQL_HOST, "mysql").
% -define(MYSQL_HOST, "mysql").
-define(MYSQL_RESOURCE, <<"emqx_authn_mysql_SUITE">>). -define(MYSQL_RESOURCE, <<"emqx_authn_mysql_SUITE">>).
-define(PATH, [authentication]). -define(PATH, [authentication]).

View File

@ -86,7 +86,6 @@ on_start(InstId, #{server := {Host, Port},
{pool_size, PoolSize}], {pool_size, PoolSize}],
PoolName = emqx_plugin_libs_pool:pool_name(InstId), PoolName = emqx_plugin_libs_pool:pool_name(InstId),
Prepares = maps:get(prepare_statement, Config, #{}), Prepares = maps:get(prepare_statement, Config, #{}),
io:format("Prepares ~p~n", [Prepares]),
State = init_prepare(#{poolname => PoolName, prepare_statement => Prepares}), State = init_prepare(#{poolname => PoolName, prepare_statement => Prepares}),
case emqx_plugin_libs_pool:start_pool(PoolName, ?MODULE, Options ++ SslOpts) of case emqx_plugin_libs_pool:start_pool(PoolName, ?MODULE, Options ++ SslOpts) of
ok -> {ok, State}; ok -> {ok, State};
@ -116,26 +115,30 @@ on_query(InstId, {Type, SQLOrKey, Params, Timeout}, AfterQuery,
LogMeta#{msg => "mysql_connector_do_sql_query_failed", reason => disconnected}), LogMeta#{msg => "mysql_connector_do_sql_query_failed", reason => disconnected}),
%% kill the poll worker to trigger reconnection %% kill the poll worker to trigger reconnection
_ = exit(Conn, restart), _ = exit(Conn, restart),
emqx_resource:query_failed(AfterQuery); emqx_resource:query_failed(AfterQuery),
Result;
{error, not_prepared} -> {error, not_prepared} ->
?SLOG(warning, ?SLOG(warning,
LogMeta#{msg => "mysql_connector_do_sql_query_failed", reason => not_prepared}), LogMeta#{msg => "mysql_connector_prepare_query_failed", reason => not_prepared}),
case prepare_sql(Prepares, PoolName) of case prepare_sql(Prepares, PoolName) of
ok -> ok ->
%% not return result, next loop will try again
on_query(InstId, {Type, SQLOrKey, Params, Timeout}, AfterQuery, State); on_query(InstId, {Type, SQLOrKey, Params, Timeout}, AfterQuery, State);
{error, Reason} -> {error, Reason} ->
?SLOG(error, ?SLOG(error,
LogMeta#{msg => "mysql_connector_do_sql_query_failed", reason => Reason}), LogMeta#{msg => "mysql_connector_do_prepare_failed", reason => Reason}),
emqx_resource:query_failed(AfterQuery) emqx_resource:query_failed(AfterQuery),
{error, Reason}
end; end;
{error, Reason} -> {error, Reason} ->
?SLOG(error, ?SLOG(error,
LogMeta#{msg => "mysql_connector_do_sql_query_failed", reason => Reason}), LogMeta#{msg => "mysql_connector_do_sql_query_failed", reason => Reason}),
emqx_resource:query_failed(AfterQuery); emqx_resource:query_failed(AfterQuery),
Result;
_ -> _ ->
emqx_resource:query_success(AfterQuery) emqx_resource:query_success(AfterQuery),
end, Result
Result. end.
mysql_function(sql) -> query; mysql_function(sql) -> query;
mysql_function(prepared_query) -> execute. mysql_function(prepared_query) -> execute.