Only store established connections in the pool

If a connection has not been fully established (i.e. authentication has
been completed) then it should not be considered as a connection pool
candidate.
This commit is contained in:
Markus Mäkelä
2017-05-01 16:11:05 +03:00
committed by Markus Mäkelä
parent 2d7df3eb89
commit 4117dcf410
8 changed files with 30 additions and 10 deletions

View File

@ -43,7 +43,10 @@ struct session;
* close MaxScale close entry point for the socket * close MaxScale close entry point for the socket
* listen Create a listener for the protocol * listen Create a listener for the protocol
* auth Authentication entry point * auth Authentication entry point
* session Session handling entry point * session Session handling entry point
* auth_default Default authenticator name
* connlimit Maximum connection limit
* established Whether connection is fully established
* @endverbatim * @endverbatim
* *
* This forms the "module object" for protocol modules within the gateway. * This forms the "module object" for protocol modules within the gateway.
@ -62,9 +65,10 @@ typedef struct mxs_protocol
int32_t (*close)(struct dcb *); int32_t (*close)(struct dcb *);
int32_t (*listen)(struct dcb *, char *); int32_t (*listen)(struct dcb *, char *);
int32_t (*auth)(struct dcb *, struct server *, struct session *, GWBUF *); int32_t (*auth)(struct dcb *, struct server *, struct session *, GWBUF *);
int32_t (*session)(struct dcb *, void *); int32_t (*session)(struct dcb *, void *); // TODO: remove this, not used
char *(*auth_default)(); char *(*auth_default)();
int32_t (*connlimit)(struct dcb *, int limit); int32_t (*connlimit)(struct dcb *, int limit);
bool (*established)(struct dcb *);
} MXS_PROTOCOL; } MXS_PROTOCOL;
/** /**

View File

@ -1344,6 +1344,7 @@ static bool
dcb_maybe_add_persistent(DCB *dcb) dcb_maybe_add_persistent(DCB *dcb)
{ {
if (dcb->user != NULL if (dcb->user != NULL
&& (dcb->func.established == NULL || dcb->func.established(dcb))
&& strlen(dcb->user) && strlen(dcb->user)
&& dcb->server && dcb->server
&& dcb->server->persistpoolmax && dcb->server->persistpoolmax

View File

@ -85,7 +85,9 @@ MXS_MODULE* MXS_CREATE_MODULE()
cdc_listen, /* Create a listener */ cdc_listen, /* Create a listener */
NULL, /* Authentication */ NULL, /* Authentication */
NULL, /* Session */ NULL, /* Session */
cdc_default_auth /* default authentication */ cdc_default_auth, /* default authentication */
NULL,
NULL,
}; };
static MXS_MODULE info = static MXS_MODULE info =

View File

@ -81,7 +81,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /**< Authentication */ NULL, /**< Authentication */
NULL, /**< Session */ NULL, /**< Session */
httpd_default_auth, /**< Default authenticator */ httpd_default_auth, /**< Default authenticator */
NULL /**< Connection limit reached */ NULL, /**< Connection limit reached */
NULL
}; };
static MXS_MODULE info = static MXS_MODULE info =

View File

@ -80,6 +80,7 @@ static int gw_send_change_user_to_backend(char *dbname,
static void gw_send_proxy_protocol_header(DCB *backend_dcb); static void gw_send_proxy_protocol_header(DCB *backend_dcb);
static bool get_ip_string_and_port(struct sockaddr_storage *sa, char *ip, int iplen, static bool get_ip_string_and_port(struct sockaddr_storage *sa, char *ip, int iplen,
in_port_t *port_out); in_port_t *port_out);
static bool gw_connection_established(DCB* dcb);
/* /*
* The module entry point routine. It is this routine that * The module entry point routine. It is this routine that
@ -105,7 +106,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
gw_change_user, /* Authentication */ gw_change_user, /* Authentication */
NULL, /* Session */ NULL, /* Session */
gw_backend_default_auth, /* Default authenticator */ gw_backend_default_auth, /* Default authenticator */
NULL /* Connection limit reached */ NULL, /* Connection limit reached */
gw_connection_established
}; };
static MXS_MODULE info = static MXS_MODULE info =
@ -794,7 +796,7 @@ gw_read_and_write(DCB *dcb)
* The reply to an ignorable command is in the packet. Extract the * The reply to an ignorable command is in the packet. Extract the
* response type and discard the response. * response type and discard the response.
*/ */
uint8_t result; uint8_t result = 0xff;
gwbuf_copy_data(read_buffer, MYSQL_HEADER_LEN, 1, &result); gwbuf_copy_data(read_buffer, MYSQL_HEADER_LEN, 1, &result);
proto->ignore_replies--; proto->ignore_replies--;
ss_dassert(proto->ignore_replies >= 0); ss_dassert(proto->ignore_replies >= 0);
@ -957,7 +959,8 @@ static int gw_MySQLWrite_backend(DCB *dcb, GWBUF *queue)
CHK_DCB(dcb); CHK_DCB(dcb);
if (dcb->was_persistent && dcb->state == DCB_STATE_POLLING) if (dcb->was_persistent && dcb->state == DCB_STATE_POLLING &&
backend_protocol->protocol_auth_state == MXS_AUTH_STATE_COMPLETE)
{ {
ss_dassert(dcb->persistentstart == 0); ss_dassert(dcb->persistentstart == 0);
/** /**
@ -1967,3 +1970,9 @@ static bool get_ip_string_and_port(struct sockaddr_storage *sa,
} }
return success; return success;
} }
static bool gw_connection_established(DCB* dcb)
{
MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol;
return proto->protocol_auth_state == MXS_AUTH_STATE_COMPLETE;
}

View File

@ -102,7 +102,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /* Authentication */ NULL, /* Authentication */
NULL, /* Session */ NULL, /* Session */
gw_default_auth, /* Default authenticator */ gw_default_auth, /* Default authenticator */
gw_connection_limit /* Send error connection limit */ gw_connection_limit, /* Send error connection limit */
NULL
}; };
static MXS_MODULE info = static MXS_MODULE info =

View File

@ -183,7 +183,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /**< Authentication */ NULL, /**< Authentication */
NULL, /**< Session */ NULL, /**< Session */
mxsd_default_auth, /**< Default authenticator */ mxsd_default_auth, /**< Default authenticator */
NULL /**< Connection limit reached */ NULL, /**< Connection limit reached */
NULL
}; };
static MXS_MODULE info = static MXS_MODULE info =

View File

@ -102,7 +102,8 @@ MXS_MODULE* MXS_CREATE_MODULE()
NULL, /**< Authentication */ NULL, /**< Authentication */
NULL, /**< Session */ NULL, /**< Session */
telnetd_default_auth, /**< Default authenticator */ telnetd_default_auth, /**< Default authenticator */
NULL /**< Connection limit reached */ NULL, /**< Connection limit reached */
NULL
}; };
static MXS_MODULE info = static MXS_MODULE info =