Skip to content

Commit

Permalink
Optimization for the ADDR case: stop loop if we found 2 (A and AAAA)
Browse files Browse the repository at this point in the history
  • Loading branch information
omoerbeek committed Aug 26, 2024
1 parent a2615ed commit 49f201d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pdns/recursordist/recursor_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype

if (routingTag) {
auto entries = getEntries(*lockedShard, qname, qtype, routingTag);
bool found = false;
unsigned int found = 0;
time_t ttd{};

if (entries.first != entries.second) {
Expand All @@ -436,17 +436,20 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype
if (!entryMatches(firstIndexIterator, qtype, requireAuth, who)) {
continue;
}
found = true;
++found;

handleServeStaleBookkeeping(now, serveStale, firstIndexIterator);

ttd = handleHit(now, *lockedShard, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone, fromAuthIP);

if (qtype != QType::ANY && qtype != QType::ADDR) { // normally if we have a hit, we are done
if (qtype == QType::ADDR && found == 2) {
break;
}
if (qtype != QType::ANY) { // normally if we have a hit, we are done
break;
}
}
if (found) {
if (found > 0) {
if (cachedState && ttd > now) {
ptrAssign(state, *cachedState);
}
Expand All @@ -460,7 +463,7 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype

if (entries.first != entries.second) {
OrderedTagIterator_t firstIndexIterator;
bool found = false;
unsigned int found = 0;
time_t ttd{};

for (auto i = entries.first; i != entries.second; ++i) {
Expand All @@ -475,17 +478,20 @@ time_t MemRecursorCache::get(time_t now, const DNSName& qname, const QType qtype
if (!entryMatches(firstIndexIterator, qtype, requireAuth, who)) {
continue;
}
found = true;
++found;

handleServeStaleBookkeeping(now, serveStale, firstIndexIterator);

ttd = handleHit(now, *lockedShard, firstIndexIterator, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone, fromAuthIP);

if (qtype != QType::ANY && qtype != QType::ADDR) { // normally if we have a hit, we are done
if (qtype == QType::ADDR && found == 2) {
break;
}
if (qtype != QType::ANY) { // normally if we have a hit, we are done
break;
}
}
if (found) {
if (found > 0) {
if (cachedState && ttd > now) {
ptrAssign(state, *cachedState);
}
Expand Down Expand Up @@ -635,6 +641,7 @@ void MemRecursorCache::replace(time_t now, const DNSName& qname, const QType qty
break;
}
}

if (!isNew) {
moveCacheItemToBack<SequencedTag>(lockedShard->d_map, stored);
}
Expand Down

0 comments on commit 49f201d

Please sign in to comment.