Commit 8f31e3ac authored by Marek Vavruša's avatar Marek Vavruša Committed by Marek Vavrusa

lib: added kr_rplan_last() function to get last processed query

The last processed query is not always resolved (if resolution fails),
so previous code returned wrong query in some messages after failure.
parent 96a4d0fa
......@@ -865,7 +865,7 @@ static void update_nslist_score(struct kr_request *request, struct kr_query *qry
}
}
bool resolution_time_exceeded(struct kr_query *qry, uint64_t now)
static bool resolution_time_exceeded(struct kr_query *qry, uint64_t now)
{
uint64_t resolving_time = now - qry->creation_time_mono;
if (resolving_time > KR_RESOLVE_TIME_LIMIT) {
......@@ -1565,7 +1565,7 @@ int kr_resolve_finish(struct kr_request *request, int state)
request->state = state;
ITERATE_LAYERS(request, NULL, finish);
struct kr_query *last = rplan->resolved.len > 0 ? array_tail(rplan->resolved) : NULL;
struct kr_query *last = kr_rplan_last(rplan);
VERBOSE_MSG(last, "finished: %d, queries: %zu, mempool: %zu B\n",
request->state, rplan->resolved.len, (size_t) mp_total_size(request->pool.ctx));
......
......@@ -280,6 +280,15 @@ struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan)
return array_tail(rplan->resolved);
}
struct kr_query *kr_rplan_last(struct kr_rplan *rplan)
{
if (!kr_rplan_empty(rplan)) {
return array_tail(rplan->pending);
}
return kr_rplan_resolved(rplan);
}
struct kr_query *kr_rplan_find_resolved(struct kr_rplan *rplan, struct kr_query *parent,
const knot_dname_t *name, uint16_t cls, uint16_t type)
{
......
......@@ -187,6 +187,13 @@ bool kr_rplan_satisfies(struct kr_query *closure, const knot_dname_t *name, uint
KR_EXPORT KR_PURE
struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan);
/**
* Return last query (either currently being solved or last resolved).
* This is necessary to retrieve the last query in case of resolution failures (e.g. time limit reached).
*/
KR_EXPORT KR_PURE
struct kr_query *kr_rplan_last(struct kr_rplan *rplan);
/** Return query predecessor. */
KR_EXPORT KR_PURE
struct kr_query *kr_rplan_next(struct kr_query *qry);
......
......@@ -218,7 +218,7 @@ static int collect(kr_layer_t *ctx)
stat_const_add(data, metric_answer_slow, 1);
}
/* Observe the final query. */
struct kr_query *last = array_tail(rplan->resolved);
struct kr_query *last = kr_rplan_last(rplan);
if (last->flags.CACHED) {
stat_const_add(data, metric_answer_cached, 1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment