From 964e935b322edabdc994f33fe86f7f124a8edce0 Mon Sep 17 00:00:00 2001 From: computerphilosopher Date: Tue, 6 Aug 2019 12:13:54 +0900 Subject: [PATCH] implement own lock --- cmd_in_second.c | 46 ++++-- cmd_in_second.h | 5 +- memcached.c | 398 ++++++++++++++++++++---------------------------- stats.c | 165 ++------------------ stats.h | 37 ----- t/bulk.t | 25 ++- 6 files changed, 237 insertions(+), 439 deletions(-) diff --git a/cmd_in_second.c b/cmd_in_second.c index b1b1e4681..4c341698d 100644 --- a/cmd_in_second.c +++ b/cmd_in_second.c @@ -37,6 +37,7 @@ typedef struct cmd_in_second_timer { int32_t front; int32_t rear; int32_t capacity; + int32_t last_elem_idx; int32_t circular_counter; } timertype; @@ -48,6 +49,7 @@ struct cmd_in_second { int32_t bulk_limit; int32_t log_per_timer; state cur_state; + pthread_mutex_t lock; }; static struct cmd_in_second this; @@ -61,9 +63,12 @@ static bool is_bulk_cmd() } const struct timeval* front_time = &this.timer.ring[this.timer.front]; - const struct timeval* rear_time = &this.timer.ring[this.timer.rear]; + const struct timeval* last_time = &this.timer.ring[this.timer.last_elem_idx]; - return rear_time->tv_sec - front_time->tv_sec <= 1; + //printf("%d\n", this.timer.last_elem_idx); + //assert(0); + + return last_time->tv_sec - front_time->tv_sec <= 1; } static void get_whole_cmd(char* whole_cmd) @@ -161,7 +166,6 @@ static void* buffer_flush_thread() static int32_t buffer_flush() { - this.cur_state = ON_FLUSHING; pthread_t tid; pthread_attr_t attr; @@ -191,12 +195,12 @@ static void buffer_add(const logtype* log) if (buffer_full) { if (is_bulk_cmd()) { + this.cur_state = ON_FLUSHING; buffer_flush(); return; } buffer->front = (buffer->front+1) % buffer->capacity; } - } static void timer_add() @@ -214,6 +218,7 @@ static void timer_add() return; }; + timer->last_elem_idx = timer->rear; timer->rear = (timer->rear+1) % timer->capacity; } @@ -226,7 +231,9 @@ static bool is_cmd_to_log(const char* collection_name, const char* cmd) bool cmd_in_second_write(const char* collection_name, const char* cmd, const char* key, const char* client_ip) { + pthread_mutex_lock(&this.lock); if (this.cur_state != ON_LOGGING || !is_cmd_to_log(collection_name, cmd)) { + pthread_mutex_unlock(&this.lock); return false; } @@ -241,38 +248,57 @@ bool cmd_in_second_write(const char* collection_name, const char* cmd, buffer_add(&log); this.timer.circular_counter = (this.timer.circular_counter+1) % this.log_per_timer; + pthread_mutex_unlock(&this.lock); return true; } +void cmd_in_second_init() +{ + assert("test"); + this.cur_state = NOT_STARTED; + pthread_mutex_init(&this.lock, NULL); + + this.buffer.front = 0; + this.buffer.rear = 0; + this.buffer.ring = NULL; + + this.timer.front = 0; + this.timer.rear = 0; + this.timer.capacity = 0; + this.timer.circular_counter = 0; + this.timer.last_elem_idx = 0; + this.timer.ring = NULL; +} + int32_t cmd_in_second_start(const char* collection_name, const char* cmd, const int32_t bulk_limit) { + pthread_mutex_lock(&this.lock); + if (this.cur_state != NOT_STARTED) { + pthread_mutex_unlock(&this.lock); return CMD_IN_SECOND_STARTED_ALREADY; } this.bulk_limit = bulk_limit; this.buffer.capacity = bulk_limit+1; - this.buffer.front = 0; - this.buffer.rear = 0; this.buffer.ring = (logtype*)malloc(this.buffer.capacity * sizeof(logtype)); if (this.buffer.ring == NULL) { + pthread_mutex_unlock(&this.lock); return CMD_IN_SECOND_NO_MEM; } this.log_per_timer = bulk_limit / 10 + (bulk_limit % 10 != 0); this.timer.capacity = this.log_per_timer + 1; - this.timer.front = 0; - this.timer.rear = 0; - this.timer.circular_counter = 0; this.timer.ring = (struct timeval*)malloc(this.timer.capacity * sizeof(struct timeval)); if (this.timer.ring == NULL) { free(this.buffer.ring); + pthread_mutex_unlock(&this.lock); return CMD_IN_SECOND_NO_MEM; } @@ -281,5 +307,7 @@ int32_t cmd_in_second_start(const char* collection_name, const char* cmd, this.cur_state = ON_LOGGING; + pthread_mutex_unlock(&this.lock); + return CMD_IN_SECOND_START; } diff --git a/cmd_in_second.h b/cmd_in_second.h index 34a63fd36..406b5b012 100644 --- a/cmd_in_second.h +++ b/cmd_in_second.h @@ -1,5 +1,5 @@ -#ifndef __CMD_IN_SECOND_LOG__ -#define __CMD_IN_SECOND_LOG__ +#ifndef __CMD_IN_SECOND_ +#define __CMD_IN_SECOND_ #endif #include @@ -10,5 +10,6 @@ #define CMD_IN_SECOND_STARTED_ALREADY 1 #define CMD_IN_SECOND_NO_MEM 2 +void cmd_in_second_init(void); int32_t cmd_in_second_start(const char* collection_name, const char* cmd, const int32_t bulk_limit); bool cmd_in_second_write(const char* collection_name, const char* cmd, const char* key, const char* client_ip); diff --git a/memcached.c b/memcached.c index c8f470456..26447836a 100644 --- a/memcached.c +++ b/memcached.c @@ -1628,10 +1628,9 @@ static void process_lop_insert_complete(conn *c) { ret = ENGINE_SUCCESS; } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_lop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_lop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("lop", "insert", c->coll_key, c->client_ip); #endif } @@ -1694,10 +1693,9 @@ static void process_sop_insert_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_sop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "insert", c->coll_key, c->client_ip); #endif } @@ -1751,12 +1749,10 @@ static void process_sop_delete_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_delete(c->coll_key, c->coll_nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_sop_delete(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "delete", c->coll_key, c->client_ip); #endif } @@ -1804,12 +1800,10 @@ static void process_sop_exist_complete(conn *c) { c->coll_key, c->coll_nkey, value->ptr, value->len, &exist, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_exist(c->coll_key, c->coll_nkey, c->client_ip, - (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_sop_exist(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "exist", c->coll_key, c->client_ip); #endif } @@ -1881,10 +1875,9 @@ static void process_mop_insert_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_mop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_mop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("mop", "insert", c->coll_key, c->client_ip); #endif } @@ -1935,10 +1928,9 @@ static void process_mop_update_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_mop_update(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_mop_update(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("mop", "update", c->coll_key, c->client_ip); #endif } @@ -2021,12 +2013,10 @@ static void process_mop_delete_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_mop_delete(c->coll_key, c->coll_nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_mop_delete(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("mop", "delete", c->coll_key, c->client_ip); #endif } @@ -2146,10 +2136,9 @@ static void process_mop_get_complete(conn *c) } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_mop_get(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_mop_get(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("mop", "get", c->coll_key, c->client_ip); #endif } @@ -2324,10 +2313,9 @@ static void process_bop_insert_complete(conn *c) { c->coll_eitem = NULL; if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_bop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "insert", c->coll_key, c->client_ip); #endif } @@ -2430,12 +2418,10 @@ static void process_bop_update_complete(conn *c) } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_update(c->coll_key, c->coll_nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_update(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "update", c->coll_key, c->client_ip); #endif } @@ -2528,12 +2514,10 @@ static void process_bop_mget_complete(conn *c) { &cur_access_count, &flags, &trimmed, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_get(key_tokens[k].value, key_tokens[k].length, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_get(key_tokens[k].value, key_tokens[k].length, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "get", c->coll_key, c->client_ip); #endif } @@ -3120,10 +3104,9 @@ static void process_mget_complete(conn *c) it = NULL; } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_get(key, nkey, c->client_ip, NULL != it); -#else stats_prefix_record_get(key, nkey, NULL != it); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "get", key, c->client_ip); #endif } if (it) { @@ -3712,19 +3695,17 @@ static void complete_incr_bin(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - if (incr) { - stats_prefix_record_incr(key, nkey, c->client_ip); - } else { - stats_prefix_record_decr(key, nkey, c->client_ip); - } -#else - if (incr) { + if (incr) { stats_prefix_record_incr(key, nkey); - } else { +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "incr", key, c->client_ip); +#endif + } else { stats_prefix_record_decr(key, nkey); - } +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "decr", key, c->client_ip); #endif + } } switch (ret) { @@ -3977,10 +3958,9 @@ static void process_bin_get(conn *c) { } if (settings.detail_enabled && ret != ENGINE_EWOULDBLOCK) { -#ifdef CMD_IN_SECOND - stats_prefix_record_get(key, nkey, c->client_ip, ret == ENGINE_SUCCESS); -#else stats_prefix_record_get(key, nkey, ret == ENGINE_SUCCESS); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "decr", key, c->client_ip); #endif } } @@ -4559,10 +4539,9 @@ static void process_bin_lop_create(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_lop_create(key, nkey, c->client_ip); -#else stats_prefix_record_lop_create(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("lop", "create", key, c->client_ip); #endif } @@ -4631,10 +4610,9 @@ static void process_bin_lop_prepare_nread(conn *c) { } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - stats_prefix_record_lop_insert(key, nkey, c->client_ip, false); -#else stats_prefix_record_lop_insert(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("lop", "insert", key, c->client_ip); #endif } @@ -4702,10 +4680,9 @@ static void process_bin_lop_insert_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_lop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_lop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("lop", "insert", c->coll_key, c->client_ip); #endif } @@ -4785,12 +4762,10 @@ static void process_bin_lop_delete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_lop_delete(key, nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_lop_delete(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("lop", "delete", key, c->client_ip); #endif } @@ -4879,12 +4854,10 @@ static void process_bin_lop_get(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_lop_get(key, nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_lop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("lop", "get", key, c->client_ip); #endif } @@ -5001,10 +4974,9 @@ static void process_bin_sop_create(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_create(key, nkey, c->client_ip); -#else stats_prefix_record_sop_create(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "create", key, c->client_ip); #endif } @@ -5077,22 +5049,22 @@ static void process_bin_sop_prepare_nread(conn *c) { } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - if (c->cmd == PROTOCOL_BINARY_CMD_SOP_INSERT) - stats_prefix_record_sop_insert(key, nkey, c->client_ip, false); - else if (c->cmd == PROTOCOL_BINARY_CMD_SOP_DELETE) - stats_prefix_record_sop_delete(key, nkey, c->client_ip, false); - else - stats_prefix_record_sop_exist(key, nkey, c->client_ip, false); -#else - if (c->cmd == PROTOCOL_BINARY_CMD_SOP_INSERT) + if (c->cmd == PROTOCOL_BINARY_CMD_SOP_INSERT) { stats_prefix_record_sop_insert(key, nkey, false); - else if (c->cmd == PROTOCOL_BINARY_CMD_SOP_DELETE) +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "insert", key, c->client_ip); +#endif + } else if (c->cmd == PROTOCOL_BINARY_CMD_SOP_DELETE) { stats_prefix_record_sop_delete(key, nkey, false); - else +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "delete", key, c->client_ip); +#endif + } else { stats_prefix_record_sop_exist(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "exist", key, c->client_ip); #endif - + } } switch (ret) { @@ -5181,10 +5153,9 @@ static void process_bin_sop_insert_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_sop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "insert", c->coll_key, c->client_ip); #endif } @@ -5244,12 +5215,10 @@ static void process_bin_sop_delete_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_delete(c->coll_key, c->coll_nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_sop_delete(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "delete", c->coll_key, c->client_ip); #endif } @@ -5299,10 +5268,9 @@ static void process_bin_sop_exist_complete(conn *c) { &exist, c->binary_header.request.vbucket); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_exist(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_sop_exist(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "exist", c->coll_key, c->client_ip); #endif } @@ -5398,12 +5366,10 @@ static void process_bin_sop_get(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_get(key, nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_sop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "get", key, c->client_ip); #endif } @@ -5530,10 +5496,9 @@ static void process_bin_bop_create(conn *c) { ret = ENGINE_SUCCESS; } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_create(key, nkey, c->client_ip); -#else stats_prefix_record_bop_create(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "create", key, c->client_ip); #endif } @@ -5614,10 +5579,9 @@ static void process_bin_bop_prepare_nread(conn *c) { } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_insert(key, nkey, c->client_ip, false); -#else stats_prefix_record_bop_insert(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "insert", key, c->client_ip); #endif } @@ -5697,10 +5661,9 @@ static void process_bin_bop_insert_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_insert(c->coll_key, c->coll_nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_bop_insert(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "insert", c->coll_key, c->client_ip); #endif } @@ -5779,12 +5742,10 @@ static void process_bin_bop_update_complete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_update(c->coll_key, c->coll_nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_update(c->coll_key, c->coll_nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "insert", c->coll_key, c->client_ip); #endif } @@ -5898,10 +5859,9 @@ static void process_bin_bop_update_prepare_nread(conn *c) { } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_update(key, nkey, c->client_ip, false); -#else stats_prefix_record_bop_update(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "update", key, c->client_ip); #endif } @@ -5979,12 +5939,10 @@ static void process_bin_bop_delete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_delete(key, nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_delete(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "delete", key, c->client_ip); #endif } @@ -6089,12 +6047,10 @@ static void process_bin_bop_get(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_get(key, nkey, c->client_ip, - (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "get", key, c->client_ip); #endif } @@ -6227,10 +6183,9 @@ static void process_bin_bop_count(conn *c) { c->binary_header.request.vbucket); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_count(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_bop_count(key, nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "count", key, c->client_ip); #endif } @@ -6874,10 +6829,9 @@ static void process_bin_getattr(conn *c) { c->binary_header.request.vbucket); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_getattr(key, nkey, c->client_ip); -#else stats_prefix_record_getattr(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "getattr", key, c->client_ip); #endif } @@ -7015,10 +6969,9 @@ static void process_bin_setattr(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_setattr(key, nkey, c->client_ip); -#else stats_prefix_record_setattr(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "setattr", key, c->client_ip); #endif } @@ -7504,10 +7457,9 @@ static void process_bin_update(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_set(key, nkey, c->client_ip); -#else stats_prefix_record_set(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "set", key, c->client_ip); #endif } @@ -7593,10 +7545,9 @@ static void process_bin_append_prepend(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_set(key, nkey, c->client_ip); -#else stats_prefix_record_set(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "set", key, c->client_ip); #endif } @@ -7768,10 +7719,9 @@ static void process_bin_delete(conn *c) { } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_delete(key, nkey, c->client_ip); -#else stats_prefix_record_delete(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "delete", key, c->client_ip); #endif } @@ -8692,10 +8642,9 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, it = NULL; } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_get(key, nkey, c->client_ip, NULL != it); -#else stats_prefix_record_get(key, nkey, NULL != it); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "get", key, c->client_ip); #endif } @@ -8910,10 +8859,9 @@ static void process_update_command(conn *c, token_t *tokens, const size_t ntoken } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_set(key, nkey, c->client_ip); -#else stats_prefix_record_set(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "set", key, c->client_ip); #endif } @@ -9002,19 +8950,17 @@ static void process_arithmetic_command(conn *c, token_t *tokens, const size_t nt } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - if (incr) { - stats_prefix_record_incr(key, nkey, c->client_ip); - } else { - stats_prefix_record_decr(key, nkey, c->client_ip); - } -#else if (incr) { stats_prefix_record_incr(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "incr", key, c->client_ip); +#endif } else { stats_prefix_record_decr(key, nkey); - } +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "decr", key, c->client_ip); #endif + } } ENGINE_ERROR_CODE ret; @@ -9106,10 +9052,9 @@ static void process_delete_command(conn *c, token_t *tokens, const size_t ntoken } if (settings.detail_enabled) { + stats_prefix_record_delete(key, nkey); #ifdef CMD_IN_SECOND - stats_prefix_record_delete(key, nkey, c->client_ip); -#else - stats_prefix_record_delete(key, nkey); + cmd_in_second_write("", "delete", key, c->client_ip); #endif } @@ -10144,10 +10089,9 @@ static void process_lop_get(conn *c, char *key, size_t nkey, } if (settings.detail_enabled) { + stats_prefix_record_lop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); #ifdef CMD_IN_SECOND - stats_prefix_record_lop_get(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else - stats_prefix_record_lop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); + cmd_in_second_write("", "get", key, c->client_ip); #endif } @@ -10256,10 +10200,9 @@ static void process_lop_prepare_nread(conn *c, int cmd, size_t vlen, } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { + stats_prefix_record_lop_insert(key, nkey, false); #ifdef CMD_IN_SECOND - stats_prefix_record_lop_insert(key, nkey, c->client_ip, false); -#else - stats_prefix_record_lop_insert(key, nkey, false); + cmd_in_second_write("lop", "insert", key, c->client_ip); #endif } @@ -10303,10 +10246,9 @@ static void process_lop_create(conn *c, char *key, size_t nkey, item_attr *attrp } if (settings.detail_enabled) { + stats_prefix_record_lop_create(key, nkey); #ifdef CMD_IN_SECOND - stats_prefix_record_lop_create(key, nkey, c->client_ip); -#else - stats_prefix_record_lop_create(key, nkey); + cmd_in_second_write("lop", "create", key, c->client_ip); #endif } @@ -10346,10 +10288,9 @@ static void process_lop_delete(conn *c, char *key, size_t nkey, } if (settings.detail_enabled) { + stats_prefix_record_lop_delete(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); #ifdef CMD_IN_SECOND - stats_prefix_record_lop_delete(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else - stats_prefix_record_lop_delete(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); + cmd_in_second_write("lop", "delete", key, c->client_ip); #endif } @@ -10578,10 +10519,9 @@ static void process_sop_get(conn *c, char *key, size_t nkey, uint32_t count, } if (settings.detail_enabled) { + stats_prefix_record_sop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); #ifdef CMD_IN_SECOND - stats_prefix_record_sop_get(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else - stats_prefix_record_sop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); + cmd_in_second_write("sop", "get", key, c->client_ip); #endif } @@ -10696,21 +10636,22 @@ static void process_sop_prepare_nread(conn *c, int cmd, size_t vlen, char *key, } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - if (cmd == (int)OPERATION_SOP_INSERT) - stats_prefix_record_sop_insert(key, nkey, c->client_ip, false); - else if (cmd == (int)OPERATION_SOP_DELETE) - stats_prefix_record_sop_delete(key, nkey, c->client_ip, false); - else - stats_prefix_record_sop_exist(key, nkey, c->client_ip, false); -#else - if (cmd == (int)OPERATION_SOP_INSERT) + if (cmd == (int)OPERATION_SOP_INSERT) { stats_prefix_record_sop_insert(key, nkey, false); - else if (cmd == (int)OPERATION_SOP_DELETE) +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "insert", key, c->client_ip); +#endif + } else if (cmd == (int)OPERATION_SOP_DELETE) { stats_prefix_record_sop_delete(key, nkey, false); - else +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "delete", key, c->client_ip); +#endif + } else { stats_prefix_record_sop_exist(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "exist", key, c->client_ip); #endif + } } switch (ret) { @@ -10763,10 +10704,9 @@ static void process_sop_create(conn *c, char *key, size_t nkey, item_attr *attrp } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_sop_create(key, nkey, c->client_ip); -#else stats_prefix_record_sop_create(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("sop", "create", key, c->client_ip); #endif } @@ -10988,10 +10928,9 @@ static void process_bop_get(conn *c, char *key, size_t nkey, } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_get(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_get(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "get", key, c->client_ip); #endif } @@ -11108,10 +11047,9 @@ static void process_bop_count(conn *c, char *key, size_t nkey, &elem_count, &access_count, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_count(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS)); -#else stats_prefix_record_bop_count(key, nkey, (ret==ENGINE_SUCCESS)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "get", key, c->client_ip); #endif } @@ -11162,10 +11100,9 @@ static void process_bop_position(conn *c, char *key, size_t nkey, bkrange, order, &position, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_position(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_position(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "position", key, c->client_ip); #endif } @@ -11225,10 +11162,9 @@ static void process_bop_pwg(conn *c, char *key, size_t nkey, const bkey_range *b &flags, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_pwg(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_pwg(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "pwg", key, c->client_ip); #endif } @@ -11342,10 +11278,9 @@ static void process_bop_gbp(conn *c, char *key, size_t nkey, ENGINE_BTREE_ORDER elem_array, &elem_count, &flags, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_gbp(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_gbp(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "gbp", key, c->client_ip); #endif } @@ -11456,10 +11391,9 @@ static void process_bop_update_prepare_nread(conn *c, int cmd, char *key, size_t } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_update(key, nkey, c->client_ip, false); -#else stats_prefix_record_bop_update(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "update", key, c->client_ip); #endif } @@ -11502,10 +11436,9 @@ static void process_bop_prepare_nread(conn *c, int cmd, char *key, size_t nkey, } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_insert(key, nkey, c->client_ip, false); -#else stats_prefix_record_bop_insert(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "insert", key, c->client_ip); #endif } @@ -11648,10 +11581,9 @@ static void process_bop_create(conn *c, char *key, size_t nkey, item_attr *attrp } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_create(key, nkey, c->client_ip); -#else stats_prefix_record_bop_create(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "create", key, c->client_ip); #endif } @@ -11693,10 +11625,9 @@ static void process_bop_delete(conn *c, char *key, size_t nkey, } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_bop_delete(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); -#else stats_prefix_record_bop_delete(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "delete", key, c->client_ip); #endif } @@ -11754,18 +11685,17 @@ static void process_bop_arithmetic(conn *c, char *key, size_t nkey, bkey_range * } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - if (incr) { - stats_prefix_record_bop_incr(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); - } else { - stats_prefix_record_bop_decr(key, nkey, c->client_ip, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); - } -#else if (incr) { stats_prefix_record_bop_incr(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "incr", key, c->client_ip); +#endif } else { stats_prefix_record_bop_decr(key, nkey, (ret==ENGINE_SUCCESS || ret==ENGINE_ELEM_ENOENT)); +#ifdef CMD_IN_SECOND + cmd_in_second_write("bop", "decr", key, c->client_ip); #endif + } } switch (ret) { @@ -12013,10 +11943,9 @@ static void process_mop_prepare_nread(conn *c, int cmd, char *key, size_t nkey, } if (settings.detail_enabled && ret != ENGINE_SUCCESS) { -#ifdef CMD_IN_SECOND - stats_prefix_record_mop_insert(key, nkey, c->client_ip, false); -#else stats_prefix_record_mop_insert(key, nkey, false); +#ifdef CMD_IN_SECOND + cmd_in_second_write("mop", "insert", key, c->client_ip); #endif } @@ -12107,10 +12036,9 @@ static void process_mop_create(conn *c, char *key, size_t nkey, item_attr *attrp } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_mop_create(key, nkey, c->client_ip); -#else stats_prefix_record_mop_create(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("mop", "create", key, c->client_ip); #endif } @@ -13128,10 +13056,9 @@ static void process_getattr_command(conn *c, token_t *tokens, const size_t ntoke attr_ids, attr_count, &attr_data, 0); if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_getattr(key, nkey, c->client_ip); -#else stats_prefix_record_getattr(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "getattr", key, c->client_ip); #endif } } @@ -13288,10 +13215,9 @@ static void process_setattr_command(conn *c, token_t *tokens, const size_t ntoke } if (settings.detail_enabled) { -#ifdef CMD_IN_SECOND - stats_prefix_record_setattr(key, nkey, c->client_ip); -#else stats_prefix_record_setattr(key, nkey); +#ifdef CMD_IN_SECOND + cmd_in_second_write("", "setattr", key, c->client_ip); #endif } } @@ -16119,6 +16045,10 @@ int main (int argc, char **argv) { cmdlog_init(settings.port, mc_logger); #endif +#ifdef CMD_IN_SECOND + cmd_in_second_init(); +#endif + #ifdef DETECT_LONG_QUERY /* initialise long query detection */ if (lqdetect_init() == -1) { diff --git a/stats.c b/stats.c index c4fc2f407..6986c4261 100644 --- a/stats.c +++ b/stats.c @@ -25,7 +25,6 @@ * Steven Grimm */ #include "config.h" -#include "cmd_in_second.h" #include "memcached.h" #include #include @@ -339,7 +338,7 @@ static PREFIX_STATS *stats_prefix_find(const char *key, const size_t nkey) { /* * Records a "get" of a key. */ -void stats_prefix_record_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -356,7 +355,7 @@ void stats_prefix_record_get(const char *key, const size_t nkey, const char* cli /* * Records a "delete" of a key. */ -void stats_prefix_record_delete(const char *key, const size_t nkey, const char* client_ip) { +void stats_prefix_record_delete(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -370,7 +369,7 @@ void stats_prefix_record_delete(const char *key, const size_t nkey, const char* /* * Records a "set" of a key. */ -void stats_prefix_record_set(const char *key, const size_t nkey, const char* client_ip) { +void stats_prefix_record_set(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -378,14 +377,13 @@ void stats_prefix_record_set(const char *key, const size_t nkey, const char* cli if (NULL != pfs) { pfs->num_sets++; } - cmd_in_second_write("", "set", key, client_ip); STATS_UNLOCK(); } /* * Records a "incr" of a key. */ -void stats_prefix_record_incr(const char *key, const size_t nkey, const char* client_ip) { +void stats_prefix_record_incr(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -393,14 +391,13 @@ void stats_prefix_record_incr(const char *key, const size_t nkey, const char* cl if (NULL != pfs) { pfs->num_incrs++; } - cmd_in_second_write("", "incr", key, client_ip); STATS_UNLOCK(); } /* * Records a "decr" of a key. */ -void stats_prefix_record_decr(const char *key, const size_t nkey, const char* client_ip) { +void stats_prefix_record_decr(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -408,14 +405,13 @@ void stats_prefix_record_decr(const char *key, const size_t nkey, const char* cl if (NULL != pfs) { pfs->num_decrs++; } - cmd_in_second_write("", "decr", key, client_ip); STATS_UNLOCK(); } /* * LIST stats */ -void stats_prefix_record_lop_create(const char *key, const size_t nkey, const char* client_ip) { +void stats_prefix_record_lop_create(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -423,11 +419,10 @@ void stats_prefix_record_lop_create(const char *key, const size_t nkey, const ch if (NULL != pfs) { pfs->num_lop_creates++; } - cmd_in_second_write("lop", "create", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_lop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_lop_insert(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -438,11 +433,10 @@ void stats_prefix_record_lop_insert(const char *key, const size_t nkey, const ch pfs->num_lop_insert_hits++; } } - cmd_in_second_write("lop", "insert", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_lop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_lop_delete(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -453,11 +447,10 @@ void stats_prefix_record_lop_delete(const char *key, const size_t nkey, const ch pfs->num_lop_delete_hits++; } } - cmd_in_second_write("lop", "delete", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_lop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_lop_get(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -468,14 +461,13 @@ void stats_prefix_record_lop_get(const char *key, const size_t nkey, const char* pfs->num_lop_get_hits++; } } - cmd_in_second_write("lop", "get", key, client_ip); STATS_UNLOCK(); } /* * SET stats */ -void stats_prefix_record_sop_create(const char *key, const size_t nkey, const char* client_ip) { +void stats_prefix_record_sop_create(const char *key, const size_t nkey) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -483,11 +475,10 @@ void stats_prefix_record_sop_create(const char *key, const size_t nkey, const ch if (NULL != pfs) { pfs->num_sop_creates++; } - cmd_in_second_write("sop", "create", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_sop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_sop_insert(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -498,11 +489,10 @@ void stats_prefix_record_sop_insert(const char *key, const size_t nkey, const ch pfs->num_sop_insert_hits++; } } - cmd_in_second_write("sop", "insert", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_sop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_sop_delete(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -513,11 +503,10 @@ void stats_prefix_record_sop_delete(const char *key, const size_t nkey, const ch pfs->num_sop_delete_hits++; } } - cmd_in_second_write("sop", "delete", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_sop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_sop_get(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -528,11 +517,10 @@ void stats_prefix_record_sop_get(const char *key, const size_t nkey, const char* pfs->num_sop_get_hits++; } } - cmd_in_second_write("sop", "get", key, client_ip); STATS_UNLOCK(); } -void stats_prefix_record_sop_exist(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { +void stats_prefix_record_sop_exist(const char *key, const size_t nkey, const bool is_hit) { PREFIX_STATS *pfs; STATS_LOCK(); @@ -543,18 +531,13 @@ void stats_prefix_record_sop_exist(const char *key, const size_t nkey, const cha pfs->num_sop_exist_hits++; } } - cmd_in_second_write("sop", "exist", key, client_ip); STATS_UNLOCK(); } /* * MAP stats */ -#ifdef CMD_IN_SECOND -void stats_prefix_record_mop_create(const char *key, const size_t nkey, const char* client_ip) { -#else void stats_prefix_record_mop_create(const char *key, const size_t nkey) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -562,17 +545,10 @@ void stats_prefix_record_mop_create(const char *key, const size_t nkey) { if (NULL != pfs) { pfs->num_mop_creates++; } -#ifdef CMD_IN_SECOND - cmd_in_second_write("mop", "create", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_mop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_mop_insert(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -583,17 +559,10 @@ void stats_prefix_record_mop_insert(const char *key, const size_t nkey, const bo pfs->num_mop_insert_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("mop", "insert", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_mop_update(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_mop_update(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -604,17 +573,10 @@ void stats_prefix_record_mop_update(const char *key, const size_t nkey, const bo pfs->num_mop_update_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("mop", "update", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_mop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_mop_delete(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -625,17 +587,10 @@ void stats_prefix_record_mop_delete(const char *key, const size_t nkey, const bo pfs->num_mop_delete_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("mop", "delete", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_mop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_mop_get(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -646,20 +601,13 @@ void stats_prefix_record_mop_get(const char *key, const size_t nkey, const bool pfs->num_mop_get_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("mop", "get", key, client_ip); -#endif STATS_UNLOCK(); } /* * B+TREE stats */ -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_create(const char *key, const size_t nkey, const char* client_ip) { -#else void stats_prefix_record_bop_create(const char *key, const size_t nkey) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -667,17 +615,10 @@ void stats_prefix_record_bop_create(const char *key, const size_t nkey) { if (NULL != pfs) { pfs->num_bop_creates++; } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "create", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_insert(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -688,17 +629,10 @@ void stats_prefix_record_bop_insert(const char *key, const size_t nkey, const bo pfs->num_bop_insert_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "insert", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_update(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_update(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -709,17 +643,10 @@ void stats_prefix_record_bop_update(const char *key, const size_t nkey, const bo pfs->num_bop_update_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "update", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_delete(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -730,15 +657,10 @@ void stats_prefix_record_bop_delete(const char *key, const size_t nkey, const bo pfs->num_bop_delete_hits++; } } - cmd_in_second_write("bop", "delete", key, client_ip); STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_incr(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_incr(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -749,17 +671,10 @@ void stats_prefix_record_bop_incr(const char *key, const size_t nkey, const bool pfs->num_bop_incr_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "incr", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_decr(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_decr(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -770,17 +685,10 @@ void stats_prefix_record_bop_decr(const char *key, const size_t nkey, const bool pfs->num_bop_decr_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "decr", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_get(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -791,17 +699,10 @@ void stats_prefix_record_bop_get(const char *key, const size_t nkey, const bool pfs->num_bop_get_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "get", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_count(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_count(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -812,17 +713,10 @@ void stats_prefix_record_bop_count(const char *key, const size_t nkey, const boo pfs->num_bop_count_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "count", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_position(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_position(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -833,17 +727,10 @@ void stats_prefix_record_bop_position(const char *key, const size_t nkey, const pfs->num_bop_position_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "position", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_pwg(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_pwg(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -854,17 +741,10 @@ void stats_prefix_record_bop_pwg(const char *key, const size_t nkey, const bool pfs->num_bop_pwg_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "pwg", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_bop_gbp(const char *key, const size_t nkey, const char* client_ip, const bool is_hit) { -#else void stats_prefix_record_bop_gbp(const char *key, const size_t nkey, const bool is_hit) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -875,20 +755,13 @@ void stats_prefix_record_bop_gbp(const char *key, const size_t nkey, const bool pfs->num_bop_gbp_hits++; } } -#ifdef CMD_IN_SECOND - cmd_in_second_write("bop", "gbp", key, client_ip); -#endif STATS_UNLOCK(); } /* * ATTR stats */ -#ifdef CMD_IN_SECOND -void stats_prefix_record_getattr(const char *key, const size_t nkey, const char* client_ip) { -#else void stats_prefix_record_getattr(const char *key, const size_t nkey) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -896,17 +769,10 @@ void stats_prefix_record_getattr(const char *key, const size_t nkey) { if (NULL != pfs) { pfs->num_getattrs++; } -#ifdef CMD_IN_SECOND - cmd_in_second_write("", "getattr", key, client_ip); -#endif STATS_UNLOCK(); } -#ifdef CMD_IN_SECOND -void stats_prefix_record_setattr(const char *key, const size_t nkey, const char* client_ip) { -#else void stats_prefix_record_setattr(const char *key, const size_t nkey) { -#endif PREFIX_STATS *pfs; STATS_LOCK(); @@ -914,9 +780,6 @@ void stats_prefix_record_setattr(const char *key, const size_t nkey) { if (NULL != pfs) { pfs->num_setattrs++; } -#ifdef CMD_IN_SECOND - cmd_in_second_write("", "setattr", key, client_ip); -#endif STATS_UNLOCK(); } diff --git a/stats.h b/stats.h index c5f41082b..9bfafddc5 100644 --- a/stats.h +++ b/stats.h @@ -22,42 +22,7 @@ int stats_prefix_count(void); #if 1 // NEW_PREFIX_STATS_MANAGEMENT int stats_prefix_insert(const char *prefix, const size_t nprefix); #endif - int stats_prefix_delete(const char *prefix, const size_t nprefix); -#ifdef CMD_IN_SECOND -void stats_prefix_record_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_delete(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_set(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_incr(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_decr(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_lop_create(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_lop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_lop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_lop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_sop_create(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_sop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_sop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_sop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_sop_exist(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_mop_create(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_mop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_mop_update(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_mop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_mop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_create(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_bop_insert(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_update(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_delete(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_incr(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_decr(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_get(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_count(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_position(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_pwg(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_bop_gbp(const char *key, const size_t nkey, const char* client_ip, const bool is_hit); -void stats_prefix_record_getattr(const char *key, const size_t nkey, const char* client_ip); -void stats_prefix_record_setattr(const char *key, const size_t nkey, const char* client_ip); -#else void stats_prefix_record_get(const char *key, const size_t nkey, const bool is_hit); void stats_prefix_record_delete(const char *key, const size_t nkey); void stats_prefix_record_set(const char *key, const size_t nkey); @@ -90,7 +55,5 @@ void stats_prefix_record_bop_pwg(const char *key, const size_t nkey, const bool void stats_prefix_record_bop_gbp(const char *key, const size_t nkey, const bool is_hit); void stats_prefix_record_getattr(const char *key, const size_t nkey); void stats_prefix_record_setattr(const char *key, const size_t nkey); -#endif - /*@null@*/ char *stats_prefix_dump(int *length); diff --git a/t/bulk.t b/t/bulk.t index 717fc6c62..5712b0ea5 100644 --- a/t/bulk.t +++ b/t/bulk.t @@ -134,7 +134,8 @@ sub wrong_cmd_test{ } -sub non_bulk_cmd { + +sub slow_cmd { my $request_cnt = 10000; request_log("sop exist", $request_cnt, $start); @@ -155,22 +156,34 @@ sub non_bulk_cmd { } } +sub file_check { + + my $file_handle; + open($file_handle, "cmd_in_second.log") or die "log file not exist\n"; + + my $line_cnt; + close($file_handle); +} + wrong_cmd_test(); -sleep(3); +sleep(1); #extremely small cases + + =pod request_log("bop insert", 1, $start); -do_bulk_coll_insert("bop", "bkey", 1); +do_bulk_coll_insert("bop", "bkey1", 1); + request_log("bop insert", 9, $start); do_bulk_coll_insert("bop", "bkey2", 9); =cut -request_log("sop insert", $bulk_size, $start); -do_bulk_coll_insert("sop", "skey", $bulk_size+1); +request_log("bop insert", $bulk_size, $start); +do_bulk_coll_insert("bop", "bkey3", $bulk_size+100); sleep(1); -#non_bulk_cmd(); +#slow_cmd(); release_memcached($engine, $server);