Simplify do_stats logic in rbtdb.c

(cherry picked from commit 4c0b0fa6a5)
This commit is contained in:
Matthijs Mekking 2019-08-12 09:57:16 +02:00
parent db381b7205
commit ea0543a74f

View file

@ -815,6 +815,12 @@ update_cachestats(dns_rbtdb_t *rbtdb, isc_result_t result) {
}
}
static bool
do_stats(rdatasetheader_t *header) {
return (EXISTS(header) &&
(header->attributes & RDATASET_ATTR_STATCOUNT) != 0);
}
static void
update_rrsetstats(dns_rbtdb_t *rbtdb, rdatasetheader_t *header,
bool increment)
@ -823,6 +829,10 @@ update_rrsetstats(dns_rbtdb_t *rbtdb, rdatasetheader_t *header,
dns_rdatastatstype_t base = 0;
dns_rdatastatstype_t type;
if (!do_stats(header)) {
return;
}
/* At the moment we count statistics only for cache DB */
INSIST(IS_CACHE(rbtdb));
@ -1460,10 +1470,7 @@ free_rdataset(dns_rbtdb_t *rbtdb, isc_mem_t *mctx, rdatasetheader_t *rdataset) {
unsigned int size;
int idx;
if (EXISTS(rdataset) &&
(rdataset->attributes & RDATASET_ATTR_STATCOUNT) != 0) {
update_rrsetstats(rbtdb, rdataset, false);
}
update_rrsetstats(rbtdb, rdataset, false);
idx = rdataset->node->locknum;
if (ISC_LINK_LINKED(rdataset, link)) {
@ -1526,8 +1533,6 @@ rollback_node(dns_rbtnode_t *node, rbtdb_serial_t serial) {
static inline void
mark_header_ancient(dns_rbtdb_t *rbtdb, rdatasetheader_t *header) {
bool do_stats = false;
/*
* If we are already ancient there is nothing to do.
*/
@ -1535,33 +1540,23 @@ mark_header_ancient(dns_rbtdb_t *rbtdb, rdatasetheader_t *header) {
return;
}
if ((header->attributes & RDATASET_ATTR_STATCOUNT) != 0) {
do_stats = EXISTS(header);
}
if (do_stats) {
/*
* Decrement the stats counter for the appropriate RRtype.
* If the STALE attribute is set, this will decrement the
* stale type counter, otherwise it decrements the active
* stats type counter.
*/
update_rrsetstats(rbtdb, header, false);
}
/*
* Decrement the stats counter for the appropriate RRtype.
* If the STALE attribute is set, this will decrement the
* stale type counter, otherwise it decrements the active
* stats type counter.
*/
update_rrsetstats(rbtdb, header, false);
header->attributes |= RDATASET_ATTR_ANCIENT;
header->node->dirty = 1;
if (do_stats) {
/* Increment the stats counter for the ancient RRtype. */
update_rrsetstats(rbtdb, header, true);
}
/* Increment the stats counter for the ancient RRtype. */
update_rrsetstats(rbtdb, header, true);
}
static inline void
mark_header_stale(dns_rbtdb_t *rbtdb, rdatasetheader_t *header) {
bool do_stats = false;
/*
* If we are already stale there is nothing to do.
*/
@ -1569,25 +1564,17 @@ mark_header_stale(dns_rbtdb_t *rbtdb, rdatasetheader_t *header) {
return;
}
if ((header->attributes & RDATASET_ATTR_STATCOUNT) != 0) {
do_stats = EXISTS(header);
}
if (do_stats) {
/* Decrement the stats counter for the appropriate RRtype.
* If the ANCIENT attribute is set (although it is very
* unlikely that an RRset goes from ANCIENT to STALE), this
* will decrement the ancient stale type counter, otherwise it
* decrements the active stats type counter.
*/
update_rrsetstats(rbtdb, header, false);
}
/* Decrement the stats counter for the appropriate RRtype.
* If the ANCIENT attribute is set (although it is very
* unlikely that an RRset goes from ANCIENT to STALE), this
* will decrement the ancient stale type counter, otherwise it
* decrements the active stats type counter.
*/
update_rrsetstats(rbtdb, header, false);
header->attributes |= RDATASET_ATTR_STALE;
if (do_stats) {
update_rrsetstats(rbtdb, header, true);
}
update_rrsetstats(rbtdb, header, true);
}
static inline void