diff --git a/src/data.cc b/src/data.cc index 5fc940e..795d4eb 100644 --- a/src/data.cc +++ b/src/data.cc @@ -28,7 +28,6 @@ void pinba_update_tag_info_add(size_t request_id, void *rep, const pinba_stats_r { pinba_tag_report *report = (pinba_tag_report *)rep; struct pinba_tag_info_data *data; - PPvoid_t ppvalue; pinba_timer_record *timer; int i, j, tag_found; pinba_word *word; @@ -49,14 +48,9 @@ void pinba_update_tag_info_add(size_t request_id, void *rep, const pinba_stats_r } word = (pinba_word *)timer->tag_values[j]; - ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL); - - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + data = (struct pinba_tag_info_data *)tag_report_map_get(report->results, word->str); - ppvalue = JudySLIns(&report->results, (uint8_t *)word->str, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - continue; - } + if (UNLIKELY(!data)) { data = (struct pinba_tag_info_data *)calloc(1, sizeof(struct pinba_tag_info_data)); if (!data) { @@ -69,10 +63,10 @@ void pinba_update_tag_info_add(size_t request_id, void *rep, const pinba_stats_r data->prev_add_request_id = request_id; data->prev_del_request_id = -1; - *ppvalue = data; + report->results = tag_report_map_add(report->results, word->str, data); + report->std.results_cnt++; } else { - data = (struct pinba_tag_info_data *)*ppvalue; data->hit_count += timer->hit_count; timeradd(&data->timer_value, &timer->value, &data->timer_value); } @@ -93,7 +87,6 @@ void pinba_update_tag_info_delete(size_t request_id, void *rep, const pinba_stat { pinba_tag_report *report = (pinba_tag_report *)rep; struct pinba_tag_info_data *data; - PPvoid_t ppvalue; pinba_timer_record *timer; int i, j, tag_found; pinba_word *word; @@ -117,13 +110,11 @@ void pinba_update_tag_info_delete(size_t request_id, void *rep, const pinba_stat word = (pinba_word *)timer->tag_values[j]; - ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL); + data = (struct pinba_tag_info_data *)tag_report_map_get(report->results, word->str); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + if (UNLIKELY(!data)) { continue; } else { - data = (struct pinba_tag_info_data *)*ppvalue; - /* count tag values only once per request */ if (request_id != data->prev_del_request_id) { data->req_count--; @@ -131,10 +122,12 @@ void pinba_update_tag_info_delete(size_t request_id, void *rep, const pinba_stat } if (UNLIKELY(data->req_count == 0)) { - free(data); - JudySLDel(&report->results, (uint8_t *)word->str, NULL); + if (tag_report_map_del(report->results, word->str) < 0) { + tag_report_destroy(report->results); + report->results = NULL; + } report->std.results_cnt--; - continue; + free(data); } else { data->hit_count -= timer->hit_count; timersub(&data->timer_value, &timer->value, &data->timer_value); @@ -151,12 +144,11 @@ void pinba_update_tag2_info_add(size_t request_id, void *rep, const pinba_stats_ { pinba_tag_report *report = (pinba_tag_report *)rep; struct pinba_tag2_info_data *data; - PPvoid_t ppvalue; pinba_timer_record *timer; int i, j, tag1_pos, tag2_pos, dummy; pinba_word *word1, *word2; int index_len; - uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE]; + char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE]; for (i = 0; i < record->timers_cnt; i++) { @@ -185,14 +177,9 @@ void pinba_update_tag2_info_add(size_t request_id, void *rep, const pinba_stats_ index_val[index_len] = '|'; index_len++; memcat_static(index_val, index_len, word2->str, word2->len, index_len); - ppvalue = JudySLGet(report->results, index_val, NULL); + data = (struct pinba_tag2_info_data *)tag_report_map_get(report->results, index_val); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - - ppvalue = JudySLIns(&report->results, index_val, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - continue; - } + if (UNLIKELY(!data)) { data = (struct pinba_tag2_info_data *)calloc(1, sizeof(struct pinba_tag2_info_data)); if (!data) { @@ -208,10 +195,9 @@ void pinba_update_tag2_info_add(size_t request_id, void *rep, const pinba_stats_ memcpy_static(data->tag1_value, word1->str, word1->len, dummy); memcpy_static(data->tag2_value, word2->str, word2->len, dummy); - *ppvalue = data; + report->results = tag_report_map_add(report->results, index_val, data); report->std.results_cnt++; } else { - data = (struct pinba_tag2_info_data *)*ppvalue; data->hit_count += timer->hit_count; timeradd(&data->timer_value, &timer->value, &data->timer_value); } @@ -232,12 +218,11 @@ void pinba_update_tag2_info_delete(size_t request_id, void *rep, const pinba_sta { pinba_tag_report *report = (pinba_tag_report *)rep; struct pinba_tag2_info_data *data; - PPvoid_t ppvalue; pinba_timer_record *timer; int i, j, tag1_pos, tag2_pos; int index_len; pinba_word *word1, *word2; - uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE]; + char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE]; PINBA_REPORT_DELETE_CHECK(report, record); @@ -267,13 +252,11 @@ void pinba_update_tag2_info_delete(size_t request_id, void *rep, const pinba_sta index_val[index_len] = '|'; index_len++; memcat_static(index_val, index_len, word2->str, word2->len, index_len); - ppvalue = JudySLGet(report->results, index_val, NULL); + data = (struct pinba_tag2_info_data *)tag_report_map_get(report->results, index_val); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + if (UNLIKELY(!data)) { continue; } else { - data = (struct pinba_tag2_info_data *)*ppvalue; - /* count tag values only once per request */ if (request_id != data->prev_del_request_id) { data->req_count--; @@ -281,8 +264,11 @@ void pinba_update_tag2_info_delete(size_t request_id, void *rep, const pinba_sta } if (UNLIKELY(data->req_count == 0)) { + if (tag_report_map_del(report->results, index_val) < 0) { + tag_report_destroy(report->results); + report->results = NULL; + } free(data); - JudySLDel(&report->results, (uint8_t *)index_val, NULL); report->std.results_cnt--; continue; } else { @@ -1549,7 +1535,6 @@ void pinba_update_rtag_info_add(size_t request_id, void *rep, const pinba_stats_ { pinba_rtag_report *report = (pinba_rtag_report *)rep; struct pinba_rtag_info_data *data; - PPvoid_t ppvalue; unsigned int i, tag_found = 0; pinba_word *word; @@ -1565,23 +1550,14 @@ void pinba_update_rtag_info_add(size_t request_id, void *rep, const pinba_stats_ } word = (pinba_word *)record->data.tag_values[i]; - ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - - ppvalue = JudySLIns(&report->results, (uint8_t *)word->str, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - return; - } - + data = (struct pinba_rtag_info_data*)tag_report_map_get(report->results, word->str); + if (UNLIKELY(!data)) { data = (struct pinba_rtag_info_data *)calloc(1, sizeof(struct pinba_rtag_info_data)); if (!data) { return; } - - *ppvalue = data; + report->results = tag_report_map_add(report->results, word->str, data); report->std.results_cnt++; - } else { - data = (struct pinba_rtag_info_data *)*ppvalue; } timeradd(&report->time_total, &record->data.req_time, &report->time_total); @@ -1604,7 +1580,6 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta { pinba_rtag_report *report = (pinba_rtag_report *)rep; struct pinba_rtag_info_data *data; - PPvoid_t ppvalue; unsigned int i, tag_found = 0; pinba_word *word; @@ -1622,12 +1597,11 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta } word = (pinba_word *)record->data.tag_values[i]; - ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + + data = (struct pinba_rtag_info_data*)tag_report_map_get(report->results, word->str); + if (UNLIKELY(!data)) { return; } else { - data = (struct pinba_rtag_info_data *)*ppvalue; - timersub(&report->time_total, &record->data.req_time, &report->time_total); timersub(&report->ru_utime_total, &record->data.ru_utime, &report->ru_utime_total); timersub(&report->ru_stime_total, &record->data.ru_stime, &report->ru_stime_total); @@ -1638,7 +1612,10 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta if (UNLIKELY(data->req_count == 0)) { free(data); - JudySLDel(&report->results, (uint8_t *)word->str, NULL); + if (tag_report_map_del(report->results, word->str) < 0) { + tag_report_destroy(report->results); + report->results = NULL; + } report->std.results_cnt--; return; } else { @@ -1657,11 +1634,10 @@ void pinba_update_rtag2_info_add(size_t request_id, void *rep, const pinba_stats { pinba_rtag_report *report = (pinba_rtag_report *)rep; struct pinba_rtag2_info_data *data; - PPvoid_t ppvalue; unsigned int i; int tag1_pos = -1, tag2_pos = -1, index_len; pinba_word *word1, *word2; - uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1]; + char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1]; for (i = 0; i < record->data.tags_cnt; i++) { if (report->tags[0] == record->data.tag_names[i]) { @@ -1686,27 +1662,21 @@ void pinba_update_rtag2_info_add(size_t request_id, void *rep, const pinba_stats index_val[index_len] = '|'; index_len++; memcat_static(index_val, index_len, word2->str, word2->len, index_len); - ppvalue = JudySLGet(report->results, (uint8_t *)index_val, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + data = (struct pinba_rtag2_info_data*)tag_report_map_get(report->results, index_val); + if (UNLIKELY(!data)) { int dummy; - ppvalue = JudySLIns(&report->results, (uint8_t *)index_val, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - return; - } - data = (struct pinba_rtag2_info_data *)calloc(1, sizeof(struct pinba_rtag2_info_data)); if (!data) { return; } - *ppvalue = data; - memcpy_static(data->tag1_value, word1->str, word1->len, dummy); memcpy_static(data->tag2_value, word2->str, word2->len, dummy); + (void)dummy; + + report->results = tag_report_map_add(report->results, index_val, data); report->std.results_cnt++; - } else { - data = (struct pinba_rtag2_info_data *)*ppvalue; } timeradd(&report->time_total, &record->data.req_time, &report->time_total); @@ -1729,11 +1699,10 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st { pinba_rtag_report *report = (pinba_rtag_report *)rep; struct pinba_rtag2_info_data *data; - PPvoid_t ppvalue; unsigned int i; int tag1_pos = -1, tag2_pos = -1, index_len; pinba_word *word1, *word2; - uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1]; + char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1]; PINBA_REPORT_DELETE_CHECK(report, record); @@ -1760,12 +1729,10 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st index_val[index_len] = '|'; index_len++; memcat_static(index_val, index_len, word2->str, word2->len, index_len); - ppvalue = JudySLGet(report->results, (uint8_t *)index_val, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + data = (struct pinba_rtag2_info_data *)tag_report_map_get(report->results, index_val); + if (UNLIKELY(!data)) { return; } else { - data = (struct pinba_rtag2_info_data *)*ppvalue; - timersub(&report->time_total, &record->data.req_time, &report->time_total); timersub(&report->ru_utime_total, &record->data.ru_utime, &report->ru_utime_total); timersub(&report->ru_stime_total, &record->data.ru_stime, &report->ru_stime_total); @@ -1776,7 +1743,10 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st if (UNLIKELY(data->req_count == 0)) { free(data); - JudySLDel(&report->results, (uint8_t *)index_val, NULL); + if (tag_report_map_del(report->results, index_val) < 0) { + tag_report_destroy(report->results); + report->results = NULL; + } report->std.results_cnt--; return; } else { @@ -1964,7 +1934,7 @@ void pinba_update_rtag_report_add(size_t request_id, void *rep, const pinba_stat { pinba_rtag_report *report = (pinba_rtag_report *)rep; struct pinba_rtag_report_data *data; - PPvoid_t ppvalue, ppvalue_host = NULL; + PPvoid_t ppvalue_host = NULL; unsigned int i, tag_found = 0; pinba_word *word; @@ -1986,16 +1956,10 @@ void pinba_update_rtag_report_add(size_t request_id, void *rep, const pinba_stat return; } - ppvalue = JudySLGet(*ppvalue_host, (uint8_t *)word->str, NULL); - - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + data = (struct pinba_rtag_report_data *)tag_report_map_get(*ppvalue_host, word->str); + if (UNLIKELY(!data)) { int dummy; - ppvalue = JudySLIns(ppvalue_host, (uint8_t *)word->str, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { - return; - } - data = (struct pinba_rtag_report_data *)calloc(1, sizeof(struct pinba_rtag_report_data)); if (!data) { return; @@ -2004,10 +1968,8 @@ void pinba_update_rtag_report_add(size_t request_id, void *rep, const pinba_stat memcpy_static(data->hostname, record->data.hostname, record->data.hostname_len, dummy); memcpy_static(data->tag_value, word->str, word->len, dummy); - *ppvalue = data; + *ppvalue_host = tag_report_map_add(*ppvalue_host, word->str, data); report->std.results_cnt++; - } else { - data = (struct pinba_rtag_report_data *)*ppvalue; } timeradd(&report->time_total, &record->data.req_time, &report->time_total); @@ -2030,7 +1992,7 @@ void pinba_update_rtag_report_delete(size_t request_id, void *rep, const pinba_s { pinba_rtag_report *report = (pinba_rtag_report *)rep; struct pinba_rtag_report_data *data; - PPvoid_t ppvalue, ppvalue_host = NULL; + PPvoid_t ppvalue_host = NULL; unsigned int i, tag_found = 0; pinba_word *word; @@ -2054,12 +2016,10 @@ void pinba_update_rtag_report_delete(size_t request_id, void *rep, const pinba_s word = (pinba_word *)record->data.tag_values[i]; - ppvalue = JudySLGet(*ppvalue_host, (uint8_t *)word->str, NULL); - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { + data = (struct pinba_rtag_report_data *)tag_report_map_get(*ppvalue_host, word->str); + if (UNLIKELY(!data)) { return; } else { - data = (struct pinba_rtag_report_data *)*ppvalue; - timersub(&report->time_total, &record->data.req_time, &report->time_total); timersub(&report->ru_utime_total, &record->data.ru_utime, &report->ru_utime_total); timersub(&report->ru_stime_total, &record->data.ru_stime, &report->ru_stime_total); @@ -2070,9 +2030,10 @@ void pinba_update_rtag_report_delete(size_t request_id, void *rep, const pinba_s if (UNLIKELY(data->req_count == 0)) { free(data); - JudySLDel(ppvalue_host, (uint8_t *)word->str, NULL); - if (*ppvalue_host == NULL) { + if (tag_report_map_del(*ppvalue_host, word->str) < 0) { + tag_report_destroy(*ppvalue_host); JudySLDel(&report->results, (uint8_t *)record->data.hostname, NULL); + ppvalue_host = NULL; } report->std.results_cnt--; return; diff --git a/src/ha_pinba.cc b/src/ha_pinba.cc index 95ad7ac..243a9a7 100644 --- a/src/ha_pinba.cc +++ b/src/ha_pinba.cc @@ -5958,10 +5958,9 @@ inline int ha_pinba::status_fetch_row(unsigned char *buf) /* {{{ */ #define TAG_INFO_FETCH_TOP_BLOCK(report_name, kind) \ Field **field; \ my_bitmap_map *old_map; \ - struct pinba_ ##report_name## _data *data; \ + struct pinba_ ##report_name## _data *data = NULL; \ pinba_ ##kind## _report *report; \ - PPvoid_t ppvalue; \ - uint8_t index[PINBA_MAX_LINE_LEN] = {0}; \ + char index[PINBA_MAX_LINE_LEN] = {0}; \ \ DBUG_ENTER("ha_pinba:: ##report_name## _fetch_row"); \ \ @@ -5976,15 +5975,15 @@ inline int ha_pinba::status_fetch_row(unsigned char *buf) /* {{{ */ \ pthread_rwlock_rdlock(&report->std.lock); \ if (this_index[0].position == 0) { \ - ppvalue = JudySLFirst(report->results, index, NULL); \ + data = (struct pinba_ ##report_name## _data *)tag_report_map_first(report->results, index); \ } else { \ strcpy((char *)index, (char *)this_index[0].str.val); \ - ppvalue = JudySLNext(report->results, index, NULL); \ + data = (struct pinba_ ##report_name## _data *)tag_report_map_next(report->results, index); \ free(this_index[0].str.val); \ this_index[0].str.val = NULL; \ } \ \ - if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) { \ + if (UNLIKELY(!data)) { \ pthread_rwlock_unlock(&report->std.lock); \ DBUG_RETURN(HA_ERR_END_OF_FILE); \ } \ @@ -5992,8 +5991,6 @@ inline int ha_pinba::status_fetch_row(unsigned char *buf) /* {{{ */ this_index[0].str.val = (unsigned char *)strdup((char *)index); \ this_index[0].position++; \ \ - data = (struct pinba_ ##report_name## _data *)*ppvalue; \ - \ old_map = dbug_tmp_use_all_columns(table, table->write_set); inline int ha_pinba::tag_info_fetch_row(unsigned char *buf) /* {{{ */ @@ -7489,6 +7486,16 @@ inline int ha_pinba::histogram_fetch_row_by_key(unsigned char *buf, const unsign pthread_rwlock_unlock(&tag_report->std.lock); DBUG_RETURN(HA_ERR_END_OF_FILE); } + } else if (share->hv_table_type == PINBA_TABLE_TAG_INFO || share->hv_table_type == PINBA_TABLE_TAG2_INFO + || share->hv_table_type == PINBA_TABLE_RTAG_INFO || share->hv_table_type == PINBA_TABLE_RTAG2_INFO) { + + header = (pinba_tag_report_data_header *)tag_report_map_get(tag_report->results, (char*)this_index[0].str.val); + if (!header) { + free(this_index[0].str.val); + this_index[0].str.val = NULL; + pthread_rwlock_unlock(&tag_report->std.lock); + DBUG_RETURN(HA_ERR_END_OF_FILE); + } } else { PPvoid_t ppvalue;