Verified Commit 72452c8e authored by Grigorii Demidov's avatar Grigorii Demidov Committed by Petr Špaček

lib/nsrep: some changes in NS selection algorythm

parent ba76332d
......@@ -96,6 +96,7 @@ struct kr_qflags {
_Bool FORWARD : 1;
_Bool DNS64_MARK : 1;
_Bool CACHE_TRIED : 1;
_Bool NO_NS_FOUND : 1;
};
typedef struct {
knot_rrset_t **at;
......
......@@ -1329,7 +1329,7 @@ static void on_udp_timeout(uv_timer_t *timer)
VERBOSE_MSG(qry, "=> server: '%s' flagged as 'bad'\n", addr_str);
}
kr_nsrep_update_rtt(&qry->ns, choice, KR_NS_TIMEOUT,
worker->engine->resolver.cache_rtt, KR_NS_UPDATE);
worker->engine->resolver.cache_rtt, KR_NS_RESET);
}
}
task->timeouts += 1;
......
......@@ -162,10 +162,10 @@ static int eval_nsrep(const char *k, void *v, void *baton)
* The fastest NS is preferred by workers until it is depleted (timeouts or degrades),
* at the same time long distance scouts probe other sources (low probability).
* Servers on TIMEOUT (depleted) can be probed by the dice roll only */
if (score <= ns->score && (qry->flags.NO_THROTTLE || score < KR_NS_TIMEOUT)) {
if (score <= ns->score && (score < KR_NS_LONG || (qry->flags.NO_THROTTLE && (score < KR_NS_TIMEOUT)))) {
update_nsrep_set(ns, (const knot_dname_t *)k, addr_choice, score);
ns->reputation = reputation;
} else {
} else if (score < KR_NS_TIMEOUT) {
/* With 10% chance, probe server with a probability given by its RTT / MAX_RTT */
if ((kr_rand_uint(100) < 10) && (kr_rand_uint(KR_NS_MAX_SCORE) >= score)) {
/* If this is a low-reliability probe, go with TCP to get ICMP reachability check. */
......
......@@ -863,7 +863,7 @@ static void update_nslist_score(struct kr_request *request, struct kr_query *qry
}
/* Penalise resolution failures except validation failures. */
} else if (!(qry->flags.DNSSEC_BOGUS)) {
kr_nsrep_update_rtt(&qry->ns, src, KR_NS_TIMEOUT, ctx->cache_rtt, KR_NS_RESET);
kr_nsrep_update_rtt(&qry->ns, src, KR_NS_TIMEOUT, ctx->cache_rtt, KR_NS_UPDATE);
WITH_VERBOSE(qry) {
char addr_str[INET6_ADDRSTRLEN];
inet_ntop(src->sa_family, kr_inaddr(src), addr_str, sizeof(addr_str));
......@@ -1433,8 +1433,12 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
} else {
VERBOSE_MSG(qry, "=> no valid NS left\n");
}
ITERATE_LAYERS(request, qry, reset);
kr_rplan_pop(rplan, qry);
if (!qry->flags.NO_NS_FOUND) {
qry->flags.NO_NS_FOUND = true;
} else {
ITERATE_LAYERS(request, qry, reset);
kr_rplan_pop(rplan, qry);
}
return KR_STATE_PRODUCE;
}
}
......
......@@ -62,6 +62,7 @@ struct kr_qflags {
bool FORWARD : 1; /**< Forward all queries to upstream; validate answers. */
bool DNS64_MARK : 1; /**< Internal mark for dns64 module. */
bool CACHE_TRIED : 1; /**< Internal to cache module. */
bool NO_NS_FOUND : 1; /**< No valid NS found during last PRODUCE stage. */
};
/** Combine flags together. This means set union for simple flags. */
......
......@@ -26,8 +26,8 @@ M.layer = {
local now = ffi.C.kr_now()
local deadline = qry.creation_time_mono + M.timeout
if now > deadline then
--log('[ ][stal] => deadline has passed')
if now > deadline or qry.flags.NO_NS_FOUND then
log('[ ][stal] => deadline has passed')
qry.stale_cb = M.callback
-- TODO: probably start the same request that doesn't stale-serve,
-- but first we need some detection of non-interactive / internal requests.
......
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