fix(mysql): fix the problem of data loss and bad match when mysql is disconnected
This commit is contained in:
parent
e1ae06a132
commit
bc37556963
|
@ -408,20 +408,34 @@ on_sql_query(
|
||||||
LogMeta = #{connector => InstId, sql => SQLOrKey, state => State},
|
LogMeta = #{connector => InstId, sql => SQLOrKey, state => State},
|
||||||
?TRACE("QUERY", "mysql_connector_received", LogMeta),
|
?TRACE("QUERY", "mysql_connector_received", LogMeta),
|
||||||
Worker = ecpool:get_client(PoolName),
|
Worker = ecpool:get_client(PoolName),
|
||||||
{ok, Conn} = ecpool_worker:client(Worker),
|
case ecpool_worker:client(Worker) of
|
||||||
?tp(
|
{ok, Conn} ->
|
||||||
mysql_connector_send_query,
|
?tp(
|
||||||
#{sql_func => SQLFunc, sql_or_key => SQLOrKey, data => Data}
|
mysql_connector_send_query,
|
||||||
),
|
#{sql_func => SQLFunc, sql_or_key => SQLOrKey, data => Data}
|
||||||
|
),
|
||||||
|
do_sql_query(SQLFunc, Conn, SQLOrKey, Data, Timeout, LogMeta);
|
||||||
|
{error, disconnected} ->
|
||||||
|
?SLOG(
|
||||||
|
error,
|
||||||
|
LogMeta#{
|
||||||
|
msg => "mysql_connector_do_sql_query_failed",
|
||||||
|
reason => worker_is_disconnected
|
||||||
|
}
|
||||||
|
),
|
||||||
|
{error, {recoverable_error, disconnected}}
|
||||||
|
end.
|
||||||
|
|
||||||
|
do_sql_query(SQLFunc, Conn, SQLOrKey, Data, Timeout, LogMeta) ->
|
||||||
try mysql:SQLFunc(Conn, SQLOrKey, Data, Timeout) of
|
try mysql:SQLFunc(Conn, SQLOrKey, Data, Timeout) of
|
||||||
{error, disconnected} = Result ->
|
{error, disconnected} ->
|
||||||
?SLOG(
|
?SLOG(
|
||||||
error,
|
error,
|
||||||
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),
|
||||||
Result;
|
{error, {recoverable_error, disconnected}};
|
||||||
{error, not_prepared} = Error ->
|
{error, not_prepared} = Error ->
|
||||||
?tp(
|
?tp(
|
||||||
mysql_connector_prepare_query_failed,
|
mysql_connector_prepare_query_failed,
|
||||||
|
|
Loading…
Reference in New Issue