diff options
Diffstat (limited to 'aclk/aclk_query_queue.c')
-rw-r--r-- | aclk/aclk_query_queue.c | 84 |
1 files changed, 79 insertions, 5 deletions
diff --git a/aclk/aclk_query_queue.c b/aclk/aclk_query_queue.c index c9461b233..18b4783ee 100644 --- a/aclk/aclk_query_queue.c +++ b/aclk/aclk_query_queue.c @@ -20,7 +20,9 @@ static struct aclk_query_queue { static inline int _aclk_queue_query(aclk_query_t query) { + now_realtime_timeval(&query->created_tv); query->created = now_realtime_usec(); + ACLK_QUEUE_LOCK; if (aclk_query_queue.block_push) { ACLK_QUEUE_UNLOCK; @@ -43,14 +45,49 @@ static inline int _aclk_queue_query(aclk_query_t query) } +// Gets a pointer to the metric associated with a particular query type. +// NULL if the query type has no associated metric. +static inline volatile uint32_t *aclk_stats_qmetric_for_qtype(aclk_query_type_t qtype) { + switch (qtype) { + case HTTP_API_V2: + return &aclk_metrics_per_sample.cloud_req_type_http; + case ALARM_STATE_UPDATE: + return &aclk_metrics_per_sample.cloud_req_type_alarm_upd; + case METADATA_INFO: + return &aclk_metrics_per_sample.cloud_req_type_metadata_info; + case METADATA_ALARMS: + return &aclk_metrics_per_sample.cloud_req_type_metadata_alarms; + case CHART_NEW: + return &aclk_metrics_per_sample.cloud_req_type_chart_new; + case CHART_DEL: + return &aclk_metrics_per_sample.cloud_req_type_chart_del; + case REGISTER_NODE: + return &aclk_metrics_per_sample.cloud_req_type_register_node; + case NODE_STATE_UPDATE: + return &aclk_metrics_per_sample.cloud_req_type_node_upd; + default: + return NULL; + } +} + int aclk_queue_query(aclk_query_t query) { int ret = _aclk_queue_query(query); if (!ret) { + // local cache of query type before we wake up query thread, which may + // free the query in a race. + aclk_query_type_t qtype = query->type; QUERY_THREAD_WAKEUP; + if (aclk_stats_enabled) { + // get target query type metric before lock so we keep lock for + // minimal time. + volatile uint32_t *metric = aclk_stats_qmetric_for_qtype(qtype); + ACLK_STATS_LOCK; aclk_metrics_per_sample.queries_queued++; + if (metric) + *metric += 1; ACLK_STATS_UNLOCK; } } @@ -102,17 +139,47 @@ aclk_query_t aclk_query_new(aclk_query_type_t type) void aclk_query_free(aclk_query_t query) { - if (query->type == HTTP_API_V2) { + switch (query->type) { + case HTTP_API_V2: freez(query->data.http_api_v2.payload); if (query->data.http_api_v2.query != query->dedup_id) freez(query->data.http_api_v2.query); - } + break; - if (query->type == CHART_NEW) + case CHART_NEW: freez(query->data.chart_add_del.chart_name); + break; - if (query->type == ALARM_STATE_UPDATE && query->data.alarm_update) - json_object_put(query->data.alarm_update); + case ALARM_STATE_UPDATE: + if (query->data.alarm_update) + json_object_put(query->data.alarm_update); + break; + + case NODE_STATE_UPDATE: + freez((void*)query->data.node_update.claim_id); + freez((void*)query->data.node_update.node_id); + break; + + case REGISTER_NODE: + freez((void*)query->data.node_creation.claim_id); + freez((void*)query->data.node_creation.hostname); + freez((void*)query->data.node_creation.machine_guid); + break; + + case CHART_DIMS_UPDATE: + case CHART_CONFIG_UPDATED: + case CHART_RESET: + case RETENTION_UPDATED: + case UPDATE_NODE_INFO: + case ALARM_LOG_HEALTH: + case ALARM_PROVIDE_CFG: + case ALARM_SNAPSHOT: + freez(query->data.bin_payload.payload); + break; + + default: + break; + } freez(query->dedup_id); freez(query->callback_topic); @@ -126,3 +193,10 @@ void aclk_queue_lock(void) aclk_query_queue.block_push = 1; ACLK_QUEUE_UNLOCK; } + +void aclk_queue_unlock(void) +{ + ACLK_QUEUE_LOCK; + aclk_query_queue.block_push = 0; + ACLK_QUEUE_UNLOCK; +} |