additional handling of ER_CONNECTION_KILLED in mar.c

This commit is contained in:
hyung-hwan 2021-09-03 15:35:36 +00:00
parent 0be47defef
commit bbfbf53cd8
4 changed files with 19 additions and 11 deletions

View File

@ -49,7 +49,7 @@ static hio_ooch_t errstr_20[] = {'I', '/', 'O', ' ', 'e', 'r', 'r', 'o', 'r', '\
static hio_ooch_t errstr_21[] = {'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 's', 'i', 'o', 'n', ' ', 'e', 'r', 'r', 'o', 'r', '\0' };
static hio_ooch_t errstr_22[] = {'i', 'n', 's', 'u', 'f', 'f', 'i', 'c', 'i', 'e', 'n', 't', ' ', 'd', 'a', 't', 'a', ' ', 'f', 'o', 'r', ' ', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 's', 'i', 'o', 'n', '\0' };
static hio_ooch_t errstr_23[] = {'b', 'u', 'f', 'f', 'e', 'r', ' ', 'f', 'u', 'l', 'l', '\0' };
static hio_ooch_t errstr_24[] = {'n', 'o', 't', ' ', 'c', 'o', 'n', 'n', 'e', 'c', 't', 'e', 'd', '\0' };
static hio_ooch_t errstr_24[] = {'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'l', 'o', 's', 't', '\0' };
static hio_ooch_t errstr_25[] = {'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'r', 'e', 'f', 'u', 's', 'e', 'd', '\0' };
static hio_ooch_t errstr_26[] = {'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'r', 'e', 's', 'e', 't', '\0' };
static hio_ooch_t errstr_27[] = {'n', 'o', ' ', 'c', 'a', 'p', 'a', 'b', 'i', 'l', 'i', 't', 'y', '\0' };

View File

@ -99,7 +99,7 @@ enum hio_errnum_t
HIO_EECMORE, /**< insufficient data for encoding conversion */
HIO_EBUFFULL, /**< buffer full */
HIO_ENOTCON, /**< not connected */
HIO_ECONLOST, /**< connection lost */
HIO_ECONRF, /**< connection refused */
HIO_ECONRS, /**< connection reset */
HIO_ENOCAPA, /**< no capability */

View File

@ -577,7 +577,7 @@ int hio_svc_marc_querywithbchars (hio_svc_marc_t* marc, hio_oow_t flagged_sid, h
return -1;
}
/* the underlying socket of the device may get disconnected.
/* the underlying socket of the device might have gotten disconnected.
* in such a case, keep the enqueued query with sq->sent 0
* and defer actual sending and processing */
}

View File

@ -28,13 +28,19 @@
#if 0
#include <mariadb/mysql.h>
#include <mariadb/errmsg.h>
#include <mariadb/mysqld_error.h>
#else
#include <mysql.h>
#include <errmsg.h>
#include <mysqld_error.h>
#endif
#include <sys/socket.h>
#if !defined(ER_CONNECTION_KILLED)
# define ER_CONNECTION_KILLED (1927)
#endif
/* ========================================================================= */
static int dev_mar_make (hio_dev_t* dev, void* ctx)
@ -296,12 +302,14 @@ static int dev_mar_ioctl (hio_dev_t* dev, int cmd, void* arg)
if (err)
{
/* but there is an error */
if (err == 1) err = mysql_errno(rdev->hnd);
if (err == 1 || err == -1) err = mysql_errno(rdev->hnd);
hio_seterrbfmt (hio, HIO_ESYSERR, "%hs", mysql_error(rdev->hnd));
if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR)
hio_seterrbfmt (hio, HIO_ESYSERR, "%hs [code=%d]", mysql_error(rdev->hnd), err);
if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR || err == CR_COMMANDS_OUT_OF_SYNC || err == ER_CONNECTION_KILLED)
{
/* the underlying socket must have gotten closed by mysql_real_query_start() */
/* the underlying socket is closed by the mysql client library when this happens.
* so the mysql_get_socket(rdev->hnd) afterwards is never reliable */
const hio_ooch_t* prev_errmsg;
prev_errmsg = hio_backuperrmsg(hio);
@ -312,7 +320,7 @@ static int dev_mar_ioctl (hio_dev_t* dev, int cmd, void* arg)
watch_mysql (rdev, 0);
hio_dev_mar_halt (rdev); /* i can't keep this device alive regardless of the caller's post-action */
hio_seterrbfmt (hio, HIO_ENOTCON, "%js", prev_errmsg);
hio_seterrbfmt (hio, HIO_ECONLOST, "%js", prev_errmsg);
}
return -1;
}
@ -487,14 +495,14 @@ static int dev_evcb_mar_ready (hio_dev_t* dev, int events)
if (err)
{
/* query send failure */
if (err == 1) err = mysql_errno(rdev->hnd); /* err is set to 1 by mariadb-connector-c 3.1 as of this writing. let me work around it by fetching the error code */
if (err == 1 || err == -1) err = mysql_errno(rdev->hnd); /* err is set to 1 by mariadb-connector-c 3.1 as of this writing. let me work around it by fetching the error code */
if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR)
if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR || err == CR_COMMANDS_OUT_OF_SYNC || err == ER_CONNECTION_KILLED)
{
/*
preserving the error information here isn't very useful because
the info won't survive until on_disconnect() is called...
hio_seterrbfmt (hio, HIO_ENOTCON, "%hs", mysql_error(rdev->hnd));
hio_seterrbfmt (hio, HIO_ECONLOST, "%hs", mysql_error(rdev->hnd));
*/
rdev->broken = 1;