From 621139f90188b691a531297b220032888b7c4e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 18 May 2018 10:18:05 +0300 Subject: [PATCH] MXS-553: Use dcb_set for KILL command handling Now that the set of DCBs is stored in the session, it can be used to speed up the handling of the KILL command processing by stopping when the first related DCB is found. --- server/modules/protocol/MySQL/mysql_common.cc | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/server/modules/protocol/MySQL/mysql_common.cc b/server/modules/protocol/MySQL/mysql_common.cc index 01560c915..36fa2ed5c 100644 --- a/server/modules/protocol/MySQL/mysql_common.cc +++ b/server/modules/protocol/MySQL/mysql_common.cc @@ -1709,26 +1709,32 @@ struct KillInfo static bool kill_func(DCB *dcb, void *data) { + bool rval = true; KillInfo* info = (KillInfo*)data; - if (dcb->dcb_role == DCB_ROLE_BACKEND_HANDLER && - dcb->session->ses_id == info->target_id) + if (dcb->session->ses_id == info->target_id) { - MySQLProtocol* proto = (MySQLProtocol*)dcb->protocol; + for (auto it = dcb->session->dcb_set->begin(); it != dcb->session->dcb_set->end(); it++) + { + MySQLProtocol* proto = (MySQLProtocol*)(*it)->protocol; - if (proto->thread_id) - { - // DCB is connected and we know the thread ID so we can kill it - info->targets.push_back(std::make_pair(dcb->server, proto->thread_id)); - } - else - { - // DCB is not yet connected, send a hangup to forcibly close it - poll_fake_hangup_event(dcb); + if (proto->thread_id) + { + // DCB is connected and we know the thread ID so we can kill it + info->targets.push_back(std::make_pair((*it)->server, proto->thread_id)); + } + else + { + // DCB is not yet connected, send a hangup to forcibly close it + poll_fake_hangup_event(*it); + } } + + // Found the session, stop iterating over DCBs + rval = false; } - return true; + return rval; } void mxs_mysql_execute_kill(MXS_SESSION* issuer, uint64_t target_id, kill_type_t type)