From: Marek VavruĊĦa Date: Fri, 23 Mar 2018 16:40:36 +0000 (-0700) Subject: cache: restore flagging entries written into cache X-Git-Tag: v2.4.0~54^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a95add2e3ff658cf7696100ce5992aeb0a925203;p=thirdparty%2Fknot-resolver.git cache: restore flagging entries written into cache This was probably lost during the cache backend rewrite in 2.x fixes #332 --- diff --git a/lib/cache/api.c b/lib/cache/api.c index 4d14b9da5..63e205740 100644 --- a/lib/cache/api.c +++ b/lib/cache/api.c @@ -638,7 +638,7 @@ do_soa: } /** It's simply inside of cycle taken out to decrease indentation. \return error code. */ -static int stash_rrarray_entry(const ranked_rr_array_t *arr, int arr_i, +static int stash_rrarray_entry(ranked_rr_array_t *arr, int arr_i, const struct kr_query *qry, struct kr_cache *cache, int *unauth_cnt); @@ -663,7 +663,7 @@ int cache_stash(kr_layer_t *ctx, knot_pkt_t *pkt) int ret = 0; int unauth_cnt = 0; for (int psec = KNOT_ANSWER; psec <= KNOT_ADDITIONAL; ++psec) { - const ranked_rr_array_t *arr = selected[psec]; + ranked_rr_array_t *arr = selected[psec]; /* uncached entries are located at the end */ for (ssize_t i = arr->len - 1; i >= 0; --i) { ranked_rr_array_entry_t *entry = arr->at[i]; @@ -821,11 +821,11 @@ static ssize_t stash_rrset(struct kr_cache *cache, const struct kr_query *qry, c return (ssize_t) val_new_entry.len; } -static int stash_rrarray_entry(const ranked_rr_array_t *arr, int arr_i, +static int stash_rrarray_entry(ranked_rr_array_t *arr, int arr_i, const struct kr_query *qry, struct kr_cache *cache, int *unauth_cnt) { - const ranked_rr_array_entry_t *entry = arr->at[arr_i]; + ranked_rr_array_entry_t *entry = arr->at[arr_i]; if (entry->cached) { return kr_ok(); } @@ -836,6 +836,7 @@ static int stash_rrarray_entry(const ranked_rr_array_t *arr, int arr_i, } /* Try to find corresponding signatures, always. LATER(optim.): speed. */ + ranked_rr_array_entry_t *entry_rrsigs = NULL; const knot_rrset_t *rr_sigs = NULL; for (ssize_t j = arr->len - 1; j >= 0; --j) { /* TODO: ATM we assume that some properties are the same @@ -846,6 +847,7 @@ static int stash_rrarray_entry(const ranked_rr_array_t *arr, int arr_i, && knot_rrsig_type_covered(&e->rr->rrs, 0) == rr->type && knot_dname_is_equal(rr->owner, e->rr->owner); if (!ok) continue; + entry_rrsigs = e; rr_sigs = e->rr; break; } @@ -856,6 +858,11 @@ static int stash_rrarray_entry(const ranked_rr_array_t *arr, int arr_i, } if (written > 0) { + /* Mark entry as cached for the rest of the query processing */ + entry->cached = true; + if (entry_rrsigs) { + entry_rrsigs->cached = true; + } if (!kr_rank_test(entry->rank, KR_RANK_AUTH) && rr->type != KNOT_RRTYPE_NS) { *unauth_cnt += 1; } diff --git a/lib/utils.h b/lib/utils.h index e47ee7aee..b990a1756 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -156,7 +156,7 @@ struct ranked_rr_array_entry { uint32_t qry_uid; uint8_t rank; /**< enum kr_rank */ uint8_t revalidation_cnt; - bool cached : 1; /**< whether it has been stashed to cache already */ + bool cached : 1; /**< Set to true if the entry was written into cache */ bool yielded : 1; bool to_wire : 1; /**< whether to be put into the answer */ bool expiring : 1; /**< low remaining TTL; see is_expiring; only used in cache ATM */