Content-Length: 374720 | pFad | http://github.com/naver/arcus-memcached/commit/ea8296a80989ea100b45b264047cc414fb61860d

44 CLEANUP : add map at long query detection · naver/arcus-memcached@ea8296a · GitHub
Skip to content

Commit

Permalink
CLEANUP : add map at long query detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ehgml961017 committed Jan 18, 2019
1 parent f13a0e8 commit ea8296a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/memcached/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct iovec {
#define JHPARK_OLD_SMGET_INTERFACE
#define MAX_EFLAG_COMPARE_COUNT 100

#define ADD_LONGQ_MAP

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
16 changes: 15 additions & 1 deletion lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
#define LONGQ_INPUT_SIZE 500 /* the size of input(time, ip, command, argument) */

static EXTENSION_LOGGER_DESCRIPTOR *mc_logger;
#ifdef ADD_LONGQ_MAP
static char *command_str[LONGQ_COMMAND_NUM] = {"sop get","mop delete", "mop get", "lop insert", "lop delete", "lop get",
"bop delete", "bop get", "bop count", "bop gbp"};
#else
static char *command_str[LONGQ_COMMAND_NUM] = {"sop get", "lop insert", "lop delete", "lop get",
"bop delete", "bop get", "bop count", "bop gbp"};

#endif
/* lqdetect buffer structure */
struct lq_detect_buffer {
char *data;
Expand Down Expand Up @@ -224,6 +228,10 @@ static bool lqdetect_dupcheck(char *key, enum lq_detect_command cmd, struct lq_d
}
}
break;
#ifdef ADD_LONGQ_MAP
case LQCMD_MOP_DELETE:
case LQCMD_MOP_GET:
#endif
case LQCMD_SOP_GET:
for(ii = 0; ii < count; ii++) {
if (arg->count == 0) {
Expand Down Expand Up @@ -276,13 +284,19 @@ static void lqdetect_write(char client_ip[], char *key, enum lq_detect_command c
case LQCMD_SOP_GET:
snprintf(bufptr, length, "%s %s\n", key, arg->range);
break;
#ifdef ADD_LONGQ_MAP
case LQCMD_MOP_DELETE:
#endif
case LQCMD_LOP_DELETE:
if (arg->delete_or_drop == 2) {
snprintf(bufptr, length, "%s %s %s\n", key, arg->range, "drop");
} else {
snprintf(bufptr, length, "%s %s\n", key, arg->range);
}
break;
#ifdef ADD_LONGQ_MAP
case LQCMD_MOP_GET:
#endif
case LQCMD_LOP_GET:
if (arg->delete_or_drop != 0) {
snprintf(bufptr, length, "%s %s %s\n", key, arg->range,
Expand Down
4 changes: 4 additions & 0 deletions lqdetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
/* detect long query target command */
enum lq_detect_command {
LQCMD_SOP_GET=0,
#ifdef ADD_LONGQ_MAP
LQCMD_MOP_DELETE,
LQCMD_MOP_GET,
#endif
LQCMD_LOP_INSERT,
LQCMD_LOP_DELETE,
LQCMD_LOP_GET,
Expand Down
60 changes: 60 additions & 0 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,33 @@ static void process_mop_delete_complete(conn *c) {
c->coll_numkeys, flist, c->coll_drop, &del_count, &dropped, 0);
}

#ifdef ADD_LONGQ_MAP
#ifdef DETECT_LONG_QUERY
/*long query detection*/
if (lqdetect_in_use && ret == ENGINE_SUCCESS) {
if (lqdetect_discriminant(del_count)) {
struct lq_detect_argument argument;
char *bufptr = argument.range;

if (c->coll_numkeys == 0) {
snprintf(bufptr, 4, "all");
} else {
snprintf(bufptr, 16, "%d", c->coll_numkeys);
}
argument.overhead = del_count;
argument.count = c->coll_numkeys;
argument.delete_or_drop = 0;
if (c->coll_drop) {
argument.delete_or_drop = 2;
}

if (! lqdetect_save_cmd(c->client_ip, c->coll_key, LQCMD_MOP_DELETE, &argument)) {
lqdetect_in_use = false;
}
}
}
#endif
#endif
if (ret == ENGINE_EWOULDBLOCK) {
c->ewouldblock = true;
ret = ENGINE_SUCCESS;
Expand Down Expand Up @@ -2110,6 +2137,35 @@ static void process_mop_get_complete(conn *c)
delete, drop_if_empty, elem_array, &elem_count, &flags, &dropped, 0);
}

#ifdef ADD_LONGQ_MAP
#ifdef DETECT_LONG_QUERY
/* long query detection */
if (lqdetect_in_use && ret == ENGINE_SUCCESS) {
if (lqdetect_discriminant(elem_count)) {
struct lq_detect_argument argument;
char *bufptr = argument.range;

if (c->coll_numkeys == 0) {
snprintf(bufptr, 4, "all");
} else {
snprintf(bufptr, 16, "%d", c->coll_numkeys);
}
argument.overhead = elem_count;
argument.count = c->coll_numkeys;
argument.delete_or_drop = 0;
if (drop_if_empty) {
argument.delete_or_drop = 2;
} else if (delete) {
argument.delete_or_drop = 1;
}

if (! lqdetect_save_cmd(c->client_ip, c->coll_key, LQCMD_MOP_GET, &argument)) {
lqdetect_in_use = false;
}
}
}
#endif
#endif
if (ret == ENGINE_EWOULDBLOCK) {
c->ewouldblock = true;
ret = ENGINE_SUCCESS;
Expand Down Expand Up @@ -9785,6 +9841,10 @@ static void lqdetect_show(conn *c)
{
char *shorted_str[LONGQ_COMMAND_NUM] = {
"sop get command entered count :",
#ifdef ADD_LONGQ_MAP
"mop delete command entered count :",
"mop get command entered count :",
#endif
"lop insert command entered count :",
"lop delete command entered count :",
"lop get command entered count :",
Expand Down

0 comments on commit ea8296a

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/naver/arcus-memcached/commit/ea8296a80989ea100b45b264047cc414fb61860d

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy