Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Habbie
Created April 26, 2013 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Habbie/5466733 to your computer and use it in GitHub Desktop.
Save Habbie/5466733 to your computer and use it in GitHub Desktop.
Index: pdns/recursor_cache.cc
===================================================================
--- pdns/recursor_cache.cc (Revision 2495)
+++ pdns/recursor_cache.cc (Arbeitskopie)
@@ -299,22 +299,34 @@
bool MemRecursorCache::doAgeCache(time_t now, const string& name, uint16_t qtype, int32_t newTTL)
{
cache_t::iterator iter = d_cache.find(tie(name, qtype));
- if(iter == d_cache.end())
+ uint32_t maxTTD=std::numeric_limits<uint32_t>::min();
+ if(iter == d_cache.end()) {
return false;
+ }
- int32_t ttl = iter->getTTD() - now;
- if(ttl < 0)
+ CacheEntry ce = *iter;
+
+ if(ce.d_records.size()==1) {
+ maxTTD=ce.d_records.begin()->d_ttd;
+ }
+ else { // find the LATEST ttd
+ for(vector<StoredRecord>::const_iterator i=ce.d_records.begin(); i != ce.d_records.end(); ++i)
+ maxTTD=max(maxTTD, i->d_ttd);
+ }
+
+ int32_t maxTTL = maxTTD - now;
+
+ if(maxTTL < 0)
return false; // would be dead anyhow
- if(ttl > newTTL) {
+ if(maxTTL > newTTL) {
d_cachecachevalid=false;
- ttl = newTTL;
- uint32_t newTTD = now + ttl;
+ uint32_t newTTD = now + newTTL;
- CacheEntry ce = *iter;
for(vector<StoredRecord>::iterator j = ce.d_records.begin() ; j != ce.d_records.end(); ++j) {
- j->d_ttd = newTTD;
+ if(j->d_ttd>newTTD) // do never renew expired or older TTLs
+ j->d_ttd = newTTD;
}
d_cache.replace(iter, ce);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment