From 7b882474648166b6ddc7a9f59ce130153d68c747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 13 Aug 2025 08:45:45 +0200 Subject: [PATCH] Don't count failed additions into the cache Previously, when the new header was NOT added into the cache, we would increment and then decrement stat counters immediately. Delay incrementing the stat counters until after the newheader has been actually added into the database. A little cleanup to accomodate the fact that qpdb->rrsetstats is always available was also done here. --- lib/dns/qpcache.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index c61b57a50a..8a2cd03879 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -843,7 +843,6 @@ mark(dns_slabheader_t *header, uint_least16_t flag) { uint_least16_t attributes = atomic_load_acquire(&header->attributes); uint_least16_t newattributes = 0; qpcache_t *qpdb = HEADERNODE(header)->qpdb; - dns_stats_t *stats = NULL; /* * If we are already ancient there is nothing to do. @@ -860,9 +859,10 @@ mark(dns_slabheader_t *header, uint_least16_t flag) { * Decrement and increment the stats counter for the appropriate * RRtype. */ - stats = dns_db_getrrsetstats(&qpdb->common); - update_rrsetstats(stats, header->typepair, attributes, false); - update_rrsetstats(stats, header->typepair, newattributes, true); + update_rrsetstats(qpdb->rrsetstats, header->typepair, attributes, + false); + update_rrsetstats(qpdb->rrsetstats, header->typepair, newattributes, + true); } static void @@ -2279,9 +2279,8 @@ qpcache__destroy(qpcache_t *qpdb) { isc_heap_destroy(&qpdb->buckets[i].heap); } - if (qpdb->rrsetstats != NULL) { - dns_stats_detach(&qpdb->rrsetstats); - } + dns_stats_detach(&qpdb->rrsetstats); + if (qpdb->cachestats != NULL) { isc_stats_detach(&qpdb->cachestats); } @@ -3087,13 +3086,6 @@ qpcache_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, NODE_WRLOCK(nlock, &nlocktype); - if (qpdb->rrsetstats != NULL) { - DNS_SLABHEADER_SETATTR(newheader, DNS_SLABHEADERATTR_STATCOUNT); - update_rrsetstats(qpdb->rrsetstats, newheader->typepair, - atomic_load_acquire(&newheader->attributes), - true); - } - expire_ttl_headers(qpdb, qpnode->locknum, &nlocktype, &tlocktype, now DNS__DB_FLARG_PASS); @@ -3117,6 +3109,10 @@ qpcache_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, nlocktype, tlocktype DNS__DB_FLARG_PASS); if (result == ISC_R_SUCCESS) { + DNS_SLABHEADER_SETATTR(newheader, DNS_SLABHEADERATTR_STATCOUNT); + update_rrsetstats(qpdb->rrsetstats, newheader->typepair, + newheader->attributes, true); + if (delegating) { qpnode->delegating = 1; }