MXS-1366: Validate closed connections before pooling them
When a session is being closed in a controlled manner, i.e. a COM_QUIT is received from the client, it is possible to deduce from this fact that the backend connections are very likely to be idle. This can be used as an additional qualification that must be met by all connections before they can be candidates for connection pooling. This assumption will not hold with batched and asynchronous queries. In this case it is possible that the COM_QUIT is received from the client before even the first result from the backend is read. For this to work, the protocol module would need to track the number and state of expected responses.
This commit is contained in:
@ -991,6 +991,19 @@ gw_read_finish_processing(DCB *dcb, GWBUF *read_buffer, uint64_t capabilities)
|
||||
/** Reset error handler when routing of the new query begins */
|
||||
dcb->dcb_errhandle_called = false;
|
||||
|
||||
if (proto->current_command == MYSQL_COM_QUIT)
|
||||
{
|
||||
/** The client is closing the connection. We know that this will be the
|
||||
* last command the client sends so the backend connections are very likely
|
||||
* to be in an idle state.
|
||||
*
|
||||
* If the client is pipelining the queries (i.e. sending N request as
|
||||
* a batch and then expecting N responses) then it is possible that
|
||||
* the backend connections are not idle when the COM_QUIT is received.
|
||||
* In most cases we can assume that the connections are idle. */
|
||||
session_qualify_for_pool(session);
|
||||
}
|
||||
|
||||
if (rcap_type_required(capabilities, RCAP_TYPE_STMT_INPUT))
|
||||
{
|
||||
/**
|
||||
|
Reference in New Issue
Block a user