MXS-1985: Kill connections inside workers
The LocalClient micro-client required a reference to the session that was valid at construction time. This is the reason why the previous implementation used dcb_foreach to first gather the targets and then execute queries on them. By replacing this reference with pointers to the raw data it requires, we lift the requirement of the orignating session being alive at construction time. Now that the LocalClient no longer holds a reference to the session, the killing of the connection does not have to be done on the same thread that started the process. This prevents the deadlock that occurred when concurrect dcb_foreach calls were made. Replaced the unused dcb_foreach_parallel with a version of dcb_foreach that allows iteration of DCBs local to this worker. The dcb_foreach_local is the basis upon which all DCB access outside of administrative tasks should be built on. This change will introduce a regression in functionality: The client will no longer receive an error if no connections match the KILL query criteria. This is done to avoid having to synchronize the workers after they have performed the killing of their own connections.
This commit is contained in:
@ -25,20 +25,15 @@
|
||||
|
||||
static const uint32_t poll_events = EPOLLIN | EPOLLOUT | EPOLLET | ERROR_EVENTS;
|
||||
|
||||
LocalClient::LocalClient(MXS_SESSION* session, int fd):
|
||||
LocalClient::LocalClient(MYSQL_session* session, MySQLProtocol* proto, int fd):
|
||||
m_state(VC_WAITING_HANDSHAKE),
|
||||
m_sock(fd),
|
||||
m_expected_bytes(0),
|
||||
m_client({}),
|
||||
m_protocol({}),
|
||||
m_client(*session),
|
||||
m_protocol(*proto),
|
||||
m_self_destruct(false)
|
||||
{
|
||||
MXS_POLL_DATA::handler = LocalClient::poll_handler;
|
||||
MySQLProtocol* client = (MySQLProtocol*)session->client_dcb->protocol;
|
||||
m_protocol.charset = client->charset;
|
||||
m_protocol.client_capabilities = client->client_capabilities;
|
||||
m_protocol.extra_capabilities = client->extra_capabilities;
|
||||
gw_get_shared_session_auth_info(session->client_dcb, &m_client);
|
||||
}
|
||||
|
||||
LocalClient::~LocalClient()
|
||||
@ -237,7 +232,7 @@ uint32_t LocalClient::poll_handler(struct mxs_poll_data* data, int wid, uint32_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
LocalClient* LocalClient::create(MXS_SESSION* session, const char* ip, uint64_t port)
|
||||
LocalClient* LocalClient::create(MYSQL_session* session, MySQLProtocol* proto, const char* ip, uint64_t port)
|
||||
{
|
||||
LocalClient* rval = NULL;
|
||||
sockaddr_storage addr;
|
||||
@ -245,7 +240,7 @@ LocalClient* LocalClient::create(MXS_SESSION* session, const char* ip, uint64_t
|
||||
|
||||
if (fd > 0 && (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0 || errno == EINPROGRESS))
|
||||
{
|
||||
LocalClient* relay = new (std::nothrow) LocalClient(session, fd);
|
||||
LocalClient* relay = new (std::nothrow) LocalClient(session, proto, fd);
|
||||
|
||||
if (relay)
|
||||
{
|
||||
@ -271,7 +266,7 @@ LocalClient* LocalClient::create(MXS_SESSION* session, const char* ip, uint64_t
|
||||
return rval;
|
||||
}
|
||||
|
||||
LocalClient* LocalClient::create(MXS_SESSION* session, SERVICE* service)
|
||||
LocalClient* LocalClient::create(MYSQL_session* session, MySQLProtocol* proto, SERVICE* service)
|
||||
{
|
||||
LocalClient* rval = NULL;
|
||||
LISTENER_ITERATOR iter;
|
||||
@ -282,7 +277,7 @@ LocalClient* LocalClient::create(MXS_SESSION* session, SERVICE* service)
|
||||
if (listener->port > 0)
|
||||
{
|
||||
/** Pick the first network listener */
|
||||
rval = create(session, "127.0.0.1", service->ports->port);
|
||||
rval = create(session, proto, "127.0.0.1", service->ports->port);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -290,7 +285,7 @@ LocalClient* LocalClient::create(MXS_SESSION* session, SERVICE* service)
|
||||
return rval;
|
||||
}
|
||||
|
||||
LocalClient* LocalClient::create(MXS_SESSION* session, SERVER* server)
|
||||
LocalClient* LocalClient::create(MYSQL_session* session, MySQLProtocol* proto, SERVER* server)
|
||||
{
|
||||
return create(session, server->name, server->port);
|
||||
return create(session, proto, server->name, server->port);
|
||||
}
|
||||
|
Reference in New Issue
Block a user