Add HARD/SOFT to executed KILL commands

The HARD and SOFT keywords are parsed and added to the executed KILL
commands.
This commit is contained in:
Markus Mäkelä
2017-09-27 21:17:52 +03:00
parent 4dd6842447
commit 49b179bf69
3 changed files with 18 additions and 8 deletions

View File

@ -627,8 +627,10 @@ bool mxs_mysql_command_will_respond(uint8_t cmd);
/* Type of the kill-command sent by client. */
typedef enum kill_type
{
KT_CONNECTION,
KT_QUERY
KT_CONNECTION = (1 << 0),
KT_QUERY = (1 << 1),
KT_SOFT = (1 << 2),
KT_HARD = (1 << 3)
} kill_type_t;
void mxs_mysql_execute_kill(MXS_SESSION* issuer, uint64_t target_id, kill_type_t type);

View File

@ -1762,7 +1762,7 @@ static bool parse_kill_query(char *query, uint64_t *thread_id_out, kill_type_t *
const char WORD_SOFT[] = "SOFT";
const char DELIM[] = " \n\t";
kill_type_t kill_type = KT_CONNECTION;
int kill_type = KT_CONNECTION;
unsigned long long int thread_id = 0;
enum kill_parse_state_t
@ -1806,10 +1806,14 @@ static bool parse_kill_query(char *query, uint64_t *thread_id_out, kill_type_t *
get_next = true;
}
if (strncasecmp(token, WORD_HARD, sizeof(WORD_HARD) - 1) == 0 ||
strncasecmp(token, WORD_SOFT, sizeof(WORD_SOFT) - 1) == 0)
if (strncasecmp(token, WORD_HARD, sizeof(WORD_HARD) - 1) == 0)
{
/* This is an optional token and needs to be ignored */
kill_type |= KT_HARD;
get_next = true;
}
else if (strncasecmp(token, WORD_SOFT, sizeof(WORD_SOFT) - 1) == 0)
{
kill_type |= KT_SOFT;
get_next = true;
}
else
@ -1888,7 +1892,7 @@ static bool parse_kill_query(char *query, uint64_t *thread_id_out, kill_type_t *
else
{
*thread_id_out = thread_id;
*kt_out = kill_type;
*kt_out = (kill_type_t)kill_type;
return true;
}
}

View File

@ -1731,8 +1731,12 @@ void mxs_mysql_execute_kill(MXS_SESSION* issuer, uint64_t target_id, kill_type_t
it != info.targets.end(); it++)
{
LocalClient* client = LocalClient::create(issuer, it->first);
const char* hard = (type & KT_HARD) ? "HARD " :
(type & KT_SOFT) ? "SOFT " :
"";
const char* query = (type & KT_QUERY) ? "QUERY " : "";
std::stringstream ss;
ss << "KILL " << (type == KT_QUERY ? "QUERY " : "") << it->second;
ss << "KILL " << hard << query << it->second;
GWBUF* buffer = modutil_create_query(ss.str().c_str());
client->queue_query(buffer);
gwbuf_free(buffer);